Configure SRT Stream ID in FFmpeg

This article provides a quick guide on how to configure the stream identifier (streamid) parameter in a Secure Reliable Transport (SRT) URL using FFmpeg. You will learn the correct URL syntax, how to format the parameter for both simple and complex routing scenarios, and how to execute the command properly in your terminal.

The SRT streamid Parameter Syntax

In FFmpeg, the streamid is passed as a query parameter at the end of the SRT destination or source URL. The basic syntax for the URL is:

srt://<hostname>:<port>?streamid=<value>

When running this command in a terminal (like bash or zsh), you must enclose the entire URL in double quotes. This prevents the shell from misinterpreting special characters (like ?, !, or &) as shell operators.

Configuration Examples

1. Simple Stream ID

If your SRT gateway or receiver only requires a simple string identifier, append ?streamid=YOUR_ID to the URL.

ffmpeg -re -i input.mp4 -c copy -f mpegts "srt://127.0.0.1:9000?streamid=live/stream1"

2. Standard Key-Value (Haivision) Format

Many enterprise SRT routers (such as the Haivision Media Gateway) use a standardized, comma-separated key-value format prefixed with #!::. The standard keys are: * u: Username / User ID * r: Resource name (stream name) * m: Mode (e.g., publish or request)

To configure this in FFmpeg, format the URL as follows:

ffmpeg -re -i input.mp4 -c:v libx264 -c:a aac -f mpegts "srt://192.168.1.100:9000?streamid=#!::u=publisher,r=live/feed1,m=publish"

3. URL Encoding for Special Characters

If your streamid contains characters that are reserved in URLs (such as spaces, slashes, or hash marks), you should URL-encode them to ensure FFmpeg parses the string correctly.

For example, the character # encodes to %23, and ! encodes to %21.

ffmpeg -re -i input.mp4 -c copy -f mpegts "srt://192.168.1.100:9000?streamid=%23%21::u=user1,r=show"

Verifying the Configuration

To verify that FFmpeg is sending the streamid correctly, you can increase the log level of your FFmpeg command to debug by adding -loglevel debug to your command:

ffmpeg -loglevel debug -re -i input.mp4 -c copy -f mpegts "srt://127.0.0.1:9000?streamid=test-stream"

In the terminal output, look for the SRT socket configuration lines, which will display the parsed streamid parameter being passed to the SRT library.