Set RTSP/UDP buffer size in FFmpeg/LibAV
Asked Answered
H

2

7

Note: I'm aware ffmpeg and libav are different libraries. This is a problem common to both.

Disclaimer: Duplicate of SO question marked as answered but actually didn't give a proper solution.


Insufficient UDP buffer size causes broken streams for several high resolution video streams. In LibAV/FFMPEG it's possible to set the udp buffer size for udp urls (udp://...) by appending some options (buffer_size) to it.

However, for RTSP urls this is not supported.

These are the only solutions I've found:

  • Rebuilding ffmpeg/libav changing the UDP_MAX_PKT_SIZE in the udp.c source file.
  • Using a nasty hack to find and modify the required value, by casting some private structs.
  • Using a different decoding library (proposed solution to aforementioned related SO question).

None of these is actually a solution. From what I found it should be possible to use the API's AVOptions to find and set this value. Or else, the AVDictionary.

It's very difficult to find how to set these throughout the documentation of either libav or ffmpeg.

Update:

The following patches have been submited to Libav tackling this topic, thanks to Libav developer @lu_zero :

Which should offer a hint on how to implement those, still these are not yet available through the official stable API.

Hydrogenolysis answered 16/3, 2015 at 11:14 Comment(4)
You could increase the default OS UDP buffer limits I guess. Improving UDP PeformanceNicholas
Not available for Windows, it may work for other platforms.. but still this should be set through the API.Hydrogenolysis
For Windows see this questionNicholas
Thanks. However I don't want to solve it for windows only. Moreover I know that it should be possible to do so within my application only. It's just that the API is not clear.Hydrogenolysis
F
3

Since this commit it is enough to pass buffer_size as option and it gets forwarded to the udp protocol through the rtp protocol.

I tested and it works as intended.

Farfamed answered 2/4, 2015 at 18:16 Comment(2)
What about TCP?Tessin
The commit link is brokenUrian
L
8

FYI, the latest ffmpeg2.8.5 already has this option. I use it to set the the buffer_size

av_dict_set(&options, "buffer_size", "655360", 0);

and I got this output:

[udp @ 0xb4945090] attempted to set receive buffer to size 655360 but it only ended up set as 327680 After some searching I run

echo 2097152 > /proc/sys/net/core/rmem_max

to fix the warning

Lui answered 9/12, 2016 at 7:44 Comment(0)
F
3

Since this commit it is enough to pass buffer_size as option and it gets forwarded to the udp protocol through the rtp protocol.

I tested and it works as intended.

Farfamed answered 2/4, 2015 at 18:16 Comment(2)
What about TCP?Tessin
The commit link is brokenUrian

© 2022 - 2024 — McMap. All rights reserved.