How to Set SRT Stream Buffer Size in FFmpeg

This guide explains how to configure the network buffer size for Secure Reliable Transport (SRT) streams using FFmpeg. You will learn about the key parameters required to adjust socket buffers and transmission latency, along with practical command-line examples to optimize your live streaming performance and prevent packet loss.

Key SRT Buffer Parameters in FFmpeg

When streaming over SRT, buffering is controlled by two main factors: the system network socket buffers and the SRT protocol latency buffer. You configure these parameters directly inside the SRT destination or source URL in FFmpeg using query parameters.

Configuration Examples

To apply these settings, append them as query parameters to your SRT URI.

1. Configuring the Receiver (Listener/Caller)

If you are receiving an SRT stream, you should increase the rcvbuf and set an appropriate latency to handle network jitter.

ffmpeg -i "srt://0.0.0.0:9000?mode=listener&rcvbuf=12058624&latency=2000000" -c copy output.mp4

In this example: * rcvbuf=12058624 allocates approximately 11.5 MB for the socket receive buffer. * latency=2000000 sets a 2-second (2,000,000 microseconds) buffer window for packet recovery.

2. Configuring the Sender (Caller/Listener)

If you are sending an SRT stream, you should configure the sndbuf to ensure the system has enough memory to hold packets during temporary network dropouts.

ffmpeg -re -i input.mp4 -c:v libx264 -preset ultrafast -f mpegts "srt://192.168.1.50:9000?mode=caller&sndbuf=12058624&latency=2000000"

In this example: * sndbuf=12058624 allocates approximately 11.5 MB for the send buffer. * latency=2000000 configures the sender to retain packets in its sending buffer for up to 2 seconds to accommodate retransmission requests (NACK) from the receiver.

For optimal stability, use the following guidelines to calculate your buffer sizes: