Route FFmpeg Tee Outputs to Specific Network Interfaces
When streaming to multiple destinations simultaneously using the
FFmpeg tee protocol, you may need to route specific outputs
through different network interfaces or physical network adapters. This
guide explains how to bind individual target streams within the
tee pseudo-muxer to specific local IP addresses, allowing
you to control which network interface each stream uses.
The Core Concept: Binding to a Local IP
FFmpeg does not select network interfaces by their system name (like
eth0 or wlan0). Instead, it routes traffic
through specific network interfaces by binding to the local IP
address assigned to that interface.
To route different outputs of a tee stream through
different interfaces, you must pass the appropriate local binding
options (localaddr or protocol-specific variants) to each
target stream inside the tee syntax.
1. Configuring UDP Targets
For UDP streams (often used for MPEG-TS), you can bind to a specific
network interface by appending the localaddr parameter
directly to the target URL query string.
Syntax:
udp://[destination_ip]:[port]?localaddr=[local_interface_ip]
Example within tee:
ffmpeg -i input.mp4 -map 0 -c copy -f tee \
"[f=mpegts]udp://233.0.0.1:1234?localaddr=192.168.1.50|[f=mpegts]udp://233.0.0.1:1234?localaddr=10.0.0.50"In this example: * The first stream is routed through the interface
with the IP 192.168.1.50. * The second stream is routed
through the interface with the IP 10.0.0.50.
2. Configuring RTMP Targets
For RTMP streaming (commonly used for YouTube, Twitch, or Facebook),
FFmpeg’s RTMP protocol utilizes the rtmp_localaddr option.
Within the tee muxer, you must pass this as a per-output
option inside the bracketed prefix.
Syntax:
[f=flv:rtmp_localaddr=[local_interface_ip]]rtmp://[destination_url]
Example within tee:
ffmpeg -i input.mp4 -c:v libx264 -c:a aac -f tee \
"[f=flv:rtmp_localaddr=192.168.1.50]rtmp://a.rtmp.youtube.com/live2/key1|[f=flv:rtmp_localaddr=10.0.0.50]rtmp://live-api-s.facebook.com:80/rtmp/key2"- The YouTube stream is forced out of the network adapter assigned to
192.168.1.50. - The Facebook stream is forced out of the network adapter assigned to
10.0.0.50.
3. Configuring SRT Targets
For Secure Reliable Transport (SRT) streams, the parameter to bind to
a local network adapter is localadapter. This is appended
as a query parameter to the SRT URL.
Syntax:
srt://[destination_ip]:[port]?localadapter=[local_interface_ip]
Example within tee:
ffmpeg -i input.mp4 -map 0 -c copy -f tee \
"[f=mpegts]srt://destination1.com:9000?localadapter=192.168.1.50|[f=mpegts]srt://destination2.com:9000?localadapter=10.0.0.50"Troubleshooting Routing Issues
If your streams are still going through the default gateway instead of the specified interfaces, verify the following:
- Active IP Addresses: Ensure the local IP addresses specified in your command are currently assigned to active network adapters on your system.
- System Routing Tables: Operating system routing tables can sometimes override FFmpeg’s bind requests. Ensure your OS metric settings do not completely restrict traffic on the secondary interface.
- Escaping Characters: In complex terminal
environments (like Bash or Zsh), ensure your
teeargument is fully enclosed in double quotes to prevent the shell from misinterpreting the?,&, and|characters.