How to Force FFmpeg to Use UDP for RTSP Capture

This guide explains how to configure FFmpeg to ingest Real-Time Streaming Protocol (RTSP) video streams using UDP instead of TCP. By default, FFmpeg often negotiates TCP to minimize packet loss, but switching to UDP reduces latency and network overhead for real-time applications. Below, you will find the exact command-line options, syntax placement, and troubleshooting steps required to enforce UDP transport.

The -rtsp_transport Flag

To force FFmpeg to capture an RTSP stream over UDP, use the demuxer option -rtsp_transport udp.

Because this is an input option, it must be placed before the -i input flag in your command:

ffmpeg -rtsp_transport udp -i rtsp://username:password@camera_ip:554/stream -c copy output.mp4

Command Breakdown

  • -rtsp_transport udp: Instructs the RTSP demuxer to request UDP data packets for the RTP audio and video channels from the streaming server.
  • -i rtsp://...: Specifies the input RTSP URL.
  • -c copy: Copies the video and audio streams directly without re-encoding, preserving quality and keeping CPU usage minimal.
  • output.mp4: Defines the destination file (or output stream URL).

Live Playback or Transcoding Example

If you are using FFmpeg (or ffplay) for live monitoring with minimal latency:

ffplay -rtsp_transport udp rtsp://username:password@camera_ip:554/stream

To transcode the incoming UDP stream to a local H.264 file:

ffmpeg -rtsp_transport udp -i rtsp://username:password@camera_ip:554/stream -c:v libx264 -preset ultrafast -c:a aac output.mkv

UDP Multicast Streams

If your RTSP server broadcasts via UDP multicast rather than unicast, specify udp_multicast instead:

ffmpeg -rtsp_transport udp_multicast -i rtsp://camera_ip:554/stream -c copy output.mp4

Important Considerations for UDP Transport

  • Packet Loss: UDP does not perform retransmission handshakes like TCP. If network bandwidth is unstable, you may experience artifacts, smearing, or dropped frames.
  • Firewalls and NAT: RTSP over UDP uses dynamic port ranges for RTP (media) and RTCP (control) packets. Ensure your local firewall allows inbound UDP traffic on the negotiated ports, otherwise the stream will connect but no media will be received.
  • Fallback Behavior: Unlike using tcp, setting the flag explicitly to udp prevents FFmpeg from silently falling back to alternative protocols if the UDP stream fails.