Reputation: 744
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
Upvotes: 4
Views: 3335
Reputation: 4815
It is also worth noting that in case you are reading a MOV file from stdin
, changing values of probesize
/analyzeduration
probably won't help. According to this email thread, it is a limitation of mov container format:
It is not generally possible to read mov files via stdin, because it is perfectly normal that mov files contain necessary information needed for decoding (like codecs etc.) at the very end of the file. (This is not a limitation of FFmpeg, but a feature of the mov file format.)
Upvotes: 0
Reputation: 2980
This is from this article about reducing latency and ffmpeg streaming guide
You can give minimum values for probesize and maximum analyze duration.
pFormatCtx->probesize = 32;
pFormatCtx->max_analyze_duration = 32;
Also, please note that the smaller values are OK only for known muxers, otherwise the connection may not be done because of lacking data about stream.
Upvotes: 0
Reputation: 744
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.
Upvotes: 3