简体   繁体   English

ffmpeg:播放udp流

[英]ffmpeg : playing udp stream

I'm playing udp stream on iDevice using ffmpeg. 我正在使用ffmpeg在iDevice上播放udp流。 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. 完成此功能的执行大约需要10秒钟。 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 ? 任何想法如何解决此延迟?

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. 我意识到这是一个古老的问题,但是我最近遇到了这个问题,因此尽管这可能不会对OP有所帮助,但为了后代,我将给出一个答案。

The short answer: 简短的答案:

Set the AVFormatContext fields for probesize and/or max_analyze_duration to something smaller than the default, ie probesize和/或max_analyze_durationAVFormatContext字段设置为小于默认值的字段,即

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. avformat_find_stream_info从输入数据流中读取,并尝试根据看到的数据包填充AVFormatContext It can do this for up to the max_analyze_duration value as set in the AVFormatContext struct. 它最多可以执行AVFormatContext结构中设置的max_analyze_duration值。

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. 这是avformat_find_stream_info长时间等待的地方。 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). max_analyze_duration的默认值为5000000(以max_analyze_duration为单位),这意味着,假设在最长持续时间内, avformat_find_stream_info可以从输入流中采样数据包(IIRC AV_TIME_BASE等于微秒,因此默认的最大等待时间为5秒)。 。

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. 通过将max_analyze_duration设置为较小的值,例如50,000( avformat_find_stream_info ),我们可以强制avformat_find_stream_info选择信息较少的AVFormatContext字段,同时将最坏情况下的等待时间限制为更合理的时间。 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. probesize字段确定avformat_find_stream_info可从流读取的字节数。 Note that if you set this value to be too low, you might be not able to get accurate codec information 请注意,如果将此值设置得太低,则可能无法获得准确的编解码器信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM