Low Latency RTSP Streaming with FFmpeg

Streaming live video over RTSP (Real-Time Streaming Protocol) with minimal delay is crucial for applications like security surveillance, live broadcasting, and interactive video feeds. This guide provides a straightforward, step-by-step approach to configuring FFmpeg for low-latency RTSP streaming, highlighting the essential command-line arguments and optimization techniques needed to reduce lag to sub-second levels.

To achieve ultra-low latency, you must optimize both the encoding process and the transport settings. FFmpeg allows you to bypass default buffering behaviors and configure the video encoder specifically for real-time delivery.

The Low-Latency FFmpeg Command

Below is a highly optimized FFmpeg command template designed to capture a video input (such as a local camera) and stream it to an RTSP server with minimal delay:

ffmpeg -f dshow -i video="Integrated Camera" -vcodec libx264 -preset ultrafast -tune zerolatency -fflags nobuffer -flags low_delay -g 30 -an -f rtsp -rtsp_transport tcp rtsp://localhost:8554/live

(Note: Replace -f dshow -i video="Integrated Camera" with your specific input source, such as /dev/video0 on Linux or an existing media file).

Key Parameter Breakdown

To understand how this command minimizes latency, here is an explanation of the critical parameters used:

Reducing Latency on the Receiver Side

A low-latency stream is only as good as the player rendering it. Many media players (like VLC) buffer several seconds of video by default to prevent stuttering. To view your RTSP stream with minimal latency, use ffplay with buffering disabled:

ffplay -fflags nobuffer -flags low_delay -rtsp_transport tcp rtsp://localhost:8554/live

By combining these sender-side FFmpeg configurations with a zero-buffer receiver, you can successfully achieve sub-second latency over RTSP.