avformat_find_stream_info 时间太长

本文详细介绍了FFmpeg中avformat_find_stream_info函数的正确使用方法,特别是其第二个参数的设置,并通过实例说明如何避免程序崩溃。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

解决方法:

AVDictionary* pOptions = NULL;
pFormatCtx->probesize = 500 * 1024;
pFormatCtx->max_analyze_duration = 8 * AV_TIME_BASE;
if (avformat_find_stream_info(pFormatCtx, NULL)<0) {
printf("Couldn't find stream information.\n");
return -1;

}


avformat_find_stream_info 的第二个参数不能设置空指针,否则会崩溃,原因如下:

http://blog.youkuaiyun.com/lanxiaziyi/article/details/71667267?locationNum=4&fps=1

av_register_all();
avformat_network_init();


url = "http://ltsbsy.qq.com/GB8lF6TL4NgUddNDzdolIN4HvPZ8zz5daxlsXsx5-6cZSDGZ6BCCX3rCl-gReh6iEaTVGJs0ZmqZVbOCYENLACEvBl-LtHkj-r6V9gAo4IcLvTrdg_yHcA/r0023flooix.320092.ts.m3u8?ver=4&sdtfrom=v4000&platform=10103&appver=5.0.2.4720";
//这个链接过一会儿就失效了


m_pFormatCtx = avformat_alloc_context();
AVDictionary *dic2 = NULL;
AVInputFormat *m_pInFmt = NULL;
 int ret2 = avformat_open_input(&m_pFormatCtx, url.toLocal8Bit(), m_pInFmt, &dic2);
 AVDictionary *dic3 = NULL;
 ret3 = avformat_find_stream_info(m_pFormatCtx, &dic3);//这里寻找流的信息,会卡个1s左右,因为它在寻找流的信息

 然后 avformat_find_stream_info 就崩溃了

为什么呢?
后来在以为大神的指导下,改为了 
avformat_find_stream_info(m_pFormatCtx, NULL);
就OK了
以前以为传入一个指向NULL的指针,和 NULL一样,现在看来是不一样的
具体的解释,看这个函数的文档就知道了
 * @param options  If non-NULL, an ic.nb_streams long array of pointers to
 *                 dictionaries, where i-th member contains options for
 *                 codec corresponding to i-th stream.
 *                 On return each dictionary will be filled with options that were not found.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI算法网奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值