Exemplo n.º 1
0
def test_stsc_box():
    bs = pack("uintbe:32, bytes:4, uintbe:8, bits:24, "
              "uintbe:32, uintbe:32, uintbe:32, uintbe:32",
              28, b"stsc", 0, b"\x00\x00\x00",
              1, 1, 1, 1)

    box_header = Parser.parse_header(bs)
    stsc = bx_def.STSC.parse_box(bs, box_header)
    box = stsc

    assert box.header.start_pos == 0
    assert box.header.type == b"stsc"
    assert box.header.box_size == 28
    assert box.header.version == 0
    assert box.header.flags == b"\x00\x00\x00"

    assert box.entry_count == 1
    assert len(box.entries) == 0

    box.load(bs)
    assert len(box.entries) == 1
    assert box.entries[0].first_chunk == 1
    assert box.entries[0].samples_per_chunk == 1
    assert box.entries[0].sample_description_index == 1

    assert bytes(box) == bs.bytes
Exemplo n.º 2
0
def test_ctts_box():
    bs = pack("uintbe:32, bytes:4, uintbe:8, bits:24, "
              "uintbe:32, uintbe:32, uintbe:32",
              24, b"ctts", 0, b"\x00\x00\x00",
              1, 1, 1)

    box_header = Parser.parse_header(bs)
    ctts = bx_def.CTTS.parse_box(bs, box_header)
    box = ctts

    assert box.header.start_pos == 0
    assert box.header.type == b"ctts"
    assert box.header.box_size == 24
    assert box.header.version == 0
    assert box.header.flags == b"\x00\x00\x00"

    assert box.entry_count == 1
    assert len(box.entries) == 0

    box.load(bs)
    assert len(box.entries) == 1
    assert box.entries[0].sample_count == 1
    assert box.entries[0].sample_offset == 1

    assert bytes(box) == bs.bytes
Exemplo n.º 3
0
def test_stsz_box():
    bs = pack("uintbe:32, bytes:4, uintbe:8, bits:24, "
              "uintbe:32, uintbe:32, uintbe:32",
              24, b"stsz", 0, b"\x00\x00\x00",
              0, 1, 1)

    box_header = Parser.parse_header(bs)
    stsz = bx_def.STSZ.parse_box(bs, box_header)
    box = stsz

    assert box.header.start_pos == 0
    assert box.header.type == b"stsz"
    assert box.header.box_size == 24
    assert box.header.version == 0
    assert box.header.flags == b"\x00\x00\x00"

    assert box.sample_size == 0
    assert box.sample_count == 1
    assert len(box.samples) == 0

    box.load(bs)
    assert len(box.samples) == 1
    assert box.samples[0].entry_size == 1

    assert bytes(box) == bs.bytes
Exemplo n.º 4
0
def test_mdhd_header_box():
    bs = pack("uintbe:32, bytes:4, uintbe:8, bits:24, "
              "uintbe:32, uintbe:32, uintbe:32, uintbe:32, "
              "bits:1, uint:5, uint:5, uint:5, bits:16",
              32, b"mdhd", 0, b"\x00\x00\x00",
              3596199850, 3596199850, 30000, 4200196,
              0x1, 21, 14, 4, b"\x00" * 2)

    box_header = Parser.parse_header(bs)
    mdhd = parse.MDHD.parse_box(bs, box_header)
    box = mdhd

    assert box.header.start_pos == 0
    assert box.header.type == b"mdhd"
    assert box.header.box_size == 32
    assert box.header.version == 0
    assert box.header.flags == b"\x00\x00\x00"

    assert box.creation_time == 3596199850
    assert box.modification_time == 3596199850
    assert box.timescale == 30000
    assert box.duration == 4200196

    assert box.language == [21, 14, 4]
    assert box.pre_defined == 0

    assert bytes(box) == bs.bytes
Exemplo n.º 5
0
def test_clap_box():
    bs = pack("uintbe:32, bytes:4, "
              "uintbe:32, uintbe:32, uintbe:32, uintbe:32, "
              "intbe:32, uintbe:32, intbe:32, uintbe:32",
              40, b"clap",
              500, 1, 333, 1,
              -12, 2, -179, 2)

    box_header = Parser.parse_header(bs)
    clap = bx_def.CLAP.parse_box(bs, box_header)
    box = clap

    assert box.header.start_pos == 0
    assert box.header.type == b"clap"
    assert box.header.box_size == 40

    assert box.clean_aperture_width_n == 500
    assert box.clean_aperture_width_d == 1
    assert box.clean_aperture_height_n == 333
    assert box.clean_aperture_height_d == 1
    assert box.horiz_off_n == -12
    assert box.horiz_off_d == 2
    assert box.vert_off_n == -179
    assert box.vert_off_d == 2
    assert bytes(box) == bs.bytes
Exemplo n.º 6
0
def test_elst_box():
    bs = pack("uintbe:32, bytes:4, uintbe:8, bits:24, "
              "uintbe:32, uintbe:32, uintbe:32, uintbe:16, uintbe:16",
              28, b"elst", 0, b"\x00\x00\x00",
              1, 3000, 0, 1, 0)

    box_header = Parser.parse_header(bs)
    elst = bx_def.ELST.parse_box(bs, box_header)
    box = elst

    assert box.header.start_pos == 0
    assert box.header.type == b"elst"
    assert box.header.box_size == 28
    assert box.header.version == 0
    assert box.header.flags == b"\x00\x00\x00"

    assert box.entry_count == 1
    assert len(box.entries) == 0

    box.load(bs)
    assert len(box.entries) == 1
    assert box.entries[0].segment_duration == 3000
    assert box.entries[0].media_time == 0
    assert box.entries[0].media_rate_integer == 1
    assert box.entries[0].media_rate_fraction == 0

    assert bytes(box) == bs.bytes
