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 nicely and pFormatCtx is populated with the streams in the file. However, when i set input to "pipe:", av_find_stream_info returns with -1.
I am using the same file and piping it by running
cat mpeg.ts | myApp
Any ideas?
Thanks, Aliza
It turns out the file I was using was too short.
av_format_open_input
reads 8K of the file & av_find_stream_info
reads according to max_analyze_duration (of the AVFormatContext
).
Since my file was too short, it reached the end of the pipe before it reached max_analyze_duration
and therefore returned -1.
I still am not sure why it worked with a regular file - maybe it seeked back to the beginning after the call to av_format_open_input
.
In any case, I was able to solve he problem by setting max_analyze_duration
to a smaller value, or by using a longer file.