Force FFmpeg to Use UDP for RTSP Stream Capture
This article explains how to force FFmpeg to use the UDP protocol instead of TCP when capturing or streaming RTSP video. While TCP ensures reliable packet delivery, UDP is often preferred for real-time video streaming due to its lower latency and reduced overhead. Below, you will find the exact command-line parameters required to force this protocol switch and a clear explanation of how to implement them in your workflow.
By default, FFmpeg negotiate the transport protocol with the RTSP
server, which often results in fallback to TCP for reliability. To force
FFmpeg to use UDP, you must use the -rtsp_transport private
option.
The FFmpeg Command
To force UDP, insert the -rtsp_transport udp option
before your input stream URL. Placing it before the
input is crucial, as it tells FFmpeg to apply the setting to the
incoming stream demuxer.
Here is the standard command structure:
ffmpeg -rtsp_transport udp -i rtsp://your_camera_ip/stream_path -c copy output.mp4Command Breakdown
-rtsp_transport udp: This flag forces FFmpeg to establish the RTSP connection over UDP.-i rtsp://your_camera_ip/stream_path: Specifies the input RTSP stream URL.-c copy: Copies the video and audio streams directly without re-encoding, saving CPU resources.output.mp4: The destination file where the stream will be saved.
Why Use UDP?
Using UDP (User Datagram Protocol) reduces latency because it does not require the handshaking and packet retransmission checks that TCP does. This makes it ideal for live monitoring and real-time security camera feeds where a slight delay is more problematic than a few dropped frames.
Note that if your network has high packet loss, forcing UDP may result in visible artifacts or gray screens in the captured video. If you experience severe packet loss, ensure that your network switches and firewalls are configured to allow UDP traffic on the specified RTSP ports.