Configure SRT Stream Multiplexing in FFmpeg
This article provides a practical guide on how to configure Secure Reliable Transport (SRT) stream multiplexing using FFmpeg. You will learn how to combine multiple video, audio, and metadata streams into a single SRT container, configure the necessary MPEG-TS muxer settings, and execute precise FFmpeg commands for low-latency, multi-stream broadcasting.
Understanding SRT and Multiplexing
SRT is a latency-optimized streaming protocol that natively wraps media inside an MPEG Transport Stream (MPEG-TS) container. To multiplex (mux) multiple streams—such as one video track and multiple language audio tracks—into a single SRT broadcast, you must configure FFmpeg to map these streams correctly into an MPEG-TS format before sending them over the SRT protocol.
Step-by-Step Configuration
1. Map Your Input Streams
To multiplex multiple inputs, use the -map option in
FFmpeg. This tells FFmpeg exactly which video and audio streams to
include in the output multiplex.
-map 0:vselects the video from the first input.-map 1:aselects the audio from the second input (e.g., English audio).-map 2:aselects the audio from the third input (e.g., Spanish audio).
2. Set the MPEG-TS Muxer
Because SRT uses MPEG-TS, you must explicitly specify the format
using -f mpegts. You can also configure specific MPEG-TS
parameters to optimize the stream:
-mpegts_start_pid: Sets the starting Packet Identifier (PID) for the streams.-metadata service_provider: Defines the provider name.-metadata service_name: Defines the stream name.
3. Configure SRT Destination Parameters
The output URL must use the srt:// schema. You can
append configuration parameters to the URL query string, such as:
mode: Set tocaller(default),listener, orrendezvous.latency: Set in microseconds (e.g.,200000for 200ms).pkt_size: Set the packet size (typically1316for MPEG-TS over SRT).
Practical Command Examples
Example 1: Multiplexing One Video and Two Audio Tracks
This command takes a video file and two separate audio files, multiplexes them into a single MPEG-TS stream, and pushes it to an SRT receiver.
ffmpeg -re -i video.mp4 -i audio_en.wav -i audio_es.wav \
-map 0:v -map 1:a -map 2:a \
-c:v libx264 -preset veryfast -b:v 3000k \
-c:a aac -b:a 128k \
-f mpegts "srt://192.168.1.50:9000?mode=caller&latency=250000&pkt_size=1316"Example 2: Multiplexing Video, Audio, and Telemetry Data
If you need to stream video, audio, and synchronous data (like GPS or sensor telemetry via timed metadata), you can multiplex them like this:
ffmpeg -re -i camera_feed.mp4 -i telemetry_data.srt \
-map 0:v -map 0:a -map 1:s \
-c:v copy -c:a copy -c:s text \
-f mpegts "srt://192.168.1.50:9000?mode=caller&latency=200000"Troubleshooting and Key Considerations
- Audio/Video Sync: Always use the
-reflag when streaming local files in real-time to prevent the stream from encoding faster than real-time, which causes buffer overflows in SRT. - Packet Size: Always set
pkt_size=1316when muxing MPEG-TS. 1316 bytes is exactly seven 188-byte MPEG-TS packets, which fits perfectly into standard MTU Ethernet frames without fragmentation. - Latency Tuning: Ensure the
latencyparameter is configured identically on both the sender (caller) and receiver (listener) ends to prevent packet drop issues.