MPEG-DASH (Dynamic Adaptive Streaming over HTTP) is a segmented video streaming protocol standardized by ISO. It enables adaptive bitrate delivery by allowing clients to switch between different representations based on current network conditions. Implementation involves generating media segments, constructing MPD manifests, and configuring codec and packaging parameters using tools such as FFmpeg and MP4Box.
Protocol Structure
MPEG-DASH delivers content via two core components:
- MPD (Media Presentation Description): XML-based manifest describing media segment layout, timing, bitrate, and codec details.
- Media Segments: Typically stored in fragmented MP4 (.m4s) or WebM format and indexed via SegmentTemplate or SegmentList.
MPEG-DASH supports both static (VOD) and dynamic (live) presentations. Segment durations are typically between 2"6 seconds.
Segment and MPD Generation with FFmpeg + MP4Box
MPEG-DASH segment generation typically involves a two-step process: encoding and fragmentation using FFmpeg, followed by DASH packaging using MP4Box (from the GPAC toolkit).
Step 1: Encode and fragment using FFmpeg
Use FFmpeg to produce a fragmented MP4 file. The flags frag_keyframe and empty_moov are necessary to allow segmentation at keyframe boundaries.
ffmpeg -i input.mp4 \
-map 0:v -c:v:0 libx264 -b:v:0 5000k -s:v:0 1920x1080 \
-map 0:v -c:v:1 libx264 -b:v:1 3000k -s:v:1 1280x720 \
-map 0:a -c:a aac -b:a 128k \
-f mp4 -movflags frag_keyframe+empty_moov output_multi.mp4
Explanation:
- -i input.mp4: Specifies the input file to be transcoded.
- -c:v libx264: Sets the video codec to H.264 (libx264), widely supported for web and mobile playback.
- -b:v 3000k: Defines the target video bitrate at 3 Mbps, balancing quality and file size for streaming scenarios.
- -c:a aac: Sets the audio codec to AAC, a standard choice for compatibility and compression.
- -f mp4: Specifies the output container format as MP4.
- -movflags frag_keyframe+empty_moov: Enables fragmented MP4 output.
- frag_keyframe: Splits the video at keyframes into segments, enabling better seek and buffering performance.
- empty_moov: Places an empty moov atom at the beginning of the file so the video is streamable before full download.
- fragmented.mp4: Name of the output file, ready for delivery in streaming or progressive playback contexts.
Step 2: Generate DASH Segments and MPD with MP4Box
MP4Box is then used to divide the fragmented MP4 into .m4s segments and generate a valid manifest.mpd file.
MP4Box -dash 4000 -frag 1000 -rap -profile live -segment-name segment_ -out manifest.mpd fragmented.mp4Explanation:
- -dash 4000: Sets segment duration to 4000ms (4 seconds)
- -frag 1000: Sets fragment duration inside each segment
- -rap: Align segments on Random Access Points (keyframes)
- -profile live: Ensures the output meets live-streaming DASH profile constraints
- -segment-name: Sets base name for segment files
Multi-Bitrate (ABR) Packaging
Adaptive Bitrate (ABR) support allows clients to switch between resolutions based on bandwidth. This requires generating multiple encodes (renditions) and packaging them in a unified MPD.
Encoding Multiple Renditions:
Use FFmpeg to create multiple video streams at different resolutions and bitrates:
Example:
ffmpeg -i input.mp4 \
-map 0:v -c:v:0 libx264 -b:v:0 5000k -s:v:0 1920x1080 \
-map 0:v -c:v:1 libx264 -b:v:1 3000k -s:v:1 1280x720 \
-map 0:a -c:a aac -b:a 128k \
-f mp4 -movflags frag_keyframe+empty_moov output_multi.mp4
Explanation:
- -i input.mp4: Specifies the input media file.
- -map 0:v -c:v:0 libx264 -b:v:0 5000k -s:v:0 1920x1080: Maps the input video to the first video output stream, and encodes using H.264 (libx264) at 1920??1080 resolution and 5 Mbps bitrate.
- -map 0:v -c:v:1 libx264 -b:v:1 3000k -s:v:1 1280x720: Maps the input video again to create a second output video stream and encodes to 1280??720 resolution at 3 Mbps.
- -map 0:a -c:a aac -b:a 128k: Maps the input audio to one output audio stream and Encodes using the AAC codec at 128 kbps.
- -f mp4: Sets the output format to MP4.
- frag_keyframe: Fragment MP4 at keyframes, improving seek and buffering.
- empty_moov: Places an empty moov atom at the start of the file, making the video immediately streamable.
- output_multi.mp4: The name of the output file containing all encoded video/audio streams in a single fragmented MP4 container.
Segmenting and manifest generation:
After encoding, generate the DASH segments and master manifest:
MP4Box -dash 4000 -profile onDemand -out manifest.mpd -segment-name video_ output_multi.mp4Explanation:
- MP4Box: A command-line tool from the GPAC project used for packaging and segmenting MP4 files for adaptive streaming.
- -dash 4000: Sets the segment duration to 4000 milliseconds (4 seconds). Splits the input MP4 file into DASH-compliant segments of fixed duration.
- -profile onDemand: Specifies the MPEG-DASH On-Demand profile and allows clients to download segments based on available bandwidth.
- -out manifest.mpd: Defines the name of the generated MPEG-DASH manifest file.
- -segment-name video_: Sets the base name prefix for the output segment files and ensures predictable and organized segment naming.
- Output_multi.mp4: Input MP4 file containing multiple bitrate representations, and must be fragmented for compatibility.
MPD Structure Overview
The Media Presentation Description (MPD) is the central control structure for MPEG-DASH playback. It defines how media files are presented, aligned, and segmented.
<AdaptationSet mimeType="video/mp4" codecs="avc1.640028" segmentAlignment="true">
<Representation id="1080p" bandwidth="5000000" width="1920" height="1080">
<BaseURL>segment_1080p/</BaseURL>
<SegmentTemplate media="seg_$Number$.m4s" initialization="init.mp4" duration="4"/>
</Representation>
</AdaptationSet>
Explanation:
- AdaptationSet: Groups all representations for a media type (e.g., video)
- Representation: Single bitrate/resolution version
- SegmentTemplate: Defines how segments are named and timed
Live MPEG-DASH Streaming
MPEG-DASH can be used for live streaming by continuously updating the MPD and rotating segment files. FFmpeg supports DASH output directly for live scenarios.
Example with FFmpeg + DASH-IF IOP:
ffmpeg -re -i input.mp4 -c:v libx264 -c:a aac -f dash -window_size 5 -extra_window_size 5 -seg_duration 4 -use_timeline 1 -use_template 1 manifest.mpdExplantation:
- -window_size: Number of segments kept in the sliding window.
- -extra_window_size: Additional segments to maintain for late joins.
- -seg_duration: Segment length in seconds.
- -use_timeline and -use_template: Enables timeline-based MPD with templated segment naming.
FFmpeg will generate:
- manifest.mpd
- Initialization segments: init-stream0.m4s
- Media segments: chunk-stream0-00001.m4s, ...
This live MPD will continuously update and slide the window forward.
Server and Player Requirements
Proper server configuration is critical for successful MPEG-DASH delivery. The server must deliver the correct MIME types and allow cross-origin access when needed.
MIME Types:
Web servers must serve DASH manifests and segments with correct content types
types {
application/dash+xml mpd;
video/mp4 m4s;
}
CORS
To allow playback in cross-domain environments (e.g., embedded players), add:
add_header Access-Control-Allow-Origin *;Supported Players:
DASH content can be played using several open-source and native players:
- Shaka Player: JavaScript-based DASH and Widevine-compatible player.
- dash.js: Reference implementation of MPEG-DASH playback in HTML5.
- ExoPlayer: Android media player with full DASH support.
- Safari: Limited support depending on stream structure and codec compatibility.


