How to Set SRT Latency and Encryption in FFmpeg

This article provides a quick guide on how to configure latency and encryption key parameters for the Secure Reliable Transport (SRT) protocol using FFmpeg. You will learn the exact command-line syntax and parameter options required to secure your stream and optimize latency for stable transmission over the internet.

To configure SRT parameters in FFmpeg, you must append them as query parameters to the SRT destination or source URL. The URL format follows the standard structure: srt://hostname:port?parameter1=value1&parameter2=value2.

Setting the Latency Parameter

The latency parameter defines the recovery buffer size to handle packet loss over unstable networks. In FFmpeg, latency is configured using the latency parameter and is measured in microseconds (1 second = 1,000,000 microseconds).

To set a latency of 2 seconds (2,000,000 microseconds), append latency=2000000 to your SRT URL:

srt://12.34.56.78:9000?latency=2000000

Note: You can also specify rcvlatency (receiver latency) and peerlatency individually if your workflow requires asymmetric latency settings, though setting latency generally configures both simultaneously.

Setting the Encryption Parameters

To secure your SRT stream, you must define a passphrase and the key length. SRT uses AES encryption.

  1. passphrase: The secret password used to encrypt the stream. It must be between 10 and 79 characters long.
  2. pbkeylen: The crypto key length in bytes. Accepted values are:
    • 16 for AES-128 encryption
    • 24 for AES-192 encryption
    • 32 for AES-256 encryption (recommended)

To encrypt your stream with a passphrase of “MySecurePassword123” and AES-256 encryption, use the following format:

srt://12.34.56.78:9000?passphrase=MySecurePassword123&pbkeylen=32

Complete FFmpeg Command Example

When putting these parameters together, ensure you wrap the entire SRT URL in quotation marks. On Linux or macOS, the ampersand (&) character can be interpreted by the terminal as a background command separator if the URL is not properly quoted.

Here is a complete FFmpeg command that transcodes an input file and streams it over SRT with a 1.5-second latency and AES-256 encryption:

ffmpeg -re -i input.mp4 -c:v libx264 -preset veryfast -c:a aac -f mpegts "srt://203.0.113.50:9000?latency=1500000&passphrase=MySuperSecretKey&pbkeylen=32"