C av_find_stream_info适用于文件,而不是管道

C av_find_stream_info适用于文件,而不是管道,c,ffmpeg,pipe,libavformat,C,Ffmpeg,Pipe,Libavformat,我有以下代码: 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_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由文件中的流填充。但是,当我将输入设置为“pipe:”时,av_find_stream_info返回-1

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

有什么想法吗

谢谢,
Aliza

原来我使用的文件太短了

av\u format\u open\u input
读取8K文件&
av\u find\u stream\u info
根据最大分析持续时间(在
AVFormatContext
中)读取

由于我的文件太短,它在到达
max\u analyze\u duration
之前到达管道末端,因此返回-1

我仍然不知道为什么它能与常规文件一起工作-也许它在调用
av\u format\u open\u input
之后又回到了开始

在任何情况下,我都可以通过将
max\u analyze\u duration
设置为较小的值或使用较长的文件来解决问题。

这是关于减少延迟和

您可以为probesize和最大分析持续时间指定最小值

pFormatCtx->probesize = 32;
pFormatCtx->max_analyze_duration = 32;
另外,请注意,较小的值仅适用于已知的情况 muxers,否则可能由于缺少 关于流的数据


还值得注意的是,如果您正在从
stdin
读取MOV文件,更改
probesize
/
analyzeduration
的值可能不会有帮助。根据,这是mov容器格式的一个限制:

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