Skip to content
systemcoding.dev
Media

Read RTSP over TCP with -rtsp_transport tcp

Read an RTSP camera over TCP with ffmpeg 7.1 -rtsp_transport tcp, which avoids the packet loss and blocked ports UDP runs into.

1 min read
Summarize in AI

FFmpeg tries UDP first for RTSP media. On Wi-Fi, through a firewall or across a VPN, UDP packets are lost or blocked, and you get grey smeared frames or a long hang before it falls back. -rtsp_transport tcp puts the media inside the RTSP control connection instead.

Shell
ffmpeg -rtsp_transport tcp -i rtsp://192.168.1.50:554/stream1 -c copy -t 10 clip.mp4
Text
Input #0, rtsp, from 'rtsp://192.168.1.50:554/stream1':
  Stream #0:0: Video: h264 (Main), yuv420p(progressive), 1920x1080, 25 fps, 25 tbr, 90k tbn
Output #0, mp4, to 'clip.mp4':
Stream mapping:
  Stream #0:0 -> #0:0 (copy)

The option is an input option, so it goes before -i. Besides tcp and udp, FFmpeg 7.1 accepts udp_multicast, http and https for tunnelled RTSP. -t 10 stops after ten seconds so the test ends by itself.

TCP trades a bit of latency for reliability. A lost packet blocks everything behind it until it is resent, so after a bad stretch of network the picture arrives late rather than damaged. For a camera on the same switch, UDP is fine and slightly faster. The camera's own address, port and path come from its manual; credentials go in the URL as rtsp://user:pass@host/path, which also puts the password in your shell history and in the process list, so read it from an environment variable in scripts.

Also inNetworking
Taggedffmpeg
Share

More snippets

Media

List ALSA devices with aplay -l

List the playback cards and devices ALSA sees with aplay -l from alsa-utils 1.2, and turn the output into a hw:card,device name.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.