Configure SRT Connection Timeout in FFmpeg

This article provides a quick guide on how to configure the connection handshaking timeout for Secure Reliable Transport (SRT) streams in FFmpeg. You will learn the specific URL parameters required to adjust this duration, helping you prevent infinite connection hangs and optimize your live streaming workflows.

To configure the connection handshaking timeout in FFmpeg for SRT, you must append the handshake_timeout parameter directly to the SRT destination or source URL as a query string.

The handshake_timeout Parameter

The handshake_timeout option controls the maximum time FFmpeg will wait for the SRT handshake to complete before closing the connection.

URL Syntax

To apply this setting, add ?handshake_timeout=VALUE to the end of your SRT URL. If you are already using other query parameters (like mode or latency), separate them using an ampersand (&).

Basic Syntax:

srt://<IP_ADDRESS>:<PORT>?handshake_timeout=<MICROSECONDS>

Multiple Parameters Syntax:

srt://<IP_ADDRESS>:<PORT>?mode=caller&latency=2000000&handshake_timeout=5000000

Practical FFmpeg Examples

1. Streaming to an SRT Receiver (Caller Mode)

If you want to stream video to a remote server and set the handshake timeout to 5 seconds (5,000,000 microseconds), use the following command:

ffmpeg -re -i input.mp4 -c:v libx264 -preset veryfast -c:a aac -f mpegts "srt://192.168.1.100:9000?mode=caller&handshake_timeout=5000000"

2. Receiving an SRT Stream (Listener Mode)

If your FFmpeg instance is listening for an incoming SRT stream and you want to set the connection handshake timeout to 3 seconds (3,000,000 microseconds):

ffmpeg -i "srt://0.0.0.0:9000?mode=listener&handshake_timeout=3000000" -c copy output.mp4

Important Considerations