Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffmpeg : playing udp stream

I'm playing udp stream on iDevice using ffmpeg. It does play the video and audio successfully.

The only issue I've got here that the following function call does take a long time

avformat_find_stream_info

It takes about 10 secs to complete the execution of this function. The media that I'm playing has following properties :

MPEG-4 VIDEO v3 (DIV3)
RESOLUTION : 640x480
Frame rate : 25

Any ideas how to workaround this delay ?

like image 249
deimus Avatar asked Aug 01 '12 19:08

deimus


1 Answers

I realize this is an old question, but I recently encountered this problem, so while this probably won't help the OP, I'll put down an answer for posterity's sake.

The short answer:

Set the AVFormatContext fields for probesize and/or max_analyze_duration to something smaller than the default, i.e.

std::string url_path = "...";
AVFormatContext *format_ctx = NULL;
avformat_open_input(&format_ctx, url_path.c_str(), NULL, NULL);
format_ctx->max_analyze_duration = 50000;
avformat_find_stream_info(format_ctx, NULL);

For the longer answer:

avformat_find_stream_info reads from the input data stream and tries to fill out the AVFormatContext based on the packets it sees. It can do this for up to the max_analyze_duration value as set in the AVFormatContext struct.

For say, local video files, it'll generally be very fast, but for network streams this can take a very long time (especially if the stream is damaged). This is where the long wait-times for avformat_find_stream_info come into play. The default value for max_analyze_duration is 5000000 (in units of AV_TIME_BASE), meaning that hypothetically, avformat_find_stream_info can be sampling packets from the input stream for up to that duration (IIRC AV_TIME_BASE is equivalent to microseconds, so the default maximum wait time is 5 seconds).

By setting the max_analyze_duration to something smaller, say 50,000 (~500ms) we force avformat_find_stream_info to choose what the AVFormatContext fields are with less information, while limiting the worst-case wait time to something more reasonable. In my experience this hasn't caused for any problems (although this may depend on how your video source is). The probesize field determines the number of bytes that avformat_find_stream_info can read from the stream. Note that if you set this value to be too low, you might be not able to get accurate codec information

like image 188
alrikai Avatar answered Sep 22 '22 07:09

alrikai