【FFPLAY】过滤器

1 基础函数

AVFilterGraph *avfilter_graph_alloc(void)
// 创建⼀个滤波器图filter graph

AVFilterGraph *graph = avfilter_graph_alloc();

AVFilter avfilter_get_by_name(const char name);
// 获取FFmpeg中定义的filter,调⽤该⽅法前需要先调⽤avfilter_register_all();进⾏滤波器注册
int av_buffersrc_add_frame(AVFilterContext ctx, AVFrame frame);
// 往源滤波器buffer中输⼊待处理的数据
int av_buffersink_get_frame(AVFilterContext ctx, AVFrame frame);
// 从⽬的滤波器buffersink中获取处理完的数据
int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt,
const char name, const char args, void *opaque,
AVFilterGraph *graph_ctx);
// 创建⼀个滤波器实例AVFilterContext,并添加到AVFilterGraph中
int avfilter_link(AVFilterContext *src, unsigned srcpad,
AVFilterContext *dst, unsigned dstpad);
// 连接两个滤波器节点

2 输入端、输出端

1 滤波器buffer代表filter graph中的源头,原始数据就往这个filter节点输⼊的;
2 ⽽滤波器buffersink代表filter graph中的输出节点,处理完成的数据从这个filter节点输出。
(audio 则是 abuffer abuffersink)

3 avfilter_link函数解析

a:参数二 n
作为 source ,第 n + 1 个流向
参数四 n
作为 sink,第n + 1个流入

    // src filter to split filter
    ret = avfilter_link(bufferSrc_ctx, 0, splitFilter_ctx, 0);
    if (ret != 0) {
        printf("Fail to link src filter and split filter\n");
        return -1;
    }
    // split filter's first pad to overlay filter's main pad
    ret = avfilter_link(splitFilter_ctx, 0, overlayFilter_ctx, 0);
    if (ret != 0) {
        printf("Fail to link split filter and overlay filter main pad\n");
        return -1;
    }
    // split filter's second pad to crop filter
    ret = avfilter_link(splitFilter_ctx, 1, cropFilter_ctx, 0);
    if (ret != 0) {
        printf("Fail to link split filter's second pad and crop filter\n");
        return -1;
    }
    // crop filter to vflip filter
    ret = avfilter_link(cropFilter_ctx, 0, vflipFilter_ctx, 0);
    if (ret != 0) {
        printf("Fail to link crop filter and vflip filter\n");
        return -1;
    }
    // vflip filter to overlay filter's second pad
    ret = avfilter_link(vflipFilter_ctx, 0, overlayFilter_ctx, 1);
    if (ret != 0) {
        printf("Fail to link vflip filter and overlay filter's second pad\n");
        return -1;
    }
    // overlay filter to sink filter
    ret = avfilter_link(overlayFilter_ctx, 0, bufferSink_ctx, 0);
    if (ret != 0) {
        printf("Fail to link overlay filter and sink filter\n");
        return -1;
    }

对应如下
【FFPLAY】过滤器_第1张图片

你可能感兴趣的:(ffmpeg,ffmpeg,音视频)