Dork's port

MPD 파일에서 segment의 개수 구하기 (How to get the number of segment) 본문

DRM

MPD 파일에서 segment의 개수 구하기 (How to get the number of segment)

Dork94 2022. 1. 29. 16:02

number of secment = second(mediaPresentationDuration) / (duration / timescale)

 

예를들어 아래의 파일에서 segment의 개수를 구한다고 가정해보자.

 

<?xml version="1.0" encoding="utf-8"?>
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:mpeg:DASH:schema:MPD:2011 DASH-MPD.xsd" type="static" profiles="urn:mpeg:dash:profile:isoff-on-demand:2011" minBufferTime="PT2S" mediaPresentationDuration="PT6M36.554S">
  <Period id="0" start="PT0.0S">
    <AdaptationSet id="0" contentType="video" segmentAlignment="true" bitstreamSwitching="true">
      <Representation id="v_t0_MAIN" mimeType="video/mp4" codecs="avc1.4d401f" bandwidth="993082" width="854" height="480">
        <SegmentTemplate timescale="15360" presentationTimeOffset="0" duration="61440" initialization="v_t0_MAIN/init.m4s" media="v_t0_MAIN/$Number%06d$.m4s" startNumber="0"></SegmentTemplate>
      </Representation>
      <Representation id="v_t0_BASE" mimeType="video/mp4" codecs="avc1.4d401e" bandwidth="495528" width="640" height="360">
        <SegmentTemplate timescale="15360" presentationTimeOffset="0" duration="61440" initialization="v_t0_BASE/init.m4s" media="v_t0_BASE/$Number%06d$.m4s" startNumber="0"></SegmentTemplate>
      </Representation>
      <Representation id="v_t0_HIGH" mimeType="video/mp4" codecs="avc1.64001f" bandwidth="1993939" width="1280" height="720">
        <SegmentTemplate timescale="15360" presentationTimeOffset="0" duration="61440" initialization="v_t0_HIGH/init.m4s" media="v_t0_HIGH/$Number%06d$.m4s" startNumber="0"></SegmentTemplate>
      </Representation>
      <Representation id="v_t0_HIGH4" mimeType="video/mp4" codecs="avc1.640028" bandwidth="6004008" width="1920" height="1080">
        <SegmentTemplate timescale="15360" presentationTimeOffset="0" duration="61440" initialization="v_t0_HIGH4/init.m4s" media="v_t0_HIGH4/$Number%06d$.m4s" startNumber="0"></SegmentTemplate>
      </Representation>
      <Representation id="v_t0_LOW" mimeType="video/mp4" codecs="avc1.4d4015" bandwidth="151863" width="426" height="240">
        <SegmentTemplate timescale="15360" presentationTimeOffset="0" duration="61440" initialization="v_t0_LOW/init.m4s" media="v_t0_LOW/$Number%06d$.m4s" startNumber="0"></SegmentTemplate>
      </Representation>
    </AdaptationSet>
    <AdaptationSet id="1" contentType="audio" lang="ko" segmentAlignment="true" bitstreamSwitching="true">
      <Representation id="a_t0_128-44100" mimeType="audio/mp4" codecs="mp4a.40.2" bandwidth="130661" audioSamplingRate="44100">
        <AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"></AudioChannelConfiguration>
        <SegmentTemplate timescale="44100" presentationTimeOffset="0" duration="176400" initialization="a_t0_128-44100/init.m4s" media="a_t0_128-44100/$Number%06d$.m4s" startNumber="0"></SegmentTemplate>
      </Representation>
      <Representation id="a_t0_320-44100" mimeType="audio/mp4" codecs="mp4a.40.2" bandwidth="322704" audioSamplingRate="44100">
        <AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"></AudioChannelConfiguration>
        <SegmentTemplate timescale="44100" presentationTimeOffset="0" duration="176400" initialization="a_t0_320-44100/init.m4s" media="a_t0_320-44100/$Number%06d$.m4s" startNumber="0"></SegmentTemplate>
      </Representation>
      <Representation id="a_t0_96-44100" mimeType="audio/mp4" codecs="mp4a.40.2" bandwidth="98654" audioSamplingRate="44100">
        <AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"></AudioChannelConfiguration>
        <SegmentTemplate timescale="44100" presentationTimeOffset="0" duration="176400" initialization="a_t0_96-44100/init.m4s" media="a_t0_96-44100/$Number%06d$.m4s" startNumber="0"></SegmentTemplate>
      </Representation>
    </AdaptationSet>
  </Period>
</MPD>

 mediaPresentationDuration="PT6M36.554S" 이므로 플레이타임을 초로 변환하면 6*60 + 36.554 = 396.554초 이다

video파일의 duration은 61440, timescale은 15360, audio의 duration은 176400, timescale은 44100이다. 

따라서 playtime per segment = 61440/15360, 176400/44100 이므로, 비디오와 오디오 파일 각각의 재생 길이는 4초임을 알 수 있다.

따라서 396.554 / 4 = 99.1385이므로 100개의 segment를 가지는 것을 알 수 있다.

위에서 start number의 값은 0으로 지정되어있으므로 동영상 재생에 필요한 segment를 불러올 때는 0~99까지 총 100개의 segment를 불러오는 것을 알 수 있다.

 

 

Comments