Eyevinn / hls-to-dash

Open source packager and tools to rewrap live HLS to live MPEG DASH
Other
40 stars 12 forks source link

hls-to-dash generates invalid mpd files #9

Open Brainiarc7 opened 6 years ago

Brainiarc7 commented 6 years ago

Hello there,

I am using hls-to-dash to generate a Multi period MPEG DASH from a master HLS playlist, as shown below:

  1. FFmpeg snippet used to encode:
/home/lin/bin/ffmpeg -loglevel debug -threads 4 -filter_complex_threads 4 -vsync 1 -i '/home/lin/Desktop/src/sowdtow.webm' -filter_complex \
"['v:0']split=2[s0][s1]; \
 [s0]scale=w=1920:h=1080:force_original_aspect_ratio=decrease:flags=lanczos,yadif[v0]; \
 [s1]scale=w=1280:h=720:force_original_aspect_ratio=decrease:flags=lanczos,yadif[v1]" \
-bsf:a aac_adtstoasc \
-b:v:0 6750k -c:v h264_nvenc -preset llhq -rc:v vbr_hq -pix_fmt yuv420p -profile:v main -level 4.1 \
-b:v:1 5250k -c:v h264_nvenc -preset llhq -rc:v vbr_hq -pix_fmt yuv420p -profile:v main -level 4.1 \
-b:a:0 256k -b:a:1 192k -c:a aac -ar 48000 \
-map "[v0]" -map "[v1]" -map 0:a:0 -map 0:a:0 \
-f hls -hls_flags discont_start+split_by_time -hls_time 10 -hls_init_time 4 -hls_list_size 10 -hls_wrap 24 \
-var_stream_map "v:0,a:0 v:1,a:1" -master_pl_publish_rate 10 -master_pl_name master.m3u8 \
"/home/lin/Desktop/dest/vs%v/master.m3u8"
  1. Snippet used to create the multi-period DASH:

hls-to-dash /home/lin/Desktop/dest/master.m3u8 --multi > /home/lin/Desktop/dest/mpd/test.mpd

  1. Output from hls-to-dash:
<?xml version="1.0"?>
<!-- Created with hls2dash (version=0.2.2) -->
<!-- https://pypi.python.org/pypi/hls2dash -->
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" xmlns:scte35="urn:scte:scte35:2014:xml+bin" profiles="urn:mpeg:dash:profile:isoff-live:2011" type="dynamic" minimumUpdatePeriod="PT10S" minBufferTime="PT1.500S" maxSegmentDuration="PT10.000000S" availabilityStartTime="2018-03-28T23:18:49.8
39191Z" publishTime="2018-03-28T20:20:21.250450Z">
  <Period id="8227010" start="PT91.411222S">
    <AdaptationSet mimeType="video/mp4" codecs="avc1.4d4029" minWidth="1280" maxWidth="1920" minHeight="720" maxHeight="1080" startWithSAP="1" segmentAlignment="true" minBandwidth="5986200" maxBandwidth="7706600">
      <SegmentTemplate timescale="90000" media="$RepresentationID$_$Number$.dash" presentationTimeOffset="8227010" startNumber="16">
        <SegmentTimeline>
          <S t="8227010" d="900900" />
          <S d="900900" />
          <S d="897897" />
          <S d="900900" />
          <S d="900900" />
          <S d="897897" />
          <S d="900900" />
          <S d="900900" />
          <S d="897897" />
          <S d="192192" />
        </SegmentTimeline>
      </SegmentTemplate>
      <Representation id="video-0/master" width="1920" height="1080" bandwidth="7706600" scanType="progressive" />
      <Representation id="video-1/master" width="1280" height="720" bandwidth="5986200" scanType="progressive" />
    </AdaptationSet>
    <AdaptationSet mimeType="audio/mp4" codecs="mp4a.40.2">
      <SegmentTemplate timescale="48000" media="$RepresentationID$_$Number$.dash" presentationTimeOffset="4387738" startNumber="16">
        <SegmentTimeline>
          <S t="4387739" d="480480" />
          <S d="480480" />
          <S d="478878" />
          <S d="480480" />
          <S d="480480" />
          <S d="478878" />
          <S d="480480" />
          <S d="480480" />
          <S d="478878" />
          <S d="102502" />
        </SegmentTimeline>
      </SegmentTemplate>
      <Representation id="audio-0/master" bandwidth="96000" />
    </AdaptationSet>
  </Period>
</MPD>
  1. Stream generated with MP4Box from the same master playlist:

MP4Box -mpd /home/lin/Desktop/dest/master.m3u8 -out /home/lin/Desktop/dest/mpd/stream.mpd

Content:

