Configure FFmpeg Tee Protocol Connection Timeouts

This article explains how to configure individual connection timeouts for multiple stream targets when using the FFmpeg tee pseudo-muxer. You will learn the correct syntax to apply protocol-specific timeout options, such as rw_timeout, to each stream target independently, ensuring that a slow or unresponsive connection to one destination does not freeze your entire streaming pipeline.

To configure connection timeouts for individual targets within the FFmpeg tee protocol, you must pass protocol-specific options inside the bracketed prefix assigned to each target.

The tee muxer uses the following general syntax to apply options to a target:

"[f=format:option1=value1:option2=value2]target_url"

Step-by-Step Configuration

1. Identify the Correct Timeout Parameter

Different network protocols in FFmpeg use different parameters to handle connection and read/write timeouts: * RTMP / TCP / HTTP: Use rw_timeout (defined in microseconds). * RTSP: Use stimeout (defined in microseconds). * UDP: Use timeout (defined in microseconds).

2. Apply the Timeout to the Target

To set a timeout, convert your desired timeout duration from seconds to microseconds (1 second = 1,000,000 microseconds) and place it inside the target’s bracketed options.

For example, to set a 5-second connection timeout for an RTMP target, use rw_timeout=5000000.

3. Handle Connection Failures with on_error

By default, if one target in a tee output fails or times out, the entire FFmpeg process may stop. To prevent this, pair your timeout configuration with the on_error=ignore option. This ensures that if one target times out, FFmpeg will continue streaming to the remaining healthy targets.

Full Command Example

The following command streams an input to two different RTMP destinations with independent connection timeouts:

ffmpeg -i input.mp4 -c:v libx264 -c:a aac -f tee \
"[f=flv:on_error=ignore:rw_timeout=5000000]rtmp://live.twitch.tv/app/stream_key|[f=flv:on_error=ignore:rw_timeout=10000000]rtmp://a.rtmp.youtube.com/live2/stream_key"

In this example: * The first target (Twitch) is configured with a 5-second connection timeout (rw_timeout=5000000). * The second target (YouTube) is configured with a 10-second connection timeout (rw_timeout=10000000). * Both targets utilize on_error=ignore so that a timeout on either connection does not interrupt the other stream.