Configure RTMP Buffer Size in FFmpeg

When streaming live video using RTMP, configuring the real-time buffer size in FFmpeg is crucial for preventing packet loss, reducing latency, and ensuring smooth ingestion. This article explains how to adjust the buffer size using specific FFmpeg parameters, target both the RTMP protocol buffer and real-time capture device buffers, and optimize your live stream’s stability.

The RTMP Protocol Buffer Option

FFmpeg allows you to configure the client-side buffer time directly for the RTMP stream. This is controlled via the -rtmp_buffer option, which specifies the buffer size in milliseconds.

To set the RTMP ingestion buffer, place the parameter before your input URL:

ffmpeg -rtmp_buffer 2000 -i rtmp://your-server-ip/live/stream -c copy output.mp4

In this example, -rtmp_buffer 2000 sets a 2-second (2000 milliseconds) buffer. Increasing this value helps smooth out playback over unstable network connections, while decreasing it reduces overall latency.

The Real-Time Input Buffer (-rtbufsize)

If you are ingesting a live feed from a local capture device (such as a webcam, capture card, or desktop grabber) and streaming it via RTMP, you must configure the real-time input buffer. If this buffer is too small, FFmpeg will drop frames, resulting in the “real-time buffer [name] too full” warning.

Use the -rtbufsize option to allocate more memory for buffering raw incoming frames before they are encoded and sent over RTMP:

ffmpeg -f dshow -rtbufsize 150M -i video="Integrated Camera" -c:v libx264 -f flv rtmp://your-server-ip/live/stream

Increasing the Thread Queue Size

During high-bitrate RTMP ingestion, the demuxer queue can overflow if the CPU cannot process the packets fast enough. To prevent the “Thread message queue blocking” warning, increase the input thread queue size using -thread_queue_size:

ffmpeg -thread_queue_size 1024 -f dshow -rtbufsize 100M -i video="Integrated Camera" -c:v libx264 -f flv rtmp://your-server-ip/live/stream

TCP Socket Buffer Adjustment

Because RTMP runs over TCP, you can also instruct FFmpeg to increase the underlying operating system TCP receive buffer. This is done by appending the rcvbuf parameter directly to the RTMP URL:

ffmpeg -i rtmp://your-server-ip/live/stream?rcvbuf=262144 -c copy output.mp4