Configure FFmpeg Tee Muxer Buffer Sizes
When streaming or saving multiple outputs simultaneously using
FFmpeg’s tee muxer, managing network latency and system
resources requires fine-tuning the buffer sizes for each individual
target. This article provides a direct guide on how to configure buffer
sizes for each output target within the FFmpeg tee
protocol, utilizing specific muxer options, the FIFO (First-In,
First-Out) packet thread, and protocol-level query parameters.
Understanding the Tee Muxer Syntax
The tee muxer maps a single input to multiple outputs.
To apply specific configurations—including buffer sizes—to an individual
target, you must pass options inside square brackets [...]
immediately preceding the target’s output destination.
There are two primary ways to configure buffering for individual targets: 1. FIFO Muxer Buffering: Buffers packets in system memory before they are sent to the target (prevents a slow target from blocking other streams). 2. Protocol-Level Socket Buffering: Sets the network socket buffer sizes for protocols like UDP, TCP, or RTMP.
Method 1: Using the FIFO Muxer for Packet Buffering
The most effective way to buffer data per target is to wrap the
target in FFmpeg’s fifo muxer. This creates a dedicated
thread and queue for that specific output.
You can configure the buffer size using the queue_size
option (defined in packets) and format_opts to pass
specific settings.
Syntax:
-f tee "[f=fifo:fifo_options=queue_size=1000]rtmp://live.server.com/app/stream1|[f=fifo:fifo_options=queue_size=5000]rtmp://live.server.com/app/stream2"In this example: * Stream 1 has a buffer queue size of 1,000 packets. * Stream 2 has a larger buffer queue size of 5,000 packets to handle greater network instability.
If a queue fills up, you can also define the behavior using
on_queue_full=drop to drop packets instead of blocking the
entire encoding process.
Method 2: Configuring Protocol-Level Network Buffers
If you need to configure the underlying network socket buffer sizes
(e.g., for UDP or SRT outputs) rather than the application-level packet
queue, you can append protocol-specific parameters directly to the
target URL inside the tee command.
For UDP Outputs:
Use the buffer_size query parameter (defined in bytes)
to set the socket send/receive buffer size.
-f tee "udp://192.168.1.100:1234?buffer_size=131072|[f=mpegts]udp://192.168.1.101:1234?buffer_size=524288"- Target 1: Uses a socket buffer size of 128 KB (131,072 bytes).
- Target 2: Uses a socket buffer size of 512 KB (524,288 bytes).
For RTMP Outputs:
Use the rtmp_buffer parameter (defined in milliseconds)
to set the client-side buffer time.
-f tee "[f=flv]rtmp://live.server.com/app/stream1?rtmp_buffer=1000"Combining FIFO and Protocol Buffers
For maximum reliability in production environments, combine the application-level FIFO queue with protocol-level socket buffers. This ensures that network fluctuations are absorbed both by FFmpeg’s memory allocation and the operating system’s network stack.
-f tee "[f=fifo:fifo_options=queue_size=2000:on_queue_full=drop]udp://192.168.1.100:1234?buffer_size=1048576"