How to Stream Desktop Capture via SRT Using FFmpeg

Streaming your desktop directly to a Secure Reliable Transport (SRT) server allows for high-quality, ultra-low-latency video delivery over unpredictable networks. This guide explains how to capture your screen on Windows, Linux, and macOS using FFmpeg and redirect the live feed to an SRT server in real time using optimal encoding settings for low latency.

Prerequisites

Ensure you have a recent build of FFmpeg installed with support for your operating system's desktop capture protocol and the libsrt library enabled. You can verify SRT support by running ffmpeg -protocols and checking for srt in the output.

1. Windows Screen Capture (gdigrab)

On Windows, use the gdigrab input device to capture the desktop display:

ffmpeg -f gdigrab -framerate 30 -i desktop \
  -c:v libx264 -preset ultrafast -tune zerolatency -pix_fmt yuv420p \
  -f mpegts "srt://<SERVER_IP>:<PORT>?mode=caller"

To include microphone or system audio, add DirectShow (dshow):

ffmpeg -f gdigrab -framerate 30 -i desktop \
  -f dshow -i audio="Microphone Array (Realtek Audio)" \
  -c:v libx264 -preset ultrafast -tune zerolatency -pix_fmt yuv420p \
  -c:a aac -b:a 128k \
  -f mpegts "srt://<SERVER_IP>:<PORT>?mode=caller"

2. Linux Screen Capture (x11grab)

On Linux systems using X11, capture your primary display using x11grab:

ffmpeg -f x11grab -framerate 30 -video_size 1920x1080 -i :0.0 \
  -c:v libx264 -preset ultrafast -tune zerolatency -pix_fmt yuv420p \
  -f mpegts "srt://<SERVER_IP>:<PORT>?mode=caller"

To include PulseAudio sound, prepend -f pulse -i default:

ffmpeg -f x11grab -framerate 30 -video_size 1920x1080 -i :0.0 \
  -f pulse -i default \
  -c:v libx264 -preset ultrafast -tune zerolatency -pix_fmt yuv420p \
  -c:a aac -b:a 128k \
  -f mpegts "srt://<SERVER_IP>:<PORT>?mode=caller"

3. macOS Screen Capture (avfoundation)

On macOS, use the avfoundation input framework. First, list your available devices by running ffmpeg -f avfoundation -list_devices true -i "". Then capture the screen index (typically 1:none for video only, or 1:0 for screen and mic):

ffmpeg -f avfoundation -framerate 30 -i "1:none" \
  -c:v libx264 -preset ultrafast -tune zerolatency -pix_fmt yuv420p \
  -f mpegts "srt://<SERVER_IP>:<PORT>?mode=caller"

Key Parameters Explained

  • -preset ultrafast & -tune zerolatency: Eliminates encoding delay and disables frame buffering in x264, essential for real-time transmission.
  • -pix_fmt yuv420p: Ensures broad player and decoder compatibility.
  • -f mpegts: SRT transmits raw payload packets, which requires wrapping the H.264 video inside an MPEG-TS container.
  • mode=caller: Connects FFmpeg to an external SRT receiver operating in listener mode.
  • latency=<microseconds>: Appended to the SRT URL (e.g., ?mode=caller&latency=200000 for 200ms) to configure the target buffer time for packet loss recovery.