Stream to Multiple SRT Targets Using FFmpeg Tee

This article demonstrates how to configure and run an FFmpeg command to stream live video to multiple SRT (Secure Reliable Transport) destinations simultaneously using the tee muxer. Utilizing the tee protocol allows you to encode your input stream only once, saving significant CPU and system resources while distributing the stream to multiple endpoints.

The Basic FFmpeg Tee Command for SRT

To stream to multiple SRT targets, you must use the tee muxer format (-f tee) and map your encoded audio and video streams to multiple outputs separated by the pipe (|) character. Because SRT typically carries MPEG-TS streams, you must explicitly specify the format as mpegts for each target inside the tee option.

Here is the standard command template:

ffmpeg -re -i input.mp4 \
  -c:v libx264 -preset veryfast -b:v 3000k -g 60 \
  -c:a aac -b:a 128k \
  -f tee -map 0:v -map 0:a \
  "[f=mpegts]srt://target1.example.com:1234?mode=caller|[f=mpegts]srt://target2.example.com:5678?mode=caller"

Command Breakdown

  • -re: Read the input at the native frame rate (essential for live streaming simulations from a file).
  • -i input.mp4: Your input source (this can be a local file, a capture card, or an RTMP/RTSP stream).
  • -c:v libx264 ... -c:a aac ...: Encodes the video to H.264 and the audio to AAC.
  • -f tee: Selects the tee muxer, which duplicates the encoded data to multiple destinations.
  • -map 0:v -map 0:a: Explicitly maps the first video stream and first audio stream to the tee muxer. This is required when using the tee format.
  • "[f=mpegts]srt://...": The double quotes contain the list of outputs.
    • [f=mpegts]: Applies the MPEG-TS container format to the individual SRT output.
    • |: The pipe character separates the different stream destinations.

Handling SRT Parameters and Escaping

SRT URLs often require additional parameters, such as latency, passphrase, or stream ID. When using these parameters inside the tee protocol, you must properly escape special characters (like ?, &, and =) to prevent FFmpeg or your command-line shell from misinterpreting them.

To pass multiple query parameters to an SRT target inside a tee command, escape the separator characters using backslashes:

ffmpeg -re -i input.mp4 \
  -c:v libx264 -b:v 4000k \
  -c:a aac -b:a 128k \
  -f tee -map 0:v -map 0:a \
  "[f=mpegts]srt://dest1.com:1234?mode=caller\&latency=200000|[f=mpegts]srt://dest2.com:5678?mode=caller\&latency=200000\&streamid=live/feed"

By using this configuration, FFmpeg will encode the input stream exactly once and duplicate the packets at the container level, allowing for efficient multi-destination SRT broadcasting.