1
votes

I created a dash output sample_video.mpd file using ffmpeg, but when I tried to play it using dash js the video was just loading and nothing else. Below is the generated mpd file

<?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="static"
mediaPresentationDuration="PT1M2.3S"
minBufferTime="PT20.0S">
<ProgramInformation>
</ProgramInformation>
<Period id="0" start="PT0.0S">
    <AdaptationSet id="0" contentType="video" segmentAlignment="true" bitstreamSwitching="true" lang="und">
        <Representation id="0" mimeType="video/mp4" codecs="avc1.640015" bandwidth="255520" width="426" height="240" frameRate="24/1">
            <SegmentTemplate timescale="12288" initialization="init-stream$RepresentationID$.m4s" media="chunk-stream$RepresentationID$-$Number%05d$.m4s" startNumber="3">
                <SegmentTimeline>
                    <S t="198656" d="69120" />
                    <S d="75264" />
                    <S d="174592" />
                    <S d="122880" />
                    <S d="125440" />
                </SegmentTimeline>
            </SegmentTemplate>
        </Representation>
        <Representation id="2" mimeType="video/mp4" codecs="avc1.64001e" bandwidth="726596" width="854" height="480" frameRate="24/1">
            <SegmentTemplate timescale="12288" initialization="init-stream$RepresentationID$.m4s" media="chunk-stream$RepresentationID$-$Number%05d$.m4s" startNumber="3">
                <SegmentTimeline>
                    <S t="198656" d="69120" />
                    <S d="75264" />
                    <S d="174592" />
                    <S d="122880" />
                    <S d="125440" />
                </SegmentTimeline>
            </SegmentTemplate>
        </Representation>
        <Representation id="4" mimeType="video/mp4" codecs="avc1.64001f" bandwidth="1433314" width="1280" height="720" frameRate="24/1">
            <SegmentTemplate timescale="12288" initialization="init-stream$RepresentationID$.m4s" media="chunk-stream$RepresentationID$-$Number%05d$.m4s" startNumber="3">
                <SegmentTimeline>
                    <S t="198656" d="69120" />
                    <S d="75264" />
                    <S d="174592" />
                    <S d="122880" />
                    <S d="125440" />
                </SegmentTimeline>
            </SegmentTemplate>
        </Representation>
    </AdaptationSet>
    <AdaptationSet id="1" contentType="audio" segmentAlignment="true" bitstreamSwitching="true" lang="und">
        <Representation id="1" mimeType="audio/mp4" codecs="mp4a.40.2" bandwidth="341000" audioSamplingRate="48000">
            <AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="6" />
            <SegmentTemplate timescale="48000" initialization="init-stream$RepresentationID$.m4s" media="chunk-stream$RepresentationID$-$Number%05d$.m4s" startNumber="3">
                <SegmentTimeline>
                    <S t="772096" d="270336" />
                    <S d="293888" />
                    <S d="681984" />
                    <S d="480256" />
                    <S d="492544" />
                </SegmentTimeline>
            </SegmentTemplate>
        </Representation>
        <Representation id="3" mimeType="audio/mp4" codecs="mp4a.40.2" bandwidth="341000" audioSamplingRate="48000">
            <AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="6" />
            <SegmentTemplate timescale="48000" initialization="init-stream$RepresentationID$.m4s" media="chunk-stream$RepresentationID$-$Number%05d$.m4s" startNumber="3">
                <SegmentTimeline>
                    <S t="772096" d="270336" />
                    <S d="293888" />
                    <S d="681984" />
                    <S d="480256" />
                    <S d="492544" />
                </SegmentTimeline>
            </SegmentTemplate>
        </Representation>
        <Representation id="5" mimeType="audio/mp4" codecs="mp4a.40.2" bandwidth="341000" audioSamplingRate="48000">
            <AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="6" />
            <SegmentTemplate timescale="48000" initialization="init-stream$RepresentationID$.m4s" media="chunk-stream$RepresentationID$-$Number%05d$.m4s" startNumber="3">
                <SegmentTimeline>
                    <S t="772096" d="270336" />
                    <S d="293888" />
                    <S d="681984" />
                    <S d="480256" />
                    <S d="492544" />
                </SegmentTimeline>
            </SegmentTemplate>
        </Representation>
    </AdaptationSet>
