最近在学习向视频添加文字,添加水印等功能,需要用到ffmpeg里面的滤镜,即filter,但是对api不是很熟悉,也不会用,下面对filter一些常用的api做一个记录!
向视频添加水印
以再视频中添加水印为例,filter有它相应的使用流程,大概可以分为几个步骤:
1.创建graph及其上下文
avfilter_graph_alloc();
2.创建filter并添加到graph中
AVFilter *avfilter_get_by_name(const char *name):创建filter
int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt,
const char *name, const char *args, void *opaque,
AVFilterGraph *graph_ctx);
3.链接连个filter
int avfilter_link(AVFilterContext *src, unsigned srcpad,
AVFilterContext *dst, unsigned dstpad):
4.检查配置的链接filter以及相关格式
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx);
5.添加frame到buffer source
int av_buffersrc_add_frame_flags(AVFilterContext *buffer_src,
AVFrame *frame, int flags);
6.从sink里面获取frame数据
int av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags);