FFmpeg Low Latency RTMP Screen Capture Guide

Streaming your desktop screen with sub-second latency using RTMP and FFmpeg requires precise configuration of capture parameters, encoder settings, and network buffers. This guide provides a direct, highly optimized FFmpeg configuration designed to eliminate transmission delays, allowing you to achieve near-real-time performance for your live desktop streams.

The Optimized FFmpeg Command

To minimize latency under one second, you must capture the screen efficiently, use a fast encoding preset, disable frame reordering, and constrain the encoder’s buffer.

Here is the recommended command for Windows (using gdigrab):

ffmpeg -f gdigrab -framerate 30 -i desktop -c:v libx264 -preset ultrafast -tune zerolatency -pix_fmt yuv420p -g 30 -bf 0 -b:v 2500k -maxrate 2500k -bufsize 500k -f flv rtmp://your-rtmp-server/live/stream-key

For Linux (using x11grab), use this version:

ffmpeg -f x11grab -framerate 30 -video_size 1920x1080 -i :0.0 -c:v libx264 -preset ultrafast -tune zerolatency -pix_fmt yuv420p -g 30 -bf 0 -b:v 2500k -maxrate 2500k -bufsize 500k -f flv rtmp://your-rtmp-server/live/stream-key

Parameter Breakdown for Ultra-Low Latency

To understand why this command achieves sub-second latency, here is a breakdown of the critical parameters used:

Server and Player Considerations

Optimizing the FFmpeg encoder is only half of the equation; the receiving server and media player must also be optimized for low latency:

  1. Disable Player Buffering: Standard players like VLC or default web players often buffer 1 to 5 seconds of video to prevent stuttering. If you are playing the stream in VLC, use the argument --network-caching=100 to reduce the player’s internal buffer.
  2. Use Low-Latency Players: For web-based playback, use a library specifically configured for low latency, such as hls.js with low-latency settings, or ingest the RTMP stream into a server that transmuxes to WebRTC or low-latency HTTP-FLV.