解决 ffmpeg 在avformat_find_stream_info执行时间太长

用ffmpeg做demux,网上很多参考文章。对于网络流,avformt_find_stream_info()函数默认需要花费较长的时间进行流格式探测,
那么,如何减少探测时间内? 可以通过设置AVFotmatContext的probesize和max_analyze_duration属性进行调节:(如果设置探测时间过短会导致在探测某些cdn来的流的时候探测不到音频流)

复制代码
复制代码
  .............
   if (avformat_open_input(&(handle->pFormatContext), "", handle->pInputFormat, NULL) < 0) {
        av_free(handle->inputBuffer);
        *errorCode = -4;
        return FALSE;
    }
    (handle->fpState)(handle, 51);

    AVDictionary* pOptions = NULL;
    handle->pFormatContext->probesize = 100 *1024;
    handle->pFormatContext->max_analyze_duration = 5 * AV_TIME_BASE;
    if (avformat_find_stream_info(handle->pFormatContext, &pOptions) < 0) {
        .........
        return FALSE;
    }
    ...............

复制代码
复制代码

备注:如果设置探测时间过短会导致在探测某些cdn来的流的时候探测不到音频流!

posted @   阿风小子  阅读(542)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示