How to Stream to Multiple Destinations with FFmpeg Tee

This article explains how to use the FFmpeg tee muxer to broadcast a single media stream to multiple network destinations simultaneously. You will learn the syntax required to duplicate your output, how to configure the command for live streaming protocols like RTMP, and how to prevent a connection failure at one destination from stopping your entire broadcast.

Understanding the FFmpeg Tee Muxer

The tee muxer in FFmpeg allows you to write the same video and audio packets to multiple outputs. Instead of encoding the input video multiple times—which consumes massive amounts of CPU or GPU resources—FFmpeg encodes the stream once and duplicates the encoded packets to your specified network addresses.

Basic Syntax

The basic structure of an FFmpeg command using the tee muxer looks like this:

ffmpeg -i input -c:v libx264 -c:a aac -f tee -map 0 "[f=flv]rtmp://address1/key|[f=flv]rtmp://address2/key"

Here is a breakdown of the key components: * -f tee: Tells FFmpeg to use the tee muxer. * -map 0: Maps all streams (video and audio) from the first input to the outputs. This is required when using the tee muxer. * The double quotes "": Enclose all target destinations. * The pipe |: Serves as the delimiter separating each destination. * [f=flv]: Specifies the container format for that specific destination (FLV is standard for RTMP streaming).

Practical Example: Streaming to YouTube and Twitch

To stream a live RTMP feed (such as a camera or local RTMP input) to both YouTube and Twitch simultaneously, you can use the following command:

ffmpeg -re -i input.mp4 -c:v libx264 -preset veryfast -maxrate 3000k -bufsize 6000k -pix_fmt yuv420p -g 60 -c:a aac -b:a 128k -f tee -map 0 "[f=flv]rtmp://a.rtmp.youtube.com/live2/your_youtube_key|[f=flv]rtmp://live.twitch.tv/app/your_twitch_key"

In this command, -re forces FFmpeg to read the input in real-time, which is essential for live streaming local files.

Handling Network Disconnections

By default, if one of your network destinations disconnects or fails, the entire FFmpeg process will crash, stopping the stream to all other destinations. To prevent this, you must apply the on_error=ignore option to each output.

Modify your destination string to include the error-handling flag:

ffmpeg -i input -c:v libx264 -c:a aac -f tee -map 0 "[f=flv:on_error=ignore]rtmp://address1/key|[f=flv:on_error=ignore]rtmp://address2/key"

With on_error=ignore applied, if the connection to address1 drops, FFmpeg will print a warning in the console but will continue streaming to address2 uninterrupted.