寻求基于FFmpeg的极简SRT流媒体收发实现方案
Absolutely—you don’t need overcomplicated configurations to get SRT up and running with FFmpeg, just like your go-to UDP example! SRT does have a tiny bit more context than UDP (since it’s a connection-oriented protocol), but the basic commands are nearly identical in simplicity.
Prerequisite
First, confirm your FFmpeg build includes SRT support. Run this command and look for srt in the output:
ffmpeg -protocols
If it’s missing, you’ll need a version compiled with --enable-libsrt (most official prebuilt FFmpeg binaries include this by default now).
Sender Command (Caller Mode)
This sends your video stream directly to the receiver’s IP and port, mirroring your UDP workflow:
ffmpeg -i myfile.mp4 -vcodec libx264 -crf 12 -f mpegts srt://192.168.1.5:1234?mode=caller
Receiver Command (Listener Mode)
Start this first to listen for the incoming SRT stream:
ffplay srt://0.0.0.0:1234?mode=listener
Even Simpler Auto-Mode Alternative
If you don’t want to specify mode=caller/listener, FFmpeg can auto-negotiate the roles for you. Just start the receiver first:
ffplay srt://0.0.0.0:1234
Then run the sender command without the mode flag:
ffmpeg -i myfile.mp4 -vcodec libx264 -crf 12 -f mpegts srt://192.168.1.5:1234
FFmpeg will automatically set the receiver as the listener and the sender as the caller.
Quick Tips
- Why the mode? SRT uses a client-server model, so one side listens for connections (listener) and the other initiates the connection (caller). Auto mode handles this automatically if you start the receiver first.
- This setup uses SRT’s default low-latency, reliable settings—great for most simple streaming use cases.
- To save the stream to a file instead of playing it, replace the ffplay command with:
ffmpeg -i srt://0.0.0.0:1234?mode=listener -c copy output.mp4
That’s all there is to it—no config files, no extra hoops, just straightforward commands like your UDP example!
内容的提问来源于stack exchange,提问作者user1767754

