How to Set sndbuf and rcvbuf in FFmpeg SRT URLs

This guide explains how to configure the send (sndbuf) and receive (rcvbuf) socket buffer sizes when streaming with the Secure Reliable Transport (SRT) protocol in FFmpeg. Properly sizing these buffers helps prevent UDP buffer overflow, mitigates packet drops over jittery connections, and ensures stable high-bitrate video transmission.

SRT Buffer Parameter Syntax

In FFmpeg, SRT options are passed directly as query parameters appended to the SRT URL. Both sndbuf and rcvbuf accept integer values representing the buffer size in bytes.

The URL structure is formatted as:

srt://<ip_or_hostname>:<port>?<parameter>=<value>&<parameter>=<value>

Always enclose the SRT URL in double quotation marks to prevent shell interpretation of the ? and & characters.


Setting the Send Buffer (sndbuf)

The sndbuf parameter controls the operating system's send buffer size for the underlying UDP socket. This is primarily used on the sending (transmitting) side of an FFmpeg pipeline.

Example: Streaming Out as Caller

To set the send buffer to 2 MB (2,097,152 bytes) while pushing an MPEG-TS stream to a remote receiver:

ffmpeg -re -i input.mp4 -c:v libx264 -b:v 4000k -c:a aac -f mpegts \
  "srt://receiver.example.com:9000?mode=caller&sndbuf=2097152"

Setting the Receive Buffer (rcvbuf)

The rcvbuf parameter controls the operating system's receive buffer size for the underlying UDP socket. This is primarily used on the receiving (ingesting) side to prevent the OS kernel from dropping incoming packets before FFmpeg reads them.

Example: Listening for an Incoming Stream

To set the receive buffer to 4 MB (4,194,304 bytes) while listening for an incoming stream:

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

Using Both Parameters Simultaneously

Both options can be combined on either input or output URLs if bidirectional data exchange or symmetric buffer sizing is required:

ffmpeg -re -i input.mp4 -c copy -f mpegts \
  "srt://receiver.example.com:9000?mode=caller&sndbuf=2097152&rcvbuf=2097152"

Important Considerations

  1. Operating System Limits: The values specified in sndbuf and rcvbuf cannot exceed the maximum socket buffer sizes permitted by the host operating system. On Linux, check and adjust the system limits if FFmpeg fails to allocate the requested size:
    • View max receive buffer: sysctl net.core.rmem_max

    • View max send buffer: sysctl net.core.wmem_max

    • Temporarily increase limits:

      sudo sysctl -w net.core.rmem_max=4194304
      sudo sysctl -w net.core.wmem_max=4194304
  2. Distinction from SRT Latency Buffers: The sndbuf and rcvbuf parameters configure OS-level socket buffers. They are distinct from the SRT internal transmission buffers, which are governed by parameters such as latency, rcvlatency, and peerlatency.