<MPD type="static" xmlns="urn:mpeg:dash:schema:mpd:2011" xmlns:hls="urn:gpac:hls:aes:mpd:2015" profiles="urn:mpeg:dash:profile:full:2011" id="master.m3u8" mediaPresentationDuration="PT92S" minBufferTime="PT1.5S">
 <ProgramInformation moreInformationURL="http://gpac.sourceforge.net">
  <Title>/home/lin/Desktop/dest/vs1/master.m3u8</Title>
  <Source>Generated from URL /home/lin/Desktop/dest/master.m3u8</Source>
  <Copyright>Generated by GPAC 0.5.2-DEV-revVersion: 0.5.2-426-gc5ad4e4+dfsg5-1build1 from /home/lin/Desktop/dest/master.m3u8</Copyright>
 </ProgramInformation>
 <Period start="PT0S" duration="PT92S" >
  <AdaptationSet segmentAlignment="true">
   <Representation id="master.m3u8" bandwidth="7706600" mimeType="video/mp2t" codecs="avc1.4d4029,mp4a.40.2" width="1920" height="1080">
    <BaseURL>/home/lin/Desktop/dest/vs0/</BaseURL>
    <SegmentList duration="10.000000">
     <SegmentURL media="master16.ts"/>
     <SegmentURL media="master17.ts"/>
     <SegmentURL media="master18.ts"/>
     <SegmentURL media="master19.ts"/>
     <SegmentURL media="master20.ts"/>
     <SegmentURL media="master21.ts"/>
     <SegmentURL media="master22.ts"/>
     <SegmentURL media="master23.ts"/>
     <SegmentURL media="master0.ts"/>
     <SegmentURL media="master1.ts"/>
    </SegmentList>
   </Representation>
   <Representation id="master.m3u8" bandwidth="5986200" mimeType="video/mp2t" codecs="avc1.4d4029,mp4a.40.2" width="1280" height="720">
    <BaseURL>/home/lin/Desktop/dest/vs1/</BaseURL>
    <SegmentList duration="10.000000">
     <SegmentURL media="master16.ts"/>
     <SegmentURL media="master17.ts"/>
     <SegmentURL media="master18.ts"/>
     <SegmentURL media="master19.ts"/>
     <SegmentURL media="master20.ts"/>
     <SegmentURL media="master21.ts"/>
     <SegmentURL media="master22.ts"/>
     <SegmentURL media="master23.ts"/>
     <SegmentURL media="master0.ts"/>
     <SegmentURL media="master1.ts"/>
    </SegmentList>
   </Representation>
  </AdaptationSet>
 </Period>
</MPD>

You'll notice that the DASH manifest generated by hls-to-dash lacks the <SegmentURL> sections, and the output is unusable:

cd ~/Desktop/dest/mpd
MP4Client test.mpd 
Using config file in /home/lin/.gpac directory
System info: 64310 MB RAM - 8 cores
Modules Found : 35 
Loading GPAC Terminal
[Thread MediaManager] Couldn't set priority(2) for thread ID 0x86a96700
[Thread MediaManager] Couldn't set priority(2) for thread ID 0x86a96700
Terminal Loaded in 47 ms
Opening URL test.mpd
[DASH] Slight drift in UTC clock at time 2018-03-28T23:18:49Z: diff AST - now 9998969 ms
[DASH] current time 0 is before start time 8227010 of first segment in timeline (timescale 90000) by 91.4112 sec - using first segment as starting point
[DASH] Slight drift in UTC clock at time 2018-03-28T23:18:49Z: diff AST - now 9998969 ms
[DASH] current time 0 is before start time 4387739 of first segment in timeline (timescale 48000) by 91.4112 sec - using first segment as starting point
[IsoMedia] : error while opening video-1/master_16.dash, error=Requested URL is not valid or cannot be found
[IsoMedia] : error while opening audio-0/master_16.dash, error=Requested URL is not valid or cannot be found
Service Connected

Whereas the stream generated by MP4Box are indeed usable:

MP4Client stream.mpd 
Using config file in /home/lin/.gpac directory
System info: 64310 MB RAM - 8 cores
Modules Found : 35 
Loading GPAC Terminal
[Thread MediaManager] Couldn't set priority(2) for thread ID 0x43ffe700
[Thread MediaManager] Couldn't set priority(2) for thread ID 0x43ffe700
Terminal Loaded in 82 ms
Opening URL stream.mpd
Service Connected

And playable.

Filing this issue as a bug.

birme commented 6 years ago

Thank you for the report. I will have a look at this when time allows.

As hls2dash generates MPD of type SegmentTimeline (and not SegmentList) it looks a bit different compared with the one MP4Box generates. Not saying that there is not an issue here but that explains the difference.

Also, what may not be clear in this is that the hls2dash only converts the HLS to a multi-periode MPEG-DASH manifest. You need a separate process actually remuxing the .ts to CMAF/fMP4 (.dash)

Brainiarc7 commented 6 years ago

Alright, thanks for the clarification.

Is it possible to add such a feature to hls2dash, similar to what gpac's mp4box does?