How to Stream SRT with Redundant Links in FFmpeg
This article provides a quick, practical guide on how to configure FFmpeg to stream video using Secure Reliable Transport (SRT) over redundant network connections. By leveraging SRT’s connection bonding capabilities (available in SRT v1.5 and later), you can prevent stream drops and buffer issues by distributing or duplicating your broadcast across multiple network interfaces, such as Ethernet and Wi-Fi or cellular.
Understanding SRT Connection Bonding
SRT connection bonding allows you to group multiple network links
into a single logical stream. To use this in FFmpeg, your FFmpeg build
must be compiled with libsrt version 1.5.0 or higher. There
are two primary bonding modes:
- Broadcast (Active-Active): Data is sent simultaneously over all configured network links. If one connection drops, the receiver continues decoding the stream from the other link without any packet loss. This is the most reliable mode for critical broadcasts.
- Backup (Active-Standby): One link is designated as primary, and the second link only transmits data if the primary link fails.
FFmpeg Command Syntax for SRT Redundancy
To stream using redundant links, you must format your output URI to define an SRT group.
Here is the template for streaming to a remote receiver using Broadcast mode over two local network adapters:
ffmpeg -re -i input.mp4 -c:v libx264 -preset veryfast -c:a aac -f mpegts \
"srt://?mode=caller&group=192.0.2.1:9000?localaddress=192.168.1.50,192.0.2.1:9000?localaddress=192.168.2.50&type=broadcast"Breaking Down the Parameters
group=: This parameter tells SRT to initialize a group connection. Inside this parameter, you list the destination endpoints separated by a comma.localaddress=: By appending?localaddress=[IP]to each member in the group, you force FFmpeg to bind each connection to a specific physical network interface on your local machine (e.g.,192.168.1.50for Ethernet and192.168.2.50for a 4G/5G cellular dongle).type=broadcast: This defines the bonding mode. Replacebroadcastwithbackupif you prefer the active-standby configuration.
Receiver Configuration
For redundant streaming to work, the receiving side must also support SRT group connections and listen for incoming bonded links. The receiver command in FFmpeg looks like this:
ffmpeg -i "srt://:9000?mode=listener&group=all" -c copy output.mp4group=all: This parameter tells the listener to accept grouped member connections from the sender, allowing the redundant streams to be merged back into a single, cohesive video feed.