Av_find_stream_info works fine with a file, not a pipe

I have the following code:

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); 

when my input is a regular file, this works well, and pFormatCtx is populated with threads in the file. However, when I set the input to "pipe:", av_find_stream_info returns with -1.

I use the same file and share it by running cat mpeg.ts | myApp cat mpeg.ts | myApp

Any ideas?

Thanks Aliza

+4
source share
3 answers

Turns out the file I used was too short.

av_format_open_input reads an 8K file and av_find_stream_info reads according to max_analyze_duration (from AVFormatContext ).

Since my file was too short, it reached the end of the channel before it reached max_analyze_duration and therefore returned -1.

I'm still not sure why it worked with a regular file - it may have returned to the beginning after calling av_format_open_input .

In any case, I was able to solve the problem by setting max_analyze_duration to a smaller value or using a longer file.

+3
source

This is from the article on reducing latency and the ffmpeg streaming guide

You can give the minimum values ​​for the sample and the maximum duration of the analysis.

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

Also, note that smaller values ​​are in order, only for known multiplexers, otherwise the connection cannot be made due to lack of flow data.

0
source

It's also worth noting that if you are reading a MOV file from stdin , changing probesize / analyzeduration values ​​probably won't help. According to this email stream , this is a limitation of the mov container format:

As a rule, it is impossible to read mov files through stdin, because it is completely normal that mov files contain the necessary information necessary for decoding (for example, codecs, etc.) at the very end of the file. (This is not a limitation of FFmpeg, but the function of the file is mov format.)

0
source

All Articles