Capture SRT Live Stream to MPEG-TS with FFmpeg
This article provides a quick guide on how to capture a Secure Reliable Transport (SRT) live stream and save it directly to an MPEG-TS (.ts) file using FFmpeg. You will learn the exact command-line syntax for both Caller and Listener modes, how to configure crucial SRT latency parameters, and how to record the stream without re-encoding to save CPU resources.
The Basic FFmpeg Command
To capture an SRT stream and save it to an MPEG-TS container without re-encoding the video and audio, use the following basic command:
ffmpeg -i "srt://<IP_ADDRESS>:<PORT>?mode=caller" -c copy -f mpegts output.tsParameter Breakdown
-i "srt://...": Specifies the input SRT URL. Wrap the URL in quotation marks to prevent the command line from misinterpreting the query parameters (like?and&).-c copy: Instructs FFmpeg to stream-copy the video and audio codecs. This avoids re-encoding, preserving the original quality and requiring minimal CPU usage.-f mpegts: Forces the output format to MPEG-TS.output.ts: The path and filename where the captured stream will be saved.
Scenario 1: FFmpeg as a Caller (Pulling the Stream)
If you are pulling a stream from an external SRT source that is configured as a listener, run FFmpeg in caller mode. You must specify the remote server’s IP address and port.
ffmpeg -i "srt://192.168.1.50:9000?mode=caller&latency=200000" -c copy -f mpegts output.tsNote: The latency parameter is defined in
microseconds. 200000 equals 200 milliseconds of latency
buffer, which helps prevent packet loss over unstable networks.
Scenario 2: FFmpeg as a Listener (Receiving a Pushed Stream)
If a camera, encoder, or external server is pushing (calling) the SRT
stream to your machine, you must set FFmpeg to listener mode. Use
0.0.0.0 to bind to all network interfaces on your local
machine.
ffmpeg -i "srt://0.0.0.0:9000?mode=listener" -c copy -f mpegts output.tsOnce you run this command, FFmpeg will pause and wait for the
incoming SRT connection before it starts writing the
output.ts file.
Important SRT Query Parameters
You can append several parameters to the SRT URL to optimize the connection:
latency: The buffer latency in microseconds. For example,&latency=300000sets a 300ms buffer. Both the sender and receiver should ideally have matching latency settings.passphrase: If the SRT stream is encrypted, append your password using&passphrase=YourPasswordHere.pbkeylen: Specifies the crypto key length (typically16,24, or32bytes, corresponding to AES-128, AES-192, and AES-256). For example,&pbkeylen=32.