Stream SRT to Multiple Destinations Using FFmpeg
This article explains how to use FFmpeg to split and push a single
live stream to multiple SRT (Secure Reliable Transport) destinations
simultaneously. You will learn the core FFmpeg commands, specifically
utilizing the tee muxer, to achieve efficient, low-latency
multi-streaming without overloading your CPU.
To push a live stream to multiple SRT servers, you should avoid
encoding the stream multiple times. Instead, encode the stream once and
use FFmpeg’s tee muxer to duplicate the output and send it
to your target SRT destinations.
The FFmpeg Command
Below is the standard command template for capturing an input stream,
encoding it, and distributing it to two different SRT servers using the
tee muxer:
ffmpeg -re -i input_source -c:v libx264 -preset veryfast -g 60 -b:v 4000k \
-c:a aac -b:a 128k -f tee -map 0:v -map 0:a \
"[f=mpegts]srt://server1.example.com:9000?mode=caller|[f=mpegts]srt://server2.example.com:9000?mode=caller"Command Breakdown
-re: Reads the input at the native frame rate. This is required when streaming a static file as a live source. If your input is a live capture card or an incoming RTMP stream, you can omit this.-i input_source: Specifies your input stream (e.g., a webcam, local video file, or RTMP feed).-c:v libx264 -preset veryfast -g 60 -b:v 4000k: Encodes the video to H.264 with a bitrate of 4000 kbps. The-g 60flag sets the keyframe interval (GOP size), which is important for maintaining stream stability.-c:a aac -b:a 128k: Encodes the audio to AAC at 128 kbps.-f tee: Activates theteemuxer, which duplicates the encoded data payload to multiple outputs.-map 0:v -map 0:a: Selects the first video and audio streams from the input to be duplicated."[f=mpegts]srt://...|[f=mpegts]srt://...": Defines the SRT destinations.- The double quotes wrap the entire output string.
- Each destination is separated by a pipe character
(
|). [f=mpegts]is prepended to each URL because SRT requires the MPEG-TS container format.?mode=callertells FFmpeg to initiate the connection to the receiving SRT servers.
Handling Connection Failures
By default, if one of the SRT destinations fails or disconnects, the
entire FFmpeg process may stop. To prevent a single server failure from
interrupting the other stream, add the onfail=ignore option
to the tee muxer configuration:
"[f=mpegts:onfail=ignore]srt://server1.example.com:9000|[f=mpegts:onfail=ignore]srt://server2.example.com:9000"Using this syntax, FFmpeg will continue pushing the live stream to the active server even if the other connection drops.