Exemplo n.º 7
0
def test_co64_box():
    bs = pack("uintbe:32, bytes:4, uintbe:8, bits:24, "
              "uintbe:32, uintbe:64, uintbe:64, uintbe:64",
              40, b"co64", 0, b"\x00\x00\x00",
              3, 0, 1, 2)

    box_header = Parser.parse_header(bs)
    stco = bx_def.CO64.parse_box(bs, box_header)
    box = stco

    assert box.header.start_pos == 0
    assert box.header.type == b"co64"
    assert box.header.box_size == 40
    assert box.header.version == 0
    assert box.header.flags == b"\x00\x00\x00"

    assert box.entry_count == 3
    assert len(box.entries) == 0

    box.load(bs)
    assert len(box.entries) == 3
    assert box.entries[0].chunk_offset == 0
    assert box.entries[1].chunk_offset == 1
    assert box.entries[2].chunk_offset == 2

    assert bytes(box) == bs.bytes
Exemplo n.º 8
0
def test_sbtt_box():
    bs = pack("uintbe:32, bytes:4, "
              "uintbe:8, uintbe:8, uintbe:8, uintbe:8, uintbe:8, uintbe:8, "
              "uintbe:16, "
              "bytes:1, bytes:11",
              28, b"sbtt",
              0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
              1,
              b'\0', b'text/plain\0')

    box_header = Parser.parse_header(bs)
    mett = bx_def.METT.parse_box(bs, box_header)
    box = mett

    assert box.header.start_pos == 0
    assert box.header.type == b"sbtt"
    assert box.header.box_size == 28

    assert box.data_reference_index == 1
    assert box.content_encoding == b'\0'
    assert box.mime_format == b'text/plain\0'

    assert len(box.boxes) == 0

    assert bytes(box) == bs.bytes
Exemplo n.º 9
0
def test_box_header():
    bs = pack("uintbe:32, bytes:4", 100, b"abcd")
    box_header = Parser.parse_header(bs)

    assert box_header.start_pos == 0
    assert box_header.type == b"abcd"
    assert box_header.box_size == 100
    assert box_header.header_size == 8
    assert box_header.content_size == 92
    assert bytes(box_header) == bs.bytes
Exemplo n.º 10
0
def test_box_header_extended():
    bs = pack("uintbe:32, bytes:4, uintbe:64", 1, b"abcd", parse.MAX_UINT_32 + 1)
    box_header = Parser.parse_header(bs)

    assert box_header.start_pos == 0
    assert box_header.type == b"abcd"
    assert box_header.box_size == parse.MAX_UINT_32 + 1
    assert box_header.header_size == 16
    assert box_header.content_size == parse.MAX_UINT_32 + 1 - 16
    assert bytes(box_header) == bs.bytes
Exemplo n.º 11
0
def test_box_header_user_type():
    bs = pack("uintbe:32, bytes:4, bytes:16", 100, b"uuid",
              b":benzina\x00\x00\x00\x00\x00\x00\x00\x00")
    box_header = Parser.parse_header(bs)

    assert box_header.start_pos == 0
    assert box_header.type == b"uuid:benzina\x00\x00\x00\x00\x00\x00\x00\x00"
    assert box_header.box_size == 100
    assert box_header.header_size == 24
    assert box_header.content_size == 76
    assert bytes(box_header) == bs.bytes
Exemplo n.º 12
0
def test_box_header_extended_user_type():
    bs = pack("uintbe:32, bytes:4, uintbe:64, bytes:16", 1, b"uuid",
              parse.MAX_UINT_32 + 1, b":benzina\x00\x00\x00\x00\x00\x00\x00\x00")
    box_header = Parser.parse_header(bs)

    assert box_header.start_pos == 0
    assert box_header.type == b"uuid:benzina\x00\x00\x00\x00\x00\x00\x00\x00"
    assert box_header.box_size == parse.MAX_UINT_32 + 1
    assert box_header.header_size == 32
    assert box_header.content_size == parse.MAX_UINT_32 + 1 - 32
    assert bytes(box_header) == bs.bytes
Exemplo n.º 13
0
def test_mdat_box_empty():
    bs = pack("uintbe:32, bytes:4",
              8, b"mdat")

    box_header = Parser.parse_header(bs)
    mdat = bx_def.MDAT.parse_box(bs, box_header)
    mdat.load(bs)
    box = mdat

    assert box.header.start_pos == 0
    assert box.header.type == b"mdat"
    assert box.header.box_size == 8
    assert box.data == b''
    assert bytes(box) == bs.bytes
Exemplo n.º 14
0
def test_nmhd_box():
    bs = pack("uintbe:32, bytes:4, uintbe:8, bits:24",
              12, b"nmhd", 0, b"\x00\x00\x00")

    box_header = Parser.parse_header(bs)
    nmhd = bx_def.NMHD.parse_box(bs, box_header)
    box = nmhd

    assert box.header.start_pos == 0
    assert box.header.type == b"nmhd"
    assert box.header.box_size == 12
    assert box.header.version == 0
    assert box.header.flags == b"\x00\x00\x00"

    assert bytes(box) == bs.bytes
