Split FFmpeg Output Streams Using Tee Protocol

This article explains how to use the FFmpeg tee protocol to split a single output stream and distribute it to multiple network destinations simultaneously. By duplicating the output at the network transport layer, you can broadcast to multiple endpoints without the CPU overhead of re-encoding or re-muxing the media for each target.


Understanding the Tee Protocol

FFmpeg provides two ways to duplicate outputs: the tee muxer and the tee protocol. While the tee muxer duplicates streams at the container level (allowing for different file formats or metadata per output), the tee protocol operates at the network/transport layer.

The tee protocol takes the final, fully-muxed bitstream and writes the exact same bytes to multiple network addresses. This is highly efficient because the encoding and muxing processes only run once.

Basic Syntax

To use the tee protocol, prefix your output destination with tee: and separate each network destination URL with a pipe character (|). The entire destination string must be enclosed in quotation marks to prevent the command line shell from misinterpreting the pipe character.

"tee:URL1|URL2|URL3"

Practical Examples

1. Splitting a UDP Stream

If you need to send a live MPEG-TS stream to two different local or remote IP addresses over UDP, you can run the following command:

ffmpeg -re -i input.mp4 -c:v libx264 -c:a aac -f mpegts "tee:udp://192.168.1.50:5000|udp://192.168.1.60:5000"

In this command: * -re reads the input file in real-time. * -f mpegts specifies the container format (MPEG-TS) before passing it to the tee protocol. * The tee protocol replicates the exact MPEG-TS packets to both 192.168.1.50 and 192.168.1.60 on port 5000.

2. Multi-Platform RTMP Streaming

You can also use the tee protocol to stream to multiple RTMP ingest points (like YouTube and Twitch) at the same time, provided they accept the same container format (usually FLV for RTMP) and codecs.

ffmpeg -re -i input.mp4 -c:v libx264 -preset veryfast -maxrate 3000k -bufsize 6000k -c:a aac -f flv "tee:rtmp://a.rtmp.youtube.com/live2/your_youtube_key|rtmp://live.twitch.tv/app/your_twitch_key"

Important Considerations

While the tee protocol is highly efficient, there are several behaviors to keep in mind: