Stream Live Desktop as DASH Feed Using FFmpeg
This article explains how to capture your live desktop activity and broadcast it as a Dynamic Adaptive Streaming over HTTP (DASH) feed using FFmpeg. You will learn the exact FFmpeg commands, encoding configurations, and DASH segmenting parameters required to generate a manifest file and media segments for real-time streaming.
Prerequisites
To stream your desktop, you must have FFmpeg installed on your
system. Your FFmpeg build needs to be compiled with support for: * An
input device grabber (gdigrab for Windows,
x11grab for Linux, or avfoundation for macOS).
* The libx264 video encoder. * The dash
muxer.
Step 1: Identify Your Screen Capture Input
The command to capture your desktop depends on your operating system.
Windows (using gdigrab)
-f gdigrab -framerate 30 -i desktopLinux (using x11grab)
-f x11grab -video_size 1920x1080 -framerate 30 -i :0.0macOS (using avfoundation)
-f avfoundation -framerate 30 -i "1"Step 2: Configure Video Encoding for DASH
DASH streams require video to be divided into precise segments. To
achieve seamless playback, you must force regular keyframe intervals
(GOP size). If your target frame rate is 30 fps, a keyframe interval of
60 (-g 60) ensures a keyframe is generated every 2
seconds.
Key video encoding parameters: * -c:v libx264: Encodes
video using H.264. * -pix_fmt yuv420p: Ensures maximum
player compatibility. * -preset veryfast: Minimizes CPU
usage during live capture. *
-g 60 -keyint_min 60 -sc_threshold 0: Forces keyframes
every 60 frames and disables scene change detection to maintain
fixed-duration segments.
Step 3: Configure the DASH Muxer
To format the output as a live DASH stream, use FFmpeg’s DASH muxer
(-f dash) with the following settings: *
-seg_duration 2: Sets the segment duration to 2 seconds
(matches the 60-frame GOP size at 30 fps). *
-window_size 5: Retains only the last 5 segments in the
manifest, which is ideal for reducing latency in live streams. *
-remove_at_exit 1: Automatically deletes old segments when
the stream stops. * -use_template 1 -use_timeline 0:
Generates a clean, template-based manifest file structure.
Step 4: Run the Complete Command
Combine the input, encoding, and DASH muxing parameters into a single command.
Windows Command Example:
ffmpeg -f gdigrab -framerate 30 -i desktop \
-c:v libx264 -pix_fmt yuv420p -preset veryfast -g 60 -keyint_min 60 -sc_threshold 0 \
-b:v 2500k -maxrate 2500k -bufsize 5000k \
-f dash -seg_duration 2 -window_size 5 -remove_at_exit 1 -use_template 1 -use_timeline 0 \
live_stream.mpdLinux Command Example:
ffmpeg -f x11grab -video_size 1920x1080 -framerate 30 -i :0.0 \
-c:v libx264 -pix_fmt yuv420p -preset veryfast -g 60 -keyint_min 60 -sc_threshold 0 \
-b:v 2500k -maxrate 2500k -bufsize 5000k \
-f dash -seg_duration 2 -window_size 5 -remove_at_exit 1 -use_template 1 -use_timeline 0 \
live_stream.mpdStep 5: Serve and Play the Stream
Running the command generates a master manifest file
(live_stream.mpd) and several media segment files
(.m4s) in your working directory.
To make the stream viewable: 1. Host the files:
Serve the directory containing the output files using a web server (such
as Nginx, Apache, or a simple Node.js/Python HTTP server). Ensure CORS
headers are enabled so web players can fetch the files. 2. Play
the stream: Load the URL of your .mpd file (e.g.,
http://localhost:8080/live_stream.mpd) in a DASH-compatible
web player like Dash.js, Shaka Player, or VLC media player.