Ejemplo n.º 1
0
 def make_mkvb(self):
    import mcio_matroska
    from mcio_matroska import MatroskaBuilder
    
    tracks = self.find_subboxes('trak')
    td_gcd = reduce(gcd, (t.get_sample_delta_gcd() for t in tracks))
    ts_base = max(t.get_mdhd().time_scale for t in tracks)
    dur = max(t.get_mdhd().get_dur() for t in tracks)
    
    mvhd = self.find_subbox('mvhd')
    dur = max(dur, mvhd.get_dur())
    (tcs, elmult, _tcs_err) = MatroskaBuilder.tcs_from_secdiv(ts_base, td_gcd)
    mb = MatroskaBuilder(tcs, dur)
    
    for track in tracks:
       mdhd = track.get_mdhd()
       se = track.get_sample_entry()
       
       htype = track.find_subbox(b'mdia').find_subbox(b'hdlr').handler_type
       if (htype == self._HTYPE_VIDE):
          ttype = mcio_matroska.TRACKTYPE_VIDEO
          at_args = (se.width, se.height)
       elif (htype == self._HTYPE_SOUN):
          ttype = mcio_matroska.TRACKTYPE_AUDIO
          at_args = (round(se.sample_rate), se.channel_count)
       else:
          continue
       
       codec_id = se.get_codec()
       ts_fact = (ts_base / mdhd.time_scale)
       mcd = track._get_most_common_dur()
       mb.add_track(track.get_sample_data(elmult*ts_fact, mcd), ttype, codec_id, se.get_codec_init_data(),
          not (track.stts is None), default_dur=round(10**9*mcd/mdhd.time_scale), *at_args)
    
    return mb