avfilter_graph_create_filter初始化buffersrc失败

使用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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值