2

I am trying to complie init.mp4 and its audio file using copy /b init.mp4 + audio.mp4 complie.mp4

It is compiling but, its not able to play on vlc and on ffmpeg play.

When I checked the mpd file, I see for audio it has

            <SegmentTemplate timescale="48000" media="57_audio_1_17_$Number$.mp4?m=1532401844" initialization="57_audio_1_17_init.mp4?m=1532401844" startNumber="6815976">
                <SegmentTimeline>
                    <S t="1521333224447" d="479232" r="1"/>
                    <S t="1521334182911" d="483328"/>
                    <S t="1521334666239" d="479232" r="3"/>
                    <S t="1521336583167" d="483328"/>
                    <S t="1521337066495" d="479232" r="3"/>
                    <S t="1521338983423" d="483328"/>
                    <S t="1521339466751" d="479232" r="4"/>
                    <S t="1521341862911" d="483328"/>
                    <S t="1521342346239" d="479232" r="3"/>
                    <S t="1521344263167" d="483328"/>
                    <S t="1521344746495" d="479232" r="3"/>
                    <S t="1521346663423" d="483328"/>
                    <S t="1521347146751" d="479232" r="4"/>
                    <S t="1521349542911" d="483328"/>
                    <S t="1521350026239" d="479232" r="3"/>
                    <S t="1521351943167" d="483328"/>
                    <S t="1521352426495" d="479232" r="3"/>
                    <S t="1521354343423" d="483328"/>
                    <S t="1521354826751" d="479232" r="4"/>
                    <S t="1521357222911" d="483328"/>
                    <S t="1521357706239" d="479232" r="3"/>
                    <S t="1521359623167" d="483328"/>
                    <S t="1521360106495" d="479232" r="3"/>
                    <S t="1521362023423" d="483328"/>
                    <S t="1521362506751" d="479232" r="4"/>
                    <S t="1521364902911" d="483328"/>
                    <S t="1521365386239" d="479232" r="3"/>
                    <S t="1521367303167" d="483328"/>
                    <S t="1521367786495" d="479232" r="3"/>
                    <S t="1521369703423" d="483328"/>
                    <S t="1521370186751" d="479232" r="4"/>
                    <S t="1521372582911" d="483328"/>
                    <S t="1521373066239" d="479232" r="3"/>
                    <S t="1521374983167" d="483328"/>
                    <S t="1521375466495" d="479232" r="3"/>
                    <S t="1521377383423" d="483328"/>
                </SegmentTimeline>
            </SegmentTemplate>
        </Representation>

Can somebody explain what it is ? And those t,r,d values are. How do I add these audio segments to complie.mp4 and make it play ?

jmsn
  • 990
  • 7
  • 14
rustin peter
  • 59
  • 2
  • 6
  • By complie you mean concatenate the files init.mp4 and audio.mp4 into a file called compile.mp4? The DASH specification usually cost money to get but a good source is usually the ffmpeg source code https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/dashdec.c#L40 – Mattias Wadman Apr 10 '19 at 11:16
  • This post explains how to convert the segments into an .mp4 file. https://stackoverflow.com/questions/23485759/combine-mpeg-dash-segments-ex-init-mp4-segments-m4s-back-to-a-full-source-m/27017348 – Jonathan Kittell Apr 10 '19 at 14:27
  • As you added the `widevine` tag, does that mean that the stream is DRM-protected? That would be the next problem after downloading and concatenating the files. You'd need to decrypt before playback. – jmsn Jun 15 '19 at 23:50

1 Answers1

2

First you need to download the init.mp4 and then based on the SegmentTimeline download the segments.

For a <SegmentTemplate>, it’s common to use the <SegmentTimeline> tag to indicate how long each segment is and which segments repeat. A timescale (units to represent one second) is often included as part of the attributes of <SegmentTemplate> so that we can calculate the time of the segment based on this unit. In the example below, the <S> tag signifies a segment tag, the d attribute specifies how long the segment is and the r attribute specifies how many segments of the same duration repeat so that $Time$ can be calculated properly for downloading the media segment as specified in the media attribute.

