DoubleLi

qq: 517712484 wx: ldbgliet

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  4737 随笔 :: 2 文章 :: 542 评论 :: 1615万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

使用FFmpeg的avfilter时,流程如下:

1.使用avfilter_get_by_name 创建AVFilter的实例,返回指针

2.构建buffersrc和buffersink,作为graph的输入输出端口

3.构建类型为AVFilterContext的对象,作为实际操作数据的对象

4.将filter与filtercontext绑定连接,使用avfilter_graph_create_filter函数。

正常代码如下:


    transform_ctx = avfilter_graph_alloc_filter(filter_graph, transform, "transform");
    ret = avfilter_init_dict(transform_ctx, &pOptions);
    if (ret <= 0)
    {
        //goto ERROR;
    }
    /*
    加入buffersrc和buffersink
    */
    ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "buffer", NULL, NULL, filter_graph);
    ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "buffersink", NULL, NULL, filter_graph);
    if (ret < 0)
    {
        //goto ERROR;
    }
此时,在
ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "buffer", NULL,NULL, filter_graph);

该段执行完后,buffersrc_ctx为空,且返回ret为-22

排错:

1.同样的buffersink初始化buffersink_ctx获得了正常的对象

2.buffersrc正常初始化

原因:

buffersrc_ctx的初始化需要args作为参数,否则无法正常初始化。

初始化语句应该改为:

ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "buffer", args,NULL, filter_graph);

args为描述输入帧序列的参数信息:

snprintf(args, sizeof(args),
"video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt,
time_base.num, time_base.den,
pCodecCtx->sample_aspect_ratio.num, pCodecCtx->sample_aspect_ratio.den);

引用于stackoverflow:

https://stackoverflow.com/questions/43038296/ffmpegavfilter-graph-create-filter-method-failed-when-initializing-filter

posted on   DoubleLi  阅读(780)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2018-03-01 H264系列(9):H264中的时间戳(DTS和PTS)
2017-03-01 Qt快速入门学习笔记(基础篇)
2016-03-01 FFmpeg解码H264及swscale缩放详解
2016-03-01 linux中cat more less head tail 命令区别
点击右上角即可分享
微信分享提示