代码是参考雷神的博客的代码,不过由于ffmpeg版本不同,记录使用中遇到的问题。
1.调用avfilter_get_by_name("ffbuffersink")时在新版本的ffmpeg要修改为avfilter_get_by_name("buffersink");否则返回指针为空,调用avfilter_graph_create_filter返回-12,在以前的版本则没有这个问题。
2.调用avfilter_graph_parse_ptr解析字幕水印时返回-22,ffmpeg报错No such filter: 'drawtext',这是由于编译的时候没有开启FreeType字体引擎库,编译的时候./configure--enable-libfreetype。
3.调用avfilter_graph_parse_ptr解析参数时返回-2,drawtext=fontfile=arial.ttf:fontcolor=red:fontsize=30:text='Lei Xiaohua':x=50:y=50里面的arial.ttf是字体文件,要保证字体文件在程序可以找到的目录,冒号在里面是分隔符,路径中不能带冒号。
4.编译完ffmpeg后可能没有libpostproc.so这个库,编译的时候加入开启这个库的编译选项--enable-postproc。
5.代码
// test_avfilter.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
/**
* 最简单的基于FFmpeg的AVFilter例子 - 纯净版
* Simplest FFmpeg AVfilter Example - Pure
*
* 雷霄骅 Lei Xiaohua
* leixiaohua1020@126.com
* 中国传媒大学/数字电视技术
* Communication University of China / Digital TV Technology
* http://blog.csdn.net/leixiaohua1020
*
* 本程序使用FFmpeg的AVfilter实现了YUV像素数据的滤镜处理功能。
* 可以给YUV数据添加各种特效功能。
* 是最简单的FFmpeg的AVFilter方面的教程。
* 适合FFmpeg的初学者。
*
* This software uses FFmpeg's AVFilter to process YUV raw data.
* It can add many excellent effect to YUV data.
* It's the simplest example ba