ffmpegdelogo滤镜去除图片水印
ffmpegdelogo滤镜去除图⽚⽔印
之前本⼈写过,
今天⽤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();
return0;
}
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"
大笑江湖cf版歌词
#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:
int OpenFileA(const char*pFileA);如何查已删除的聊天记录
int OpenOutPut(const char*pFileOut);
int InitFilter(const char* filter_desc);
private:
static DWORD WINAPI VideoAReadProc(LPVOID lpParam);
void VideoARead();
static DWORD WINAPI VideoDelogoProc(LPVOID lpParam);
void VideoDelogo();
private:
AVFormatContext *m_pFormatCtx_FileA =NULL;
AVCodecContext *m_pReadCodecCtx_VideoA =NULL;
AVCodec *m_pReadCodec_VideoA =NULL;
AVCodecContext *m_pCodecEncodeCtx_Video =NULL;
AVFormatContext *m_pFormatCtx_Out =NULL;
AVFifoBuffer *m_pVideoAFifo =NULL;
int m_iVideoWidth =1920;
int m_iVideoHeight =1080;
int m_iYuv420FrameSize =0;
private:
AVFilterGraph* m_pFilterGraph =NULL;
AVFilterContext* m_pFilterCtxSrcVideoA =NULL;
草量级是什么意思AVFilterContext* m_pFilterCtxSink =NULL;
private:
CRITICAL_SECTION m_csVideoASection;
HANDLE m_hVideoAReadThread =NULL;
HANDLE m_hVideoDelogoThread =NULL;
};
Delogo.cpp的代码如下:
#include"Delogo.h"
//#include "log/log.h"
CDelogo::CDelogo()
{
InitializeCriticalSection(&m_csVideoASection);
}
CDelogo::~CDelogo()
{
DeleteCriticalSection(&m_csVideoASection);
}
int CDelogo::StartDelogo(const char*pFileA,const char*pFileOut,int x,int y,int width,int height)
{
int ret =-1;
do
{
ret =OpenFileA(pFileA);
if(ret !=0)
{
break;
}
ret =OpenOutPut(pFileOut);
if(ret !=0)
{
break;
}
char szFilterDesc[512]={0};
_snprintf(szFilterDesc,sizeof(szFilterDesc),
"[in0]delogo=x=%d:y=%d:w=%d:h=%d:show=0[out]", x, y, width, height);
ret =InitFilter(szFilterDesc);
if(ret !=0)
{
break;
}
m_iYuv420FrameSize =av_image_get_buffer_size(AV_PIX_FMT_YUV420P, m_pReadCodecCtx_VideoA->width, m_pReadCodecCtx_VideoA->height,1 );

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。