Stream to Multiple RTSP Targets with FFmpeg Tee

This article explains how to configure and run an FFmpeg command to stream a single video input to multiple RTSP (Real-Time Streaming Protocol) destinations simultaneously using the tee muxer. By utilizing this method, you can duplicate your stream at the container level, saving valuable CPU resources by encoding the video only once.

The FFmpeg Tee Muxer Concept

The tee muxer in FFmpeg behaves like the Unix tee command: it splits a single input stream and writes it to multiple outputs. When streaming to multiple RTSP targets, this allows you to compress the video and audio once and send the resulting packets to multiple network destinations.

The FFmpeg Command Syntax

To stream to multiple RTSP targets, use the following command structure:

ffmpeg -re -i input.mp4 -c:v libx264 -preset veryfast -c:a aac -f tee -map 0:v -map 0:a "[f=rtsp;rtsp_transport=tcp]rtsp://server1.com:554/live/stream1|[f=rtsp;rtsp_transport=tcp]rtsp://server2.com:554/live/stream2"

Command Breakdown

Streaming Without Re-encoding (Stream Copy)

If your input file or camera feed is already in the correct format (e.g., H.264 video and AAC audio), you can bypass encoding entirely to drastically reduce CPU usage. Use the -c copy flag:

ffmpeg -re -i input.mp4 -c copy -f tee -map 0:v -map 0:a "[f=rtsp]rtsp://server1.com:554/live/stream1|[f=rtsp]rtsp://server2.com:554/live/stream2"

Handling Failures

By default, if one of the RTSP connections fails, the entire FFmpeg process may crash. If you want the stream to continue running even if one target goes offline, add the onfail=ignore option to each output within the brackets:

ffmpeg -re -i input.mp4 -c copy -f tee -map 0:v -map 0:a "[f=rtsp;onfail=ignore]rtsp://server1.com:554/live/stream1|[f=rtsp;onfail=ignore]rtsp://server2.com:554/live/stream2"