FFmpeg Tee Muxer: Stream to Multiple RTMP Servers

This article explains how to configure the tee muxer in FFmpeg to split a single input stream and broadcast it simultaneously to two different RTMP destinations. You will learn the exact command-line syntax, key configuration parameters, and best practices to ensure stable, low-latency dual-streaming without unnecessarily taxing your system’s CPU.

The tee muxer is an efficient tool that duplicates the output of an FFmpeg process, allowing you to write to multiple destinations (like YouTube and Twitch) at the same time. Because it duplicates the packet stream after encoding, your CPU only has to encode the video and audio once, saving massive amounts of processing power.

Basic Command Syntax

To stream to two RTMP servers, use the -f tee output flag and map your destinations inside double quotes, separated by a pipe (|) character. Each destination must specify its muxer format using the f=flv flag, as RTMP requires the FLV container format.

Here is the basic command structure:

ffmpeg -i input_source -c:v libx264 -c:a aac -f tee "[f=flv]rtmp://server1.example.com/app/stream_key1|[f=flv]rtmp://server2.example.com/app/stream_key2"

Command Breakdown

Handling Connection Failures (Onfail Option)

By default, if one of your RTMP connections drops, the entire FFmpeg process will crash, stopping the stream to the surviving server. To prevent this, you can use the onfail=ignore option. This ensures that if one RTMP server disconnects, FFmpeg will continue streaming to the other.

Add onfail=ignore inside the brackets of each destination:

ffmpeg -i input_source -c:v libx264 -preset veryfast -maxrate 3000k -bufsize 6000k -c:a aac -f tee "[f=flv:onfail=ignore]rtmp://server1.example.com/app/stream_key1|[f=flv:onfail=ignore]rtmp://server2.example.com/app/stream_key2"

Streaming with Existing Encoded Video (No Re-encoding)

If your input source is already encoded in an RTMP-compatible format (H.264 video and AAC audio) and does not need to be re-encoded, you can use the copy codec option to further reduce CPU usage to near zero:

ffmpeg -i input_source -c copy -f tee "[f=flv]rtmp://server1.example.com/app/stream_key1|[f=flv]rtmp://server2.example.com/app/stream_key2"