def process_tfdt(self, data): "Extract baseMediaDecodeTime." version = ord(data[8]) if version == 0: self.base_media_decode_time = str_to_uint32(data[12:16]) else: self.base_media_decode_time = str_to_uint64(data[12:20]) seg = self.input_segments[-1] seg['base_media_decode_time'] = self.base_media_decode_time self.tfdt_size = len(data) return data
def process_sidx(self, data, file_pos): "Extract sidx parts." version = ord(data[8]) timescale = str_to_uint32(data[16:20]) if version == 0: earliest_time = str_to_uint32(data[20:24]) first_offset = str_to_uint32(data[24:28]) pos = 28 else: earliest_time = str_to_uint32(data[20:28]) first_offset = str_to_uint64(data[28:36]) pos = 36 if first_offset != 0: raise ValueError("Only supports first_offset == 0") pos += 2 reference_count = str_to_uint16(data[pos:pos + 2]) pos += 2 sidx_data = {'timescale': timescale, 'segments': []} offset = file_pos + len(data) + first_offset start = earliest_time for i in range(reference_count): field = str_to_uint32(data[pos:pos + 4]) pos += 4 reference_type = field >> 31 if reference_type != 0: raise ValueError("Only sidx reference type == 0 supported") size = field & 0x7fffffff duration = str_to_uint32(data[pos:pos + 4]) if self.verbose: print("Input sidx %d: dur=%d" % (i + 1, duration)) pos += 4 field = str_to_uint32(data[pos:pos + 4]) pos += 4 starts_with_sap = field >> 31 if starts_with_sap != 1: raise ValueError("Only sidx with starts_with_sap supported") sap_type = (field >> 28) & 0x7 if sap_type != 1: raise ValueError("Only sap type 1 supported, not %d" % sap_type) sap_delta_time = field & 0x0fffffff if sap_delta_time != 0: raise ValueError("Only sap_delta_time == 0 supported") seg_data = { 'offset': offset, 'size': size, 'start': start, 'duration': duration } sidx_data['segments'].append(seg_data) offset += size start += duration self.sidx_data = sidx_data return data
def process_tfdt(self, data, output): """Adjust time of tfdt if offset set.""" version = ord(data[8]) if version == 0: # 32-bit baseMediaDecodeTime tfdt = str_to_uint32(data[12:16]) if self.offset != None: tfdt += self.offset output += data[:12] + uint32_to_str(tfdt) + data[16:] else: output += data else: output = data[:12] tfdt = str_to_uint64(data[12:20]) if self.offset != None: tfdt += self.offset output += uint64_to_str(tfdt) else: output += data self.tfdt = tfdt return output
def process_tfhd(self, data): """Check flags and set default values. We are only interested in some values.""" tf_flags = str_to_uint32(data[8:12]) & 0xffffff self.track_id = str_to_uint32(data[12:16]) pos = 16 if tf_flags & 0x000001: # base_data_offset_present base_data_offset = str_to_uint64(data[pos:pos + 8]) pos += 8 if tf_flags & 0x000002: # sample-description-index-present sample_description_index = str_to_uint32(data[pos:pos + 4]) pos += 4 if tf_flags & 0x000008: # default_sample_duration_present self.default_sample_duration = str_to_uint32(data[pos:pos + 4]) pos += 4 if tf_flags & 0x000010: # default_sample_size_present self.default_sample_size = str_to_uint32(data[pos:pos + 4]) pos += 4 if tf_flags & 0x000020: # default_sample_flags_present self.default_sample_flags = str_to_uint32(data[pos:pos + 4]) pos += 4 return data