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
-re: Reads the input at the native frame rate. This is required when streaming a static file (like an MP4) to simulate a live feed.-i input.mp4: Defines your input source (this could also be an RTMP stream, a capture card, or an IP camera).-c:v libx264 -preset veryfast: Encodes the video to H.264 using a fast preset to keep CPU usage low.-c:a aac: Encodes the audio to AAC format.-f tee: Specifies the output format as theteemuxer.-map 0:v -map 0:a: Maps all video and audio streams from the first input to the output."[f=rtsp;rtsp_transport=tcp]rtsp://...|[f=rtsp...]rtsp://...": The double quotes contain the list of targets separated by the pipe (|) character.f=rtsp: Tells the tee muxer to format this specific output as RTSP.rtsp_transport=tcp: Forces TCP transport for the RTSP stream, which is highly recommended for stability over network packets.
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"