Exemplo n.º 15
0
def test_pasp_box():
    bs = pack("uintbe:32, bytes:4, uintbe:32, uintbe:32",
              16, b"pasp", 150, 157)

    box_header = Parser.parse_header(bs)
    pasp = bx_def.PASP.parse_box(bs, box_header)
    box = pasp

    assert box.header.start_pos == 0
    assert box.header.type == b"pasp"
    assert box.header.box_size == 16

    assert box.h_spacing == 150
    assert box.v_spacing == 157
    assert bytes(box) == bs.bytes
Exemplo n.º 16
0
def test_full_box_header():
    bs = pack("uintbe:32, bytes:4, uintbe:8, bits:24",
              100, b"abcd", 1, b"\x00\x00\x07")
    box_header = Parser.parse_header(bs)
    full_box_header = parse.FullBoxHeader()
    full_box_header.extend_header(bs, box_header)
    del box_header

    assert full_box_header.start_pos == 0
    assert full_box_header.type == b"abcd"
    assert full_box_header.box_size == 100
    assert full_box_header.header_size == 12
    assert full_box_header.content_size == 88
    assert full_box_header.version == 1
    assert full_box_header.flags == b"\x00\x00\x07"

    assert bytes(full_box_header) == bs.bytes
Exemplo n.º 17
0
def test_stsd_box():
    bs = pack("uintbe:32, bytes:4, uintbe:8, bits:24, uintbe:32",
              16, b"stsd", 0, b"\x00\x00\x00", 0)

    box_header = Parser.parse_header(bs)
    stsd = bx_def.STSD.parse_box(bs, box_header)
    box = stsd

    assert box.header.start_pos == 0
    assert box.header.type == b"stsd"
    assert box.header.box_size == 16
    assert box.header.version == 0
    assert box.header.flags == b"\x00\x00\x00"

    assert box.entry_count == 0

    assert bytes(box) == bs.bytes
Exemplo n.º 18
0
def test_url__box():
    bs = pack("uintbe:32, bytes:4, uintbe:8, bits:24",
              12, b"url ", 0, b"\x00\x00\x01")

    box_header = Parser.parse_header(bs)
    url_ = bx_def.URL_.parse_box(bs, box_header)
    box = url_

    assert box.header.start_pos == 0
    assert box.header.type == b"url "
    assert box.header.box_size == 12
    assert box.header.version == 0
    assert box.header.flags == b"\x00\x00\x01"

    assert box.location is None

    assert bytes(box) == bs.bytes
Exemplo n.º 19
0
def test_dref_box():
    bs = pack("uintbe:32, bytes:4, uintbe:8, bits:24, uintbe:32",
              16, b"dref", 0, b"\x00\x00\x00", 1)

    box_header = Parser.parse_header(bs)
    dref = bx_def.DREF.parse_box(bs, box_header)
    box = dref

    assert box.header.start_pos == 0
    assert box.header.type == b"dref"
    assert box.header.box_size == 16
    assert box.header.version == 0
    assert box.header.flags == b"\x00\x00\x00"

    assert box.entry_count == 1

    assert bytes(box) == bs.bytes
Exemplo n.º 20
0
def test_tkhd_box():
    bs = pack("uintbe:32, bytes:4, uintbe:8, bits:24, "
              "uintbe:32, uintbe:32, uintbe:32, bits:32, uintbe:32, "
              "bits:32, bits:32, "
              "uintbe:16, uintbe:16, uintbe:8, uintbe:8, "
              "bits:16, "
              "uintbe:32, uintbe:32, uintbe:32, uintbe:32, uintbe:32, uintbe:32, uintbe:32, uintbe:32, uintbe:32, "
              "uintbe:16, uintbe:16, uintbe:16, uintbe:16",
              92, b"tkhd", 0, b"\x00\x00\x07",
              3596199850, 3596199850, 1, b"\x00" * 4, 6720313,
              b"\x00" * 4, b"\x00" * 4,
              0, 0, 0, 0,
              b"\x00" * 2,
              65536, 0, 0, 0, 65536, 0, 0, 0, 1073741824,
              318, 0, 180, 0)

    box_header = Parser.parse_header(bs)
    tkhd = bx_def.TKHD.parse_box(bs, box_header)
    box = tkhd

    assert box.header.start_pos == 0
    assert box.header.type == b"tkhd"
    assert box.header.box_size == 92
    assert box.header.version == 0
    assert box.header.flags == b"\x00\x00\x07"

    assert box.creation_time == 3596199850
    assert box.modification_time == 3596199850
    assert box.track_id == 1
    assert box.duration == 6720313

    assert box.layer == 0
    assert box.alternate_group == 0
    assert box.volume == [0, 0]

    assert box.matrix == [65536, 0, 0, 0, 65536, 0, 0, 0, 1073741824]

    assert box.width == 318
    assert box.height == 180

    assert box.is_audio is False

    assert bytes(box) == bs.bytes
