ffmpeg delogo滤镜去除图片水印

之前本人写过ffmpeg movie滤镜添加图片水印ffmpeg 非movie滤镜添加图片水印
今天用delogo滤镜去掉图片水印,ffmpeg命令行如下:

ffmpeg -i in-computer_drawmovie.mp4 -vf delogo=x=100:y=300:w=480:h=320:show=0 in-computer_drawmovie_delogo.mp4

指定去除的起始位置为100,300,水印的宽度和高度分别为480和320。

水印去除前,效果如下:
在这里插入图片描述
去除水印后,效果如下:
在这里插入图片描述

去除的原理是根据被去掉部分周围的色彩进行颜色构造,具体我暂时没兴趣研究。

下面是代码结构:
在这里插入图片描述
FfmpegDelogoTest.cpp的代码如下:

#include <iostream>
#include "Delogo.h"
#include <vector>

#ifdef	__cplusplus
extern "C"
{
   
   
#endif

#pragma comment(lib, "avcodec.lib")
#pragma comment(lib, "avformat.lib")
#pragma comment(lib, "avutil.lib")
#pragma comment(lib, "avdevice.lib")
#pragma comment(lib, "avfilter.lib")
#pragma comment(lib, "postproc.lib")
#pragma comment(lib, "swresample.lib")
#pragma comment(lib, "swscale.lib")


#ifdef __cplusplus
};
#endif



std::string Unicode_to_Utf8(const std::string & str)
{
   
   
	int nwLen = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0);
	wchar_t * pwBuf = new wchar_t[nwLen + 1];//一定要加1,不然会出现尾巴 
	ZeroMemory(pwBuf, nwLen * 2 + 2);
	::MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), pwBuf, nwLen);
	int nLen = ::WideCharToMultiByte(CP_UTF8, 0, pwBuf, -1, NULL, NULL, NULL, NULL);
	char * pBuf = new char[nLen + 1];
	ZeroMemory(pBuf, nLen + 1);
	::WideCharToMultiByte(CP_UTF8, 0, pwBuf, nwLen, pBuf, nLen, NULL, NULL);
	std::string retStr(pBuf);
	delete[]pwBuf;
	delete[]pBuf;
	pwBuf = NULL;
	pBuf = NULL;
	return retStr;
}


int main()
{
   
   
	CDelogo cCDelogo;
	const char *pFileA = "E:\\learn\\ffmpeg\\FfmpegFilterTest\\x64\\Release\\in-computer_drawmovie.mp4";

	const char *pFileOut = "E:\\learn\\ffmpeg\\FfmpegFilterTest\\x64\\Release\\in-computer_drawmovie_delogo.mp4";

	int x = 100;
	int y = 300;
	int width = 480;
	int height = 320;
	cCDelogo.StartDelogo(pFileA, pFileOut, x, y, width, height);
	cCDelogo.WaitFinish();
	return 0;
}



Delogo.h的代码如下:

#pragma once

#include <Windows.h>
#include <string>

#ifdef	__cplusplus
extern "C"
{
   
   
#endif
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libswresample/swresample.h"
#include "libavdevice/avdevice.h"
#include "libavutil/audio_fifo.h"
#include "libavutil/avutil.h"
#include "libavutil/fifo.h"
#include "libavutil/frame.h"
#include "libavutil/imgutils.h"

#include "libavfilter/avfilter.h"
#include "libavfilter/buffersink.h"
#include "libavfilter/buffersrc.h"


#ifdef __cplusplus
};
#endif

class CDelogo
{
   
   
public:
	CDelogo();
	~CDelogo();
public:
	int StartDelogo(const char *pFileA, const char *pFileOut, int x, int y, int width, int height);
	int WaitFinish();
private
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值