How should I use the dash (not webm_dash_manifest!) format in ffmpeg?

Alton Patrick picture Alton Patrick · Oct 14, 2016 · Viewed 8.9k times · Source

FFmpeg has a format named "dash":

> ffmpeg -formats
...
  E dash            DASH Muxer
...

This presumably corresponds to the code in libavformat/dashenc.c.

I can find a number of items on the web about how to use the WebM DASH Manifest format, but nothing at all about this other DASH format.

Can someone point me to documentation or examples that use the "DASH Muxer" either from the command line or API?

Answer

Jeroen Ost picture Jeroen Ost · Dec 9, 2016

The dash muxer in ffmpeg is fairly new and not yet in the documentation. I managed to get it to work for my use case by looking at the source. It creates the .mpd dash file as well as the segments (unless you don't segment, and plan to use the Range: headers feature of DASH for seeks and partial access). The muxer options are:

  • window_size: number of segments kept in the manifest
  • extra_window_size: number of segments kept outside of the manifest before removing from disk
  • min_seg_duration: minimum segment duration (in microseconds)
  • remove_at_exit: remove all segments when finished
  • use_template: Use SegmentTemplate in the dash manifest instead of SegmentList
  • use_timeline: Use SegmentTimeline in SegmentTemplate
  • single_file: Store all segments in one file, accessed using byte ranges
  • single_file_name: DASH-templated name to be used for baseURL. Implies storing all segments in one file, accessed using byte ranges
  • init_seg_name: DASH-templated name to used for the initialization segment, defaults to init-stream$RepresentationID$.m4s
  • media_seg_name: DASH-templated name to used for the media segments, defaults to chunk-stream$RepresentationID$-$Number%05d$.m4s

My use case is live streaming, segments of exactly 4 seconds, no segment timeline, using segment template, and I use:

ffmpeg -i /dev/dvb/adapter0/dvr0 -vf yadif=0 -r 25 -vcodec libx264 -keyint_min 0 -g 100 -b:v 1000k -ac 2 -strict 2 -acodec aac -ab 64k -map 0:v -map 0:a -f dash -min_seg_duration 4000 -use_template 1 -use_timeline 0 -init_seg_name init-\$RepresentationID\$.mp4 -media_seg_name test-\$RepresentationID\$-\$Number\$.mp4 test.mpd

The generated dash manifest looks like this:

<?xml version="1.0" encoding="utf-8"?>
<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="urn:mpeg:dash:schema:mpd:2011"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xsi:schemaLocation="urn:mpeg:DASH:schema:MPD:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd"
    profiles="urn:mpeg:dash:profile:isoff-live:2011"
    type="dynamic"
    minimumUpdatePeriod="PT500S"
    suggestedPresentationDelay="PT4S"
    availabilityStartTime="2016-12-09T10:11:16"
    publishTime="2016-12-09T10:13:53"
    minBufferTime="PT4.0S">
  <ProgramInformation>
  </ProgramInformation>
  <Period start="PT0.0S">
        <AdaptationSet contentType="video" segmentAlignment="true" bitstreamSwitching="true" frameRate="25/1">
        <Representation id="0" mimeType="video/mp4" codecs="avc1.64001e" bandwidth="1000000" width="720" height="576" frameRate="25/1">
            <SegmentTemplate timescale="1000000" duration="4000000" initialization="init-$RepresentationID$.mp4" media="test-$RepresentationID$-$Number%05d$.mp4" startNumber="1">
            </SegmentTemplate>
        </Representation>
    </AdaptationSet>
    <AdaptationSet contentType="audio" segmentAlignment="true" bitstreamSwitching="true">
        <Representation id="1" mimeType="audio/mp4" codecs="mp4a.40.2" bandwidth="64000" audioSamplingRate="48000">
            <AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2" />
            <SegmentTemplate timescale="1000000" duration="4000000" initialization="init-$RepresentationID$.mp4" media="test-$RepresentationID$-$Number$.mp4" startNumber="1">
            </SegmentTemplate>
        </Representation>
    </AdaptationSet>
  </Period>
</MPD>

The manifest and associated stream plays in ExoPlayer on Android. It currently seems to only generate DASH live manifests and video or audio-only files. Changing from live to VOD is trivial though (have a look at the DASH spec). I've tested the stream in ExoPlayer on Android and it plays fine.