Exemplo n.º 21
0
def test_ftyp_box():
    bs = pack("uintbe:32, bytes:4, "
              "bytes:4, uintbe:32, bytes:12",
              28, b"ftyp",
              b"mp42", 0, b"mp42mp41iso4")

    box_header = Parser.parse_header(bs)
    ftyp = parse.FTYP.parse_box(bs, box_header)
    box = ftyp

    assert box.header.start_pos == 0
    assert box.header.type == b"ftyp"
    assert box.header.box_size == 28
    assert box.major_brand == 1836069938            # b"mp42"
    assert box.minor_version == 0
    assert box.compatible_brands == [1836069938,    # b"mp42"
                                     1836069937,    # b"mp41"
                                     1769172788]    # b"iso4"
    assert bytes(box) == bs.bytes
Exemplo n.º 22
0
def test_vmhd_header_box():
    bs = pack("uintbe:32, bytes:4, uintbe:8, bits:24, "
              "uintbe:16, uintbe:16, uintbe:16, uintbe:16",
              20, b"vmhd", 0, b"\x00\x00\x01",
              0, 0, 0, 0)

    box_header = Parser.parse_header(bs)
    vmhd = parse.VMHD.parse_box(bs, box_header)
    box = vmhd

    assert box.header.start_pos == 0
    assert box.header.type == b"vmhd"
    assert box.header.box_size == 20
    assert box.header.version == 0
    assert box.header.flags == b"\x00\x00\x01"

    assert box.graphicsmode == 0
    assert box.opcolor == [0, 0, 0]

    assert bytes(box) == bs.bytes
Exemplo n.º 23
0
def test_hdlr_box():
    bs = pack("uintbe:32, bytes:4, uintbe:8, bits:24, "
              "uintbe:32, bytes:4, bits:32, bits:32, bits:32, bytes:19",
              51, b"hdlr", 0, b"\x00\x00\x00",
              0, b"vide", b"\x00" * 4, b"\x00" * 4, b"\x00" * 4, b"Vireo Eyes v2.4.22\0")

    box_header = Parser.parse_header(bs)
    hdlr = parse.HDLR.parse_box(bs, box_header)
    box = hdlr

    assert box.header.start_pos == 0
    assert box.header.type == b"hdlr"
    assert box.header.box_size == 51
    assert box.header.version == 0
    assert box.header.flags == b"\x00\x00\x00"

    assert box.pre_defined == 0
    assert box.handler_type == b"vide"
    assert box.name == b"Vireo Eyes v2.4.22\0"

    assert bytes(box) == bs.bytes
Exemplo n.º 24
0
def test_sample_entry_box():
    bs = pack("uintbe:32, bytes:4, "
              "uintbe:8, uintbe:8, uintbe:8, uintbe:8, uintbe:8, uintbe:8, "
              "uintbe:16",
              16, b"____",
              0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
              1)

    box_header = Parser.parse_header(bs)
    sample_entry_box = bx_def.SampleEntryBox.parse_box(bs, box_header)
    box = sample_entry_box

    assert box.header.start_pos == 0
    assert box.header.type == b"____"
    assert box.header.box_size == 16

    assert box.data_reference_index == 1
    
    assert len(box.boxes) == 0

    assert bytes(box) == bs.bytes
Exemplo n.º 25
0
def test_mvhd_box():
    bs = pack("uintbe:32, bytes:4, uintbe:8, bits:24, "
              "uintbe:32, uintbe:32, uintbe:32, uintbe:32, "
              "uintbe:16, uintbe:16, uintbe:8, uintbe:8, "
              "bits:16, bits:32, bits:32, "
              "uintbe:32, uintbe:32, uintbe:32, uintbe:32, uintbe:32, uintbe:32, uintbe:32, uintbe:32, uintbe:32, "
              "bits:32, bits:32, bits:32, bits:32, bits:32, bits:32, "
              "uintbe:32",
              108, b"mvhd", 0, b"\x00\x00\x00",
              3596199850, 3596199850, 48000, 6720608,
              1, 0, 1, 0,
              b"\x00" * 2, b"\x00" * 4, b"\x00" * 4,
              65536, 0, 0, 0, 65536, 0, 0, 0, 1073741824,
              b"\x00" * 4, b"\x00" * 4, b"\x00" * 4, b"\x00" * 4, b"\x00" * 4, b"\x00" * 4,
              3)

    box_header = Parser.parse_header(bs)
    mvhd = bx_def.MVHD.parse_box(bs, box_header)
    box = mvhd

    assert box.header.start_pos == 0
    assert box.header.type == b"mvhd"
    assert box.header.box_size == 108
    assert box.header.version == 0
    assert box.header.flags == b"\x00\x00\x00"

    assert box.creation_time == 3596199850
    assert box.modification_time == 3596199850
    assert box.timescale == 48000
    assert box.duration == 6720608

    assert box.rate == [1, 0]
    assert box.volume == [1, 0]

    assert box.matrix == [65536, 0, 0, 0, 65536, 0, 0, 0, 1073741824]
    assert box.pre_defined == [b"\x00" * 4] * 6

    assert box.next_track_id == 3

    assert bytes(box) == bs.bytes