<SegmentTemplate>
  timescale="48000"
  initialization="$RepresentationID$-init.dash"
  media="$RepresentationID$-$Time$.dash"
    startNumber="1">
    <SegmentTimeline>
      <S t="0" d="96256" r="2" />
      <S d="95232" />
      <S d="96256" r="2" />
      <S d="95232" />
      <S d="96256" r="2" />
   </SegmentTimeline>
</SegmentTemplate>

The following is an example of a segment template from a representation. It uses the $Time$ variable.

<SegmentTemplate timescale="30000" media="155_video_1_2_$Time$.mp4?m=1545421124" initialization="155_video_1_2_init.mp4?m=1545421124" startNumber="710">
  <SegmentTimeline>
       <S t="255197799" d="360360" r="8"/>
       <S t="258441039" d="334334"/>
  </SegmentTimeline>
</SegmentTemplate>

The request URL for the first segment is 155_video_1_2_255197799.mp4. With a 360360 duration, the next segment request is 155_video_1_2_255558159.mp4, and so on through the ninth segment.

The final segment request is 155_video_1_2_258441039.mp4.

If the segment template uses $Number$ instead of $Time$ then you download the files at the start number then repeat how ever many times indicated by r.

<AdaptationSet
            bitstreamSwitching="false"
            contentType="video"
            id="1"
            mimeType="video/mp4"
            segmentAlignment="true">
            <SegmentTemplate
                initialization="$RepresentationID$/init.mp4"
                media="$RepresentationID$/$Number$.m4f"
                startNumber="218646"
                timescale="90000">
                <SegmentTimeline>
                    <S
                        d="540540"
                        r="28"/>
                </SegmentTimeline>
            </SegmentTemplate>
            <Representation
                bandwidth="1199626"
                codecs="avc1.4D001E"
                frameRate="90000/3003"
                height="480"
                id="5501_video_seg_auto_video_32"
                width="528"/>
        </AdaptationSet>

The first file will be the start number and then repeat the segments 28 times. So start + 28 is 29 files plus init.mp4.

218646.m4f
218647.m4f
218648.m4f
218649.m4f
218650.m4f
218651.m4f
218652.m4f
218653.m4f
218654.m4f
218655.m4f
218656.m4f
218657.m4f
218658.m4f
218659.m4f
218660.m4f
218661.m4f
218662.m4f
218663.m4f
218664.m4f
218665.m4f
218666.m4f
218667.m4f
218668.m4f
218669.m4f
218670.m4f
218671.m4f
218672.m4f
218673.m4f
218674.m4f
init.mp4

Then you can convert the segments into an .mp4 file.

cat init.mp4 > source.mp4
cat segment-1.m4f >> source.mp4
cat segment-2.m4f >> source.mp4
...

References:

https://developers.google.com/cast/docs/mpl/streaming_protocols

https://docs.aws.amazon.com/mediapackage/latest/ug/segtemp-format.html

Combine MPEG-DASH segments (ex, init.mp4 + segments.m4s) back to a full source.mp4?

Jonathan Kittell
  • 7,163
  • 15
  • 50
  • 93
  • The problem is, in the MPD file, there is no $Time$ variable. Instead, it has $Number$. I tried putting, 57_audio_1_17_$Number$.mp4?m=1532401844 57_audio_1_17_1521333224447.mp4?m=1532401844 but, it is not working for me. in the SegmentTemplate, there is something called startNumber="6815976" I am able to download a mp4 file using this start number 57_audio_1_17_6815976.mp4?m=1532401844 like this. But the audio is not completed, it is giving error. can you check my edited post again to see the mpd file ? – rustin peter Apr 10 '19 at 17:02