def _parse(self): self._traks = {} moov_pos, box_size, _, header_size = \ next(find_headers_at(self._file, {b"moov"}, self._offset)) self._file.seek(moov_pos) for trak_pos, _, _, _ in \ find_headers_at(self._file, {b"trak"}, moov_pos + header_size, box_size - header_size): trak_label = get_name_at(self._file, trak_pos) if trak_label[-1] == 0: trak_label = trak_label[:-1] trak_shape = get_shape_at(self._file, trak_pos) trak_stbl_pos, _, _, _ = find_sample_table_at(self._file, trak_pos) self._traks[trak_label] = Trak(trak_label, trak_shape, trak_stbl_pos)
def test_get_sample_size_at(): creation_time = utils.to_mp4_time(datetime(2019, 9, 15, 0, 0, 0)) modification_time = utils.to_mp4_time(datetime(2019, 9, 16, 0, 0, 0)) samples_sizes = [198297, 127477, 192476] samples_offset = 10 trak = utils.make_trak(creation_time, modification_time, samples_sizes, samples_offset) # MOOV.TRAK.TKHD tkhd = trak.boxes[0] tkhd.track_id = 1 tkhd.width = [512, 0] tkhd.height = [512, 0] trak.refresh_box_size() buffer = io.BytesIO(bytes(trak)) stbl_pos, _, _, _ = mp4.find_sample_table_at(buffer, 0) sz, _ = mp4.get_sample_size_at(buffer, stbl_pos) stbl = utils.get_sample_table(trak) stsz = next(utils.find_boxes(stbl.boxes, {b"stsz"})) assert (sz == [e.entry_size for e in stsz.samples]).all()
def test_find_sample_table_at(): creation_time = utils.to_mp4_time(datetime(2019, 9, 15, 0, 0, 0)) modification_time = utils.to_mp4_time(datetime(2019, 9, 16, 0, 0, 0)) samples_sizes = [198297, 127477, 192476] samples_offset = 10 trak = utils.make_trak(creation_time, modification_time, samples_sizes, samples_offset) # MOOV.TRAK.TKHD tkhd = trak.boxes[0] tkhd.track_id = 1 tkhd.width = [512, 0] tkhd.height = [512, 0] trak.refresh_box_size() buffer = io.BytesIO(bytes(trak)) _, box_size, box_type, header_size = mp4.find_sample_table_at(buffer, 0) stbl = utils.get_sample_table(trak) assert box_size == stbl.header.box_size assert box_type == stbl.header.type assert header_size == stbl.header.header_size