【问题标题】:av_find_stream_info works OK with file, not with pipeav_find_stream_info 适用于文件,不适用于管道
【发布时间】:2012-07-05 07:34:05
【问题描述】:

我有以下代码:

av_register_all();
pFormatCtx = avformat_alloc_context();
const char* input = "pipe:";
AVInputFormat* iFormat = av_find_input_format("mpegts");
if ( avformat_open_input(&pFormatCtx, input, iFormat, NULL) != 0 )
         return -1;
int res = av_find_stream_info(pFormatCtx);

当我的输入是一个常规文件时,这很好用,并且 pFormatCtx 填充了文件中的流。但是,当我将输入设置为“管道:”时,av_find_stream_info 返回 -1。

我正在使用相同的文件并通过运行管道它 cat mpeg.ts | myApp

有什么想法吗?

谢谢, 艾丽莎

【问题讨论】:

    标签: c ffmpeg pipe libavformat


    【解决方案1】:

    原来我使用的文件太短了。

    av_format_open_input 读取 8K 文件,av_find_stream_info 根据 max_analyze_duration(AVFormatContext)读取。

    由于我的文件太短,它在到达max_analyze_duration 之前就到达了管道的末端,因此返回-1。

    我仍然不确定为什么它适用于常规文件 - 可能在调用 av_format_open_input 后它会回到开头。

    无论如何,我可以通过将max_analyze_duration 设置为较小的值或使用更长的文件来解决他的问题。

    【讨论】:

      【解决方案2】:

      这是来自article 关于减少延迟和ffmpeg streaming guide

      您可以为探针大小和最长分析持续时间提供最小值。

      pFormatCtx->probesize = 32;
      pFormatCtx->max_analyze_duration = 32;
      

      另外,请注意,较小的值仅适用于已知 多路复用器,否则可能由于缺少连接而无法完成 关于流的数据。

      【讨论】:

        【解决方案3】:

        还值得注意的是,如果您从stdin 读取MOV 文件,更改probesize/analyzeduration 的值可能无济于事。根据this email thread,是mov容器格式的限制:

        通常不可能通过标准输入读取 mov 文件,因为它 mov 文件包含必要信息是完全正常的 需要在文件的最后进行解码(如编解码器等)。 (这不是FFmpeg的限制,而是mov文件的一个特点 格式。)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-02-26
          • 2020-06-11
          • 1970-01-01
          • 2021-12-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多