Exemplo n.º 26
0
def test_avc1_box():
    bs = pack("uintbe:32, bytes:4, "
              "uintbe:8, uintbe:8, uintbe:8, uintbe:8, uintbe:8, uintbe:8, "
              "uintbe:16, "
              "uintbe:16, uintbe:16, uintbe:32, uintbe:32, uintbe:32, "
              "uintbe:16, uintbe:16, uintbe:16, uintbe:16, uintbe:16, uintbe:16, "
              "uintbe:32, "
              "uintbe:16, bytes:32, uintbe:16, "
              "intbe:16",
              58, b"avc1",
              0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
              1,
              0x0, 0x0, 0x0, 0x0, 0x0,
              512, 512, 72, 0, 72, 0,
              0x0,
              1, b'\0' * 32, 24,
              -1)

    box_header = Parser.parse_header(bs)
    avc1 = bx_def.AVC1.parse_box(bs, box_header)
    box = avc1

    assert box.header.start_pos == 0
    assert box.header.type == b"avc1"
    assert box.header.box_size == 58

    assert box.data_reference_index == 1
    assert box.width == 512
    assert box.height == 512
    assert box.horizresolution == [72, 0]
    assert box.vertresolution == [72, 0]
    assert box.frame_count == 1
    assert box.compressorname == b'\0' * 32
    assert box.depth == 24

    assert len(box.boxes) == 0

    assert bytes(box) == bs.bytes
Exemplo n.º 27
0
def test_hvcc_box():
    bs = pack("uintbe:32, bytes:4, "
              "uintbe:8, "
              "int:2, int:1, int:5, uintbe:32, uintbe:48, uintbe:8, "
              "bits:4, int:12, bits:6, int:2, bits:6, int:2, bits:5, int:3, bits:5, int:3, "
              "uintbe:16, uint:2, uint:3, uint:1, uint:2, uint:8, "

              "uint:1, bits:1, uint:6, uintbe:16, "
              
              "uint:16, bytes:3",
              39, b"hvcc",
              1,
              0, 0, 3, 1879048192, 193514046488576, 90,
              '0b1111', 0, '0b111111', 0, '0b111111', 1, '0b11111', 0, '0b11111', 0,
              0, 0, 1, 0, 3, 1,

              1, '0b0', 32, 1,

              3, b"321")

    box_header = Parser.parse_header(bs)
    hvcc = bx_def.HVCC.parse_box(bs, box_header)
    box = hvcc

    assert box.header.start_pos == 0
    assert box.header.type == b"hvcc"
    assert box.header.box_size == 39

    assert box.configuration_version == 1

    assert box.general_profile_space == 0
    assert box.general_tier_flag == 0
    assert box.general_profile_idc == 3
    assert box.general_profile_compatibility_flags == 1879048192
    assert box.general_constraint_indicator_flags == 193514046488576
    assert box.general_level_idc == 90

    assert box.min_spatial_segmentation_idc == 0
    assert box.parallelism_type == 0
    assert box.chroma_format == 1
    assert box.bit_depth_luma_minus_8 == 0
    assert box.bit_depth_chroma_minus_8 == 0

    assert box.avg_frame_rate == 0
    assert box.constant_frame_rate == 0
    assert box.num_temporal_layers == 1
    assert box.temporal_id_nested == 0
    assert box.length_size_minus_one == 3
    assert box.num_of_arrays == 1

    assert len(box.arrays) == 0
    box.load(bs)
    assert len(box.arrays) == 1

    array = box.arrays[0]
    assert array.array_completeness == 1
    assert array.nal_unit_type == 32
    assert array.num_nalus == 1
    assert len(array.nalus) == 1

    nalu = array.nalus[0]
    assert nalu.nal_unit_length == 3
    assert nalu.nal_unit == b"321"

    assert bytes(box) == bs.bytes
