MPEG-DASH (Dynamic Adaptive Streaming over HTTP) is an international standard for adaptive streaming. This guide shows how to create DASH streams with FFmpeg.
HLS vs DASH
| Feature | HLS | DASH |
|---|---|---|
| Developer | Apple | MPEG (International Standard) |
| Manifest | .m3u8 | .mpd |
| Segments | .ts | .m4s |
| DRM Support | FairPlay | Widevine, PlayReady |
Basic DASH Encoding
ffmpeg -i input.mp4 -c:v libx264 -crf 21 -preset fast -c:a aac -b:a 128k -f dash -seg_duration 4 -use_timeline 1 -use_template 1 output.mpd
Multi-Bitrate DASH
ffmpeg -i input.mp4 -map 0:v -map 0:v -map 0:v -map 0:a -c:v libx264 -crf 21 -filter:v:0 "scale=1920:1080" -b:v:0 5000k -filter:v:1 "scale=1280:720" -b:v:1 2500k -filter:v:2 "scale=854:480" -b:v:2 1000k -c:a aac -b:a 128k -f dash -seg_duration 4 -adaptation_sets "id=0,streams=v id=1,streams=a" manifest.mpd
Key DASH Options
- -seg_duration: Segment length in seconds
- -use_timeline 1: Use SegmentTimeline in manifest
- -use_template 1: Use SegmentTemplate for URLs
- -adaptation_sets: Group video and audio streams
Serving DASH
Configure Nginx for DASH:
location /dash/ {
types {
application/dash+xml mpd;
video/mp4 m4s mp4;
}
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}
Playing DASH
Use dash.js or Shaka Player in your web application:
<script src="https://cdn.dashjs.org/latest/dash.all.min.js"></script>
<video id="video" controls></video>
<script>
var player = dashjs.MediaPlayer().create();
player.initialize(document.querySelector("#video"), "manifest.mpd", true);
</script>
Recommendation: For maximum compatibility, generate both HLS and DASH from the same source.