Exemple #1
0
    def __init__(self, box: Box):
        self.box = box
        self.full_box = FullBox(box)
        tr_flags = self.full_box.flags
        self.sample_count = parse_big_endian_number(
            self.full_box.reader.read(4))
        if tr_flags & TRFlags.DATA_OFFSET_PRESENT:
            self.full_box.reader.skip(4)
        if tr_flags & TRFlags.FIRST_SAMPLE_FLAGS_PRESENT:
            self.full_box.reader.skip(4)
        if tr_flags & TRFlags.FIRST_SAMPLE_FLAGS_PRESENT:
            self.full_box.reader.skip(4)

        assert self.sample_count > 0
        # First sample
        if tr_flags & TRFlags.SAMPLE_DURATION_PRESENT:
            self.full_box.reader.skip(4)
        if tr_flags & TRFlags.SAMPLE_SIZE_PRESENT:
            self.full_box.reader.skip(4)
        if tr_flags & TRFlags.SAMPLE_FLAGS_PRESENT:
            self.full_box.reader.skip(4)
        if tr_flags & TRFlags.SAMPLE_COMPOSITION_TIME_OFFSETS_PRESENT:
            self.first_sample_composition_time_offset = parse_signed_big_endian_number(
                self.full_box.reader.read(4))
        else:
            self.first_sample_composition_time_offset = 0
Exemple #2
0
 def __init__(self, box: Box):
     self.box = box
     self.full_box = FullBox(box)
     int_size = 8 if self.full_box.version == 1 else 4
     self.full_box.reader.skip(2 *
                               int_size)  # creation_time, modification_time
     self.track_ID = parse_big_endian_number(self.full_box.reader.read(4))
Exemple #3
0
 def read_edit():
     segment_duration = parse_big_endian_number(
         self.full_box.reader.read(int_size))
     media_time, = struct.unpack(">i",
                                 self.full_box.reader.read(int_size))
     self.full_box.reader.skip(4)  # media_rate
     return Edit(segment_duration, media_time)
Exemple #4
0
    def __init__(self, reader: ByteReader):
        self.offset = reader.position
        size = parse_big_endian_number(reader.read(4))
        kind = reader.read(4)
        if size == 1:
            size = parse_big_endian_number(reader.read(8))
        elif size == 0:
            size = reader.end - reader.position
        if kind == b"uuid":
            kind += reader.read(16)
        content_offset = reader.position
        content_size = size - (content_offset - self.offset)

        self.kind = kind
        self.full_size = size
        self.reader = RegionByteReader(reader, content_offset, content_size)
        reader.skip(content_size)
Exemple #5
0
def read_vint(reader: ByteReader, raw: bool = False):
    header_byte = ord(reader.read(1))
    if header_byte == 0:
        raise WrongFile("VINT with zero header byte")
    tail_length = 0
    mask = 0x80
    while header_byte & mask == 0:
        tail_length += 1
        mask >>= 1

    header_number_part = header_byte & ~mask if not raw else header_byte
    return parse_big_endian_number(
        bytes([header_number_part]) + reader.read(tail_length))
Exemple #6
0
    def __init__(self, box: Box):
        self.box = box
        self.full_box = FullBox(box)
        int_size = 8 if self.full_box.version == 1 else 4
        entry_count = parse_big_endian_number(self.full_box.reader.read(4))

        def read_edit():
            segment_duration = parse_big_endian_number(
                self.full_box.reader.read(int_size))
            media_time, = struct.unpack(">i",
                                        self.full_box.reader.read(int_size))
            self.full_box.reader.skip(4)  # media_rate
            return Edit(segment_duration, media_time)

        self.edits = [read_edit() for _ in range(entry_count)]
Exemple #7
0
 def __init__(self, box: Box):
     self.box = box
     self.version = parse_big_endian_number(box.reader.read(1))
     self.flags = parse_big_endian_number(box.reader.read(3))
     self.reader = RegionByteReader(box.reader, box.reader.position,
                                    box.reader.size - 4)
Exemple #8
0
 def __init__(self, box: Box):
     self.box = box
     self.full_box = FullBox(box)
     int_size = 8 if self.full_box.version == 1 else 4
     self.base_media_decode_time = parse_big_endian_number(
         self.full_box.reader.read(int_size))