</Period>

The following is the ffmpeg command that i used to generate multi bitrate video

ffmpeg -y -i sample_video.mp4 ^
-c:v libx264 -x264opts "keyint=24:min-keyint=24:no-scenecut" -r 24 ^
-c:a aac -b:a 128k ^
-bf 1 -b_strategy 0 -sc_threshold 0 -pix_fmt yuv420p ^
-map 0:v:0 -map 0:a:0 -map 0:v:0 -map 0:a:0 -map 0:v:0 -map 0:a:0 ^
-b:v:0 250k  -filter:v:0 "scale=-2:240" -profile:v:0 baseline ^
-b:v:1 750k  -filter:v:1 "scale=-2:480" -profile:v:1 main ^
-b:v:2 1500k -filter:v:2 "scale=-2:720" -profile:v:2 high ^
sample_dash.mp4

and to generate the mpd file

ffmpeg -y -re -i sample_dash.mp4 ^
-map 0 ^
-use_timeline 1 -use_template 1 -window_size 5 -adaptation_sets 
"id=0,streams=v id=1,streams=a" ^
-f dash sample_video.mpd

Also I saw in the chrome network tab that only init-stream4.m4s and init-stream5.m4s was called.

1

1 Answers

1
votes

Are you ready to use ffmpeg+mp4box dash packager? I have found mp4box produce better segments+manifest.

ffmpeg -i tos.mp4 -threads 4 -preset fast -c:v libx264 -profile:v main -level 4.0 -s:v 640x360 -b:v 512k -pix_fmt yuv420p -refs 3 -bf 3 -g 75 -keyint_min 25 -b_strategy 1 -flags +cgop -sc_threshold 0 -movflags negative_cts_offsets+faststart -an -y temp-v1.mp4
ffmpeg -i tos.mp4 -threads 4 -preset fast -c:v libx264 -profile:v main -level 4.0 -s:v 1280x720 -b:v 1500k -pix_fmt yuv420p -refs 3 -bf 3 -g 75 -keyint_min 25 -b_strategy 1 -flags +cgop -sc_threshold 0 -movflags negative_cts_offsets+faststart -an -y temp-v2.mp4
ffmpeg -i tos.mp4 -threads 4 -preset fast -c:v libx264 -profile:v main -level 4.0 -s:v 1920x1080 -b:v 2100k -pix_fmt yuv420p -refs 3 -bf 3 -g 75 -keyint_min 25 -b_strategy 1 -flags +cgop -sc_threshold 0 -movflags negative_cts_offsets+faststart -an -y temp-v3.mp4
ffmpeg -i tos.mp4 -threads 4 -c:a aac -strict experimental -b:a 128k -maxrate:a 128k -bufsize:a 128k -af aresample=44100 -ar 44100 -ac 2 -vn -y temp-a1.mp4
MP4Box -dash 264600 -frag 264600 -dash-scale 44100 -bound -mem-frags -rap -profile dashavc264:live -min-buffer 12000 -bs-switching no -sample-groups-traf -single-traf -subsegs-per-sidx -1 -segment-name $RepresentationID$/$Number$$Init=i$  -out manifest.mpd temp-v1.mp4#trackID=1:id=v1:period=p0 temp-v2.mp4#trackID=1:id=v2:period=p0 temp-v3.mp4#trackID=1:id=v3:period=p0 temp-a1.mp4#trackID=1:id=a1:period=p0

I always use audiorate(44100,48000) in a dash-scale and scale*seconds=value of dash/frag formula to give a segment file duration.