Exemplo n.º 28
0
def test_photo_heic_guided_parsing():
    bstr = ConstBitStream(filename="data/photo.heic")

    box_header = Parser.parse_header(bstr)
    ftyp = parse.FTYP.parse_box(bstr, box_header)
    assert ftyp.header.start_pos == 0
    assert ftyp.header.type == b"ftyp"
    assert ftyp.header.box_size == 24
    assert ftyp.major_brand == 1751476579  # b"heic"
    assert ftyp.minor_version == 0
    assert ftyp.compatible_brands == [1835623985,  # b"mif1"
                                      1751476579]  # b"heic"
    assert ftyp.padding == b''

    # meta
    box_header = Parser.parse_header(bstr)
    meta = parse.META.parse_box(bstr, box_header)
    assert meta.header.start_pos == 24
    assert meta.header.type == b"meta"
    assert meta.header.box_size == 3955
    assert meta.header.version == 0
    assert meta.header.flags == b"\x00\x00\x00"
    assert meta.padding == b''

    # meta/hdlr
    box_header = Parser.parse_header(bstr)
    hdlr = parse.HDLR.parse_box(bstr, box_header)
    assert hdlr.header.start_pos == 36
    assert hdlr.header.type == b"hdlr"
    assert hdlr.header.box_size == 34
    assert hdlr.header.version == 0
    assert hdlr.header.flags == b"\x00\x00\x00"
    assert hdlr.pre_defined == 0
    assert hdlr.handler_type == b"pict"
    assert hdlr.name == b'\0'
    assert hdlr.padding == b'\0'

    # meta/dinf
    box_header = Parser.parse_header(bstr)
    dinf = parse.DINF.parse_box(bstr, box_header)
    assert dinf.header.start_pos == 70
    assert dinf.header.type == b"dinf"
    assert dinf.header.box_size == 36
    assert dinf.padding == b''

    # meta/dinf/dref
    box_header = Parser.parse_header(bstr)
    dref = parse.DREF.parse_box(bstr, box_header)
    assert dref.header.start_pos == 78
    assert dref.header.type == b"dref"
    assert dref.header.box_size == 28
    assert dref.header.version == 0
    assert dref.header.flags == b"\x00\x00\x00"
    assert dref.entry_count == 1
    assert dref.padding == b''

    # meta/dinf/dref/url_
    box_header = Parser.parse_header(bstr)
    url = parse.URL_.parse_box(bstr, box_header)
    assert url.header.start_pos == 94
    assert url.header.type == b"url "
    assert url.header.box_size == 12
    assert url.location is None
    assert url.padding == b''

    # meta/pitm
    box_header = Parser.parse_header(bstr)
    pitm = parse.PITM.parse_box(bstr, box_header)
    assert pitm.header.start_pos == 106
    assert pitm.header.type == b"pitm"
    assert pitm.header.box_size == 14
    assert pitm.padding == b''

    # meta/iinf
    box_header = Parser.parse_header(bstr)
    iinf = parse.IINF.parse_box(bstr, box_header)
    assert iinf.header.start_pos == 120
    assert iinf.header.type == b"iinf"
    assert iinf.header.box_size == 1085
    assert iinf.entry_count == 51
    assert iinf.padding == b''

    for i in range(iinf.entry_count):
        # meta/iinf/infe
        box_header = Parser.parse_header(bstr)
        infe = parse.INFE.parse_box(bstr, box_header)

        if infe.item_id == 49:
            assert infe.header.start_pos == 134 + 48 * 21
            assert infe.header.type == b"infe"
            assert infe.header.box_size == 21
            assert infe.header.version == 2
            assert infe.header.flags == b"\x00\x00\x00"

            assert infe.item_id == 49
            assert infe.item_protection_index == 0
            assert infe.item_type == 1735551332     # b"grid"
            assert infe.item_name == b'\0'
            assert infe.content_type is None
            assert infe.content_encoding is None
            assert infe.item_uri_type is None
            assert infe.extension_type is None
            assert infe.padding == b''
        elif infe.item_id == 50:
            assert infe.header.start_pos == 134 + 49 * 21
            assert infe.header.type == b"infe"
            assert infe.header.box_size == 21
            assert infe.header.version == 2
            assert infe.header.flags == b"\x00\x00\x00"

            assert infe.item_id == 50
            assert infe.item_protection_index == 0
            assert infe.item_type == 1752589105     # b"hvc1"
            assert infe.item_name == b'\0'
            assert infe.content_type is None
            assert infe.content_encoding is None
            assert infe.item_uri_type is None
            assert infe.extension_type is None
            assert infe.padding == b''
        elif infe.item_id == 51:
            assert infe.header.start_pos == 134 + 50 * 21
            assert infe.header.type == b"infe"
            assert infe.header.box_size == 21
            assert infe.header.version == 2
            assert infe.header.flags == b"\x00\x00\x01"

            assert infe.item_id == 51
            assert infe.item_protection_index == 0
            assert infe.item_type == 1165519206     # b"Exif"
            assert infe.item_name == b'\0'
            assert infe.content_type is None
            assert infe.content_encoding is None
            assert infe.item_uri_type is None
            assert infe.extension_type is None
            assert infe.padding == b''
        else:
            assert infe.header.start_pos == 134 + i * 21
            assert infe.header.type == b"infe"
            assert infe.header.box_size == 21
            assert infe.header.version == 2
            assert infe.header.flags == b"\x00\x00\x01"

            assert infe.item_id == i + 1
            assert infe.item_protection_index == 0
            assert infe.item_type == 1752589105     # b"hvc1"
            assert infe.item_name == b'\0'
            assert infe.content_type is None
            assert infe.content_encoding is None
            assert infe.item_uri_type is None
            assert infe.extension_type is None
            assert infe.padding == b''

    # meta/iref
    box_header = Parser.parse_header(bstr)
    iref = parse.IREF.parse_box(bstr, box_header)
    assert iref.header.start_pos == 1205
    assert iref.header.type == b"iref"
    assert iref.header.box_size == 148
    assert iref.header.version == 0
    assert iref.header.flags == b"\x00\x00\x00"
    assert iref.padding == b''

    # meta/iref/dimg
    box_header = Parser.parse_header(bstr)
    dimg = SingleItemTypeReferenceBox.parse_box(bstr, box_header)
    assert dimg.header.start_pos == 1217
    assert dimg.header.type == b"dimg"
    assert dimg.header.box_size == 108
    assert dimg.from_item_id == 49
    assert dimg.reference_count == 48
    assert dimg.to_item_ids == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
                                15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
                                27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
                                39, 40, 41, 42, 43, 44, 45, 46, 47, 48]
    assert dimg.padding == b''

    # meta/iref/thmb
    box_header = Parser.parse_header(bstr)
    thmb = SingleItemTypeReferenceBox.parse_box(bstr, box_header)
    assert thmb.header.start_pos == 1325
    assert thmb.header.type == b"thmb"
    assert thmb.header.box_size == 14
    assert thmb.from_item_id == 50
    assert thmb.reference_count == 1
    assert thmb.to_item_ids == [49]
    assert thmb.padding == b''

    # meta/iref/cdsc
    box_header = Parser.parse_header(bstr)
    cdsc = SingleItemTypeReferenceBox.parse_box(bstr, box_header)
    assert cdsc.header.start_pos == 1339
    assert cdsc.header.type == b"cdsc"
    assert cdsc.header.box_size == 14
    assert cdsc.from_item_id == 51
    assert cdsc.reference_count == 1
    assert cdsc.to_item_ids == [49]
    assert cdsc.padding == b''

    # meta/iprp
    box_header = Parser.parse_header(bstr)
    iprp = parse.IPRP.parse_box(bstr, box_header)
    assert iprp.header.start_pos == 1353
    assert iprp.header.type == b"iprp"
    assert iprp.header.box_size == 1778
    assert iprp.padding == b''

    # meta/iprp/ipco
    box_header = Parser.parse_header(bstr)
    ipco = parse.IPCO.parse_box(bstr, box_header)
    assert ipco.header.start_pos == 1361
    assert ipco.header.type == b"ipco"
    assert ipco.header.box_size == 1452
    assert ipco.padding == b''

    # meta/iprp/ipco/colr
    box_header = Parser.parse_header(bstr)
    colr = UnknownBox.parse_box(bstr, box_header)
    assert colr.header.start_pos == 1369
    assert colr.header.type == b"colr"
    assert colr.header.box_size == 560
    assert colr.padding == b''

    # meta/iprp/ipco/hvcC
    box_header = Parser.parse_header(bstr)
    hvcC = UnknownBox.parse_box(bstr, box_header)
    assert hvcC.header.start_pos == 1929
    assert hvcC.header.type == b"hvcC"
    assert hvcC.header.box_size == 112
    assert hvcC.padding == b''

    # meta/iprp/ipco/ispe
    box_header = Parser.parse_header(bstr)
    ispe = UnknownBox.parse_box(bstr, box_header)
    assert ispe.header.start_pos == 2041
    assert ispe.header.type == b"ispe"
    assert ispe.header.box_size == 20
    assert ispe.padding == b''

    # meta/iprp/ipco/ispe
    box_header = Parser.parse_header(bstr)
    ispe = UnknownBox.parse_box(bstr, box_header)
    assert ispe.header.start_pos == 2061
    assert ispe.header.type == b"ispe"
    assert ispe.header.box_size == 20
    assert ispe.padding == b''

    # meta/iprp/ipco/irot
    box_header = Parser.parse_header(bstr)
    irot = UnknownBox.parse_box(bstr, box_header)
    assert irot.header.start_pos == 2081
    assert irot.header.type == b"irot"
    assert irot.header.box_size == 9
    assert irot.padding == b''

    # meta/iprp/ipco/pixi
    box_header = Parser.parse_header(bstr)
    pixi = UnknownBox.parse_box(bstr, box_header)
    assert pixi.header.start_pos == 2090
    assert pixi.header.type == b"pixi"
    assert pixi.header.box_size == 16
    assert pixi.padding == b''

    # meta/iprp/ipco/colr
    box_header = Parser.parse_header(bstr)
    colr = UnknownBox.parse_box(bstr, box_header)
    assert colr.header.start_pos == 2106
    assert colr.header.type == b"colr"
    assert colr.header.box_size == 560
    assert colr.padding == b''

    # meta/iprp/ipco/hvcC
    box_header = Parser.parse_header(bstr)
    hvcC = UnknownBox.parse_box(bstr, box_header)
    assert hvcC.header.start_pos == 2666
    assert hvcC.header.type == b"hvcC"
    assert hvcC.header.box_size == 111
    assert hvcC.padding == b''

    # meta/iprp/ipco/ispe
    box_header = Parser.parse_header(bstr)
    ispe = UnknownBox.parse_box(bstr, box_header)
    assert ispe.header.start_pos == 2777
    assert ispe.header.type == b"ispe"
    assert ispe.header.box_size == 20
    assert ispe.padding == b''

    # meta/iprp/ipco/pixi
    box_header = Parser.parse_header(bstr)
    pixi = UnknownBox.parse_box(bstr, box_header)
    assert pixi.header.start_pos == 2797
    assert pixi.header.type == b"pixi"
    assert pixi.header.box_size == 16
    assert pixi.padding == b''

    # meta/iprp/ipma
    box_header = Parser.parse_header(bstr)
    ipma = parse.IPMA.parse_box(bstr, box_header)
    assert ipma.header.start_pos == 2813
    assert ipma.header.type == b"ipma"
    assert ipma.header.box_size == 318
    assert ipma.header.version == 0
    assert ipma.header.flags == b"\x00\x00\x00"
    assert ipma.entry_count == 50
    assert len(ipma.entries) == 50
    assert ipma.padding == b''

    entry = ipma.entries[0]
    assert entry.item_id == 1
    assert entry.association_count == 3
    assert len(entry.associations) == 3
    association = entry.associations[0]
    assert association.essential == 1
    assert association.property_index == 3
    association = entry.associations[1]
    assert association.essential == 1
    assert association.property_index == 1
    association = entry.associations[2]
    assert association.essential == 1
    assert association.property_index == 2

    entry = ipma.entries[1]
    assert entry.item_id == 2
    assert entry.association_count == 3
    assert len(entry.associations) == 3
    association = entry.associations[0]
    assert association.essential == 1
    assert association.property_index == 3
    association = entry.associations[1]
    assert association.essential == 1
    assert association.property_index == 1
    association = entry.associations[2]
    assert association.essential == 1
    assert association.property_index == 2

    entry = ipma.entries[48]
    assert entry.item_id == 49
    assert entry.association_count == 3
    assert len(entry.associations) == 3
    association = entry.associations[0]
    assert association.essential == 0
    assert association.property_index == 4
    association = entry.associations[1]
    assert association.essential == 1
    assert association.property_index == 5
    association = entry.associations[2]
    assert association.essential == 0
    assert association.property_index == 6

    entry = ipma.entries[49]
    assert entry.item_id == 50
    assert entry.association_count == 5
    assert len(entry.associations) == 5
    association = entry.associations[0]
    assert association.essential == 1
    assert association.property_index == 7
    association = entry.associations[1]
    assert association.essential == 1
    assert association.property_index == 8
    association = entry.associations[2]
    assert association.essential == 0
    assert association.property_index == 9
    association = entry.associations[3]
    assert association.essential == 1
    assert association.property_index == 5
    association = entry.associations[4]
    assert association.essential == 0
    assert association.property_index == 10

    # meta/idat
    box_header = Parser.parse_header(bstr)
    idat = parse.IDAT.parse_box(bstr, box_header)
    idat.load(bstr)
    assert idat.header.start_pos == 3131
    assert idat.header.type == b"idat"
    assert idat.header.box_size == 16
    assert len(idat.data) == 8
    assert idat.data[0] == int.from_bytes(b"\x00", "big")
    assert idat.data[1] == int.from_bytes(b"\x00", "big")
    assert idat.data[6] == int.from_bytes(b"\x0b", "big")
    assert idat.data[7] == int.from_bytes(b"\xd0", "big")
    assert idat.padding == b''

    # meta/iloc
    box_header = Parser.parse_header(bstr)
    iloc = parse.ILOC.parse_box(bstr, box_header)
    assert iloc.header.start_pos == 3147
    assert iloc.header.type == b"iloc"
    assert iloc.header.box_size == 832
    assert iloc.header.version == 1
    assert iloc.header.flags == b"\x00\x00\x00"
    assert iloc.padding == b''

    assert iloc.offset_size == 4
    assert iloc.length_size == 4
    assert iloc.base_offset_size == 0
    assert iloc.index_size == 0
    assert iloc.item_count == 51
    assert len(iloc.items) == 51
    assert iloc.padding == b''

    item = iloc.items[0]
    assert item.item_id == 1
    assert item.construction_method == 0
    assert item.data_reference_index == 0
    assert item.base_offset is None
    assert item.extent_count == 1
    assert len(item.extents) == 1
    extent = item.extents[0]
    assert extent.extent_index is None
    assert extent.extent_offset == 14854
    assert extent.extent_length == 33763

    item = iloc.items[1]
    assert item.item_id == 2
    assert item.construction_method == 0
    assert item.data_reference_index == 0
    assert item.base_offset is None
    assert item.extent_count == 1
    assert len(item.extents) == 1
    extent = item.extents[0]
    assert extent.extent_index is None
    assert extent.extent_offset == 48617
    assert extent.extent_length == 35158

    item = iloc.items[49]
    assert item.item_id == 50
    assert item.construction_method == 0
    assert item.data_reference_index == 0
    assert item.base_offset is None
    assert item.extent_count == 1
    assert len(item.extents) == 1
    extent = item.extents[0]
    assert extent.extent_index is None
    assert extent.extent_offset == 3995
    assert extent.extent_length == 8651

    item = iloc.items[50]
    assert item.item_id == 51
    assert item.construction_method == 0
    assert item.data_reference_index == 0
    assert item.base_offset is None
    assert item.extent_count == 1
    assert len(item.extents) == 1
    extent = item.extents[0]
    assert extent.extent_index is None
    assert extent.extent_offset == 12646
    assert extent.extent_length == 2208

    # mdat
    box_header = Parser.parse_header(bstr)
    mdat = parse.MDAT.parse_box(bstr, box_header)
    mdat.load(bstr)
    assert mdat.header.start_pos == 3979
    assert mdat.header.type == b"mdat"
    assert mdat.header.box_size == 1350049
    assert len(mdat.data) == 1350033
    assert mdat.data[0] == int.from_bytes(b"\x00", "big")
    assert mdat.data[1] == int.from_bytes(b"\x00", "big")
    assert mdat.data[6] == int.from_bytes(b"\xaf", "big")
    assert mdat.data[7] == int.from_bytes(b"\x88", "big")
    assert mdat.data[1350031] == int.from_bytes(b"\xfd", "big")
    assert mdat.data[1350032] == int.from_bytes(b"\x80", "big")
    assert mdat.padding == b''
Exemplo n.º 29
0
    mdia_boxes_end = mdia.header.start_pos + mdia.header.box_size
    bstr.bytepos = mdia.boxes_start_pos

    for box_header in Parser.parse(bstr, headers_only=True):
        if bstr.bytepos >= mdia_boxes_end:
            break

        if box_header.type != b"hdlr":
            box = Parser.parse_box(bstr, box_header)
            box.load(bstr)

        else:
            # hdlr.name should finish with a b'\0'. If it doesn't, add one
            # Add a b'\0' for safety
            hdlr_bstr = BitStream(bytes(box_header))
            hdlr_header = Parser.parse_header(hdlr_bstr)
            hdlr_header.box_size += 1
            hdlr_bstr.overwrite(bytes(hdlr_header), 0)
            hdlr_bstr.append(
                bstr.read("bytes:{}".format(box_header.box_size -
                                            box_header.header_size)) + b'\0')
            box = Parser.parse_box(hdlr_bstr, hdlr_header)
            box.load(hdlr_bstr)

            # Prevent adding one too many b'\0'
            if box.padding.startswith(b'\0'):
                box.padding = box.padding[1:]

        mdia.append(box)

del bstr