Configure ffmpeg DASH Adaptation Sets

When streaming video using Dynamic Adaptive Streaming over HTTP (DASH), organizing video, audio, and subtitle streams into logical adaptation sets is crucial for client-side playback compatibility. This article provides a direct guide on how to configure adaptation sets in a DASH manifest using FFmpeg, focusing on the -adaptation_sets option, its syntax, and practical command-line examples for various streaming scenarios.

The -adaptation_sets Option

In FFmpeg, the DASH muxer uses the -adaptation_sets option to group different media streams (such as different resolutions of a video, different language audio tracks, or subtitles) into distinct <AdaptationSet> elements within the Media Presentation Description (MPD) manifest.

The basic syntax for this option is:

-adaptation_sets "id=dataset_id,streams=stream_identifiers id=dataset_id,streams=stream_identifiers ..."

Each adaptation set definition is separated by a space, and the entire argument is enclosed in quotes.

Key Parameters

Practical Configuration Examples

1. Automatic Grouping by Media Type

If you have a standard source with one video stream and one audio stream, you can automatically group them by their media type:

ffmpeg -i input.mp4 -map 0:v -map 0:a -f dash -adaptation_sets "id=0,streams=v id=1,streams=a" output.mpd

This configuration creates two adaptation sets: one containing all video streams (ID 0) and one containing all audio streams (ID 1).

2. Manual Mapping for Multi-Bitrate Video

When encoding a single video source into multiple bitrates (e.g., 1080p, 720p, 360p) along with an audio track, you must map the streams explicitly. FFmpeg assigns output indices in the order they are mapped:

ffmpeg -i input.mp4 \
  -map 0:v -b:v:0 5000k -s:v:0 1920x1080 \
  -map 0:v -b:v:1 3000k -s:v:1 1280x720 \
  -map 0:v -b:v:2 1000k -s:v:2 640x360 \
  -map 0:a -b:a:0 128k \
  -f dash \
  -adaptation_sets "id=0,streams=0,1,2 id=1,streams=3" \
  output.mpd

In this example: * Stream 0 (1080p), Stream 1 (720p), and Stream 2 (360p) are grouped into adaptation set 0. * Stream 3 (audio) is assigned to adaptation set 1.

3. Configuring Multi-Language Audio and Subtitles

For complex streams with multiple audio languages and subtitles, you can group them to ensure the player displays them as selectable options:

ffmpeg -i input.mkv \
  -map 0:v:0 \
  -map 0:a:0 \
  -map 0:a:1 \
  -map 0:s:0 \
  -map 0:s:1 \
  -f dash \
  -adaptation_sets "id=0,streams=0 id=1,streams=1 id=2,streams=2 id=3,streams=3 id=4,streams=4" \
  output.mpd

This isolates each video, audio, and subtitle track into its own adaptation set, allowing the DASH player to toggle between different languages and subtitle options seamlessly.