之前本人写过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

最低0.47元/天 解锁文章
4592

被折叠的 条评论
为什么被折叠?



