FFmpeg Multi RTMP Streaming Using Tee Protocol

This article provides a straightforward guide on how to use the FFmpeg tee muxer protocol to stream live video to multiple RTMP destinations simultaneously. You will learn the exact command structure, how to configure the video and audio parameters, and how to handle stream flags to ensure a reliable multi-platform broadcast without encoding your video multiple times.

Using the tee protocol in FFmpeg is the most efficient way to multi-stream because it encodes the input stream only once and splits the output to multiple destinations. This drastically reduces CPU usage compared to running multiple separate FFmpeg instances or encoding multiple streams inside a single command.

The Basic Command Structure

To stream to multiple RTMP targets, you need to set the output format to -f tee and map your video and audio streams into a pipe-delimited list of destinations.

Here is the template for the command:

ffmpeg -re -i input_source -c:v libx264 -preset veryfast -c:a aac -f tee -map 0:v -map 0:a "[f=flv]rtmp://dest1.example.com/live/stream_key|[f=flv]rtmp://dest2.example.com/live/stream_key"

Command Breakdown

Handling Connection Failures with onfail=ignore

By default, if one of your RTMP targets disconnects or fails to connect, the entire FFmpeg process will stop. To prevent a single target failure from killing your entire broadcast, you can append the onfail=ignore option to each stream.

Here is how to write the command with fault tolerance:

ffmpeg -re -i input.mp4 -c:v libx264 -preset veryfast -maxrate 3000k -bufsize 6000k -g 60 -c:a aac -f tee -map 0:v -map 0:a "[f=flv:onfail=ignore]rtmp://dest1.example.com/live/key1|[f=flv:onfail=ignore]rtmp://dest2.example.com/live/key2"

In this version, if dest1 goes offline, FFmpeg will print a warning but continue pushing the stream to dest2 without interruption.

Escaping Special Characters

RTMP stream keys often contain special characters like ?, &, or =. When these characters are placed inside the tee syntax, they can confuse the FFmpeg parser.

If your stream key contains special characters, you must escape the entire URL string or wrap the specific URL in single quotes within the double quotes:

"[f=flv]rtmp://dest1.com/live/key|[f=flv]'rtmp://dest2.com/live/key?option=value&other=value'"