1. Frédéric Yhuel
  2. Python scripts

Commits

Frédéric Yhuel  committed e5e20c9

build_moov_box: track_ID bug

  • Participants
  • Parent commits 2e58962
  • Branches master

Comments (0)

Files changed (1)

File build_moov_box.py

View file
 modif_time = creation_time
 
 track_ID = {
-        "audio": 1,
-        "video": 2,
-        "metad": 3,
-        "hint" : 4,
+        "audio": 0,
+        "video": 0,
+        "text": 0,
         }
+next_track_ID = 1
 #################################################################
 
 def main():
     vstream = None
     astream = None
     streams = ss_media.getElementsByTagName("StreamIndex")
+    global next_track_ID
     for stream in streams:
         if stream.attributes["Type"].value == "video":
             vstream = stream
+            if track_ID["video"] == 0:
+                track_ID["video"] = next_track_ID
+                next_track_ID += 1
         if stream.attributes["Type"].value == "audio":
             astream = stream
+            if track_ID["audio"] == 0:
+                track_ID["audio"] = next_track_ID
+                next_track_ID += 1
+        #if stream.attributes["Type"].value == "text":
+            #tstream = stream
+
 
     try:
         DisplayWidth = vstream.attributes["DisplayWidth"].value
             res[("AACL", Index)] = b16decode(CodecPrivateData)
 
 
-    pprint(res)
+    #pprint(res)
     return res
 
 
             video_extra = build_dvc1(params)
 
         sample_entry_size = 86 + len(video_extra)
-        #width = 224 #FIXME
         width = params["MaxWidth"]
-        #height = 128 #FIXME
         height = params["MaxHeight"]
         horiz_resolution = 0x00480000
         vert_resolution = 0x00480000
     elif track_type == "audio":
         if params["acodec"] == "AACL":
             audio_fmt = "mp4a"
-            #audio_extra = pack(">H31LHB", 0x0000, 0x00816573, 0x64730000, 0x00000380,\
-            #        0x80807000, 0x00000480, 0x80806240, 0x15003000, 0x0001f400,\
-            #        0x0001f400, 0x05808080, 0x50121008, 0xc4000020, 0x00000000,\
-            #        0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,\
-            #        0x00000000, 0x01000000, 0,0,0,0,0,0,0,0,0,0, 0x00068080,\
-            #        0x8001, 0x02)
             audio_extra = build_esds(params)
 
         elif params["acodec"] == "WMAP":
 
         sample_entry_size = 36 + len(audio_extra)
         sample_rate = params[("SamplingRate", 0)]<<16
-        print "sample_rate is %x" % sample_rate
         SampleEntry = pack(">L4sLHH", sample_entry_size, audio_fmt, 0, 0, 1)
         SampleEntry += pack(">QHHLL", 0, 2, 16, 0, sample_rate)
         SampleEntry += audio_extra
 def build_esds(params):
 
     CodecPrivateData = params[("AACL", 0)]
-    if len(CodecPrivateData) == 2:
-        CodecPrivateData += b16decode("08C4000020000000000000000000\
-000000000000000000000000000000000000000100000000000000000000000000\
-00000000000000000000000000000000000000000000000000000000000000")
-
     tag = 3
     length = 0x80808000 + len(CodecPrivateData) + 18 + 8
-    #length = 0x80808000 + 0x70
     ES_ID = 0
     priority = 0
 
     return dvc1
 
 def build_avcC(params):
-    print("Enter build_avcC")
     AVCProfileIndication = 0x64 #FIXME
     profile_compatibility = 0x40 #FIXME
     AVCLevelIndication = 0x1f #FIXME
 
     for i in range(numOfSequenceParameterSets):
         sequenceParameterSetNALUnit = params[("sequenceParameterSetNALUnit", i)]
-        print("first SPS is %s" % b16encode(sequenceParameterSetNALUnit))
         sequenceParameterSetLength = len(sequenceParameterSetNALUnit)
         AVCDecoderConfigurationRecord += pack(">H", sequenceParameterSetLength)
         fmt = ">%is" % sequenceParameterSetLength
     matrix = (0x00010000,0,0,0,0x00010000,0,0,0,0x40000000)
 
     pre_defined = (0,0,0,0,0,0)
-    next_track_ID = 3 #FIXME
 
     mvhd = pack(">L4sL", mvhd_size, "mvhd", 0x01000000)
     mvhd += pack(">QQLQ", creation_time, modif_time, timescale, duration)
 
 if __name__ == "__main__":
     main()
+    pprint(track_ID)
+    print "next_track_ID is %i" % next_track_ID