Esempio n. 1
0
def load(fh, position, end):
    if position is None:
        position = fh.tell()

    fh.seek(position)
    header_size = 8
    size = struct.unpack(">I", fh.read(4))[0]
    name = fh.read(4)

    if name not in constants.CONTAINERS_LIST:
        if name == constants.TAG_SA3D:
            return sa3d.load(fh, position, end)
        else:
            return box.load(fh, position, end)

    if size == 1:
        size = struct.unpack(">Q", fh.read(8))[0]
        header_size = 16

    if size < 8:
        print "Error, invalid size in ", name, " at ", position
        return None

    if (position + size) > end:
        print "Error: Container box size exceeds bounds."
        return None

    padding = 0
    if name == constants.TAG_STSD:
        padding = 8

    if name in constants.SOUND_SAMPLE_DESCRIPTIONS:
        current_pos = fh.tell()
        fh.seek(current_pos + 8)
        sample_description_version = struct.unpack(">h", fh.read(2))[0]
        fh.seek(current_pos)

        if sample_description_version == 0:
            padding = 28
        elif sample_description_version == 1:
            padding = 28 + 16
        elif sample_description_version == 2:
            padding = 56
        else:
            print("Unsupported sample description version:",
                  sample_description_version)

    new_box = Container()
    new_box.name = name
    new_box.position = position
    new_box.header_size = header_size
    new_box.content_size = size - header_size
    new_box.padding = padding
    new_box.contents = load_multiple(
        fh, position + header_size + padding, position + size)

    if new_box.contents is None:
        return None

    return new_box
Esempio n. 2
0
def load(fh, position, end):
    if position is None:
        position = fh.tell()

    fh.seek(position)
    header_size = 8
    size = struct.unpack(">I", fh.read(4))[0]
    name = fh.read(4)

    if name not in constants.CONTAINERS_LIST:
        if name == constants.TAG_SA3D:
            return sa3d.load(fh, position, end)
        else:
            return box.load(fh, position, end)

    if size == 1:
        size = struct.unpack(">Q", fh.read(8))[0]
        header_size = 16

    if size < 8:
        print "Error, invalid size in ", name, " at ", position
        return None

    if (position + size) > end:
        print "Error: Container box size exceeds bounds."
        return None

    padding = 0
    stsd_version = 0
    if (name == constants.TAG_STSD):
        padding = 8

    if (name == constants.TAG_MP4A):
        current_pos = fh.tell()
        fh.seek(current_pos + 8)
        sample_description_version = struct.unpack(">h", fh.read(2))[0]
        fh.seek(current_pos)

        if sample_description_version == 1:
            padding = 28 + 16  # Mov
        else:
            padding = 28  # Mp4

    new_box = Container()
    new_box.name = name
    new_box.position = position
    new_box.header_size = header_size
    new_box.content_size = size - header_size
    new_box.padding = padding
    new_box.contents = load_multiple(fh, position + header_size + padding,
                                     position + size)

    if new_box.contents is None:
        return None

    return new_box
Esempio n. 3
0
def load(fh, position=None, end=None):
    if position is None:
        position = fh.tell()

    fh.seek(position)
    header_size = 8
    size = struct.unpack(">I", fh.read(4))[0]
    name = fh.read(4)

    if name not in constants.CONTAINERS_LIST:
        return box.load(fh, position, end)

    if size == 1:
        size = struct.unpack(">Q", fh.read(8))[0]
        header_size = 16

    if size < 8:
        print "Error, invalid size in ", name, " at ", position
        return None

    if (position + size) > end:
        print "Error: Container box size exceeds bounds."
        return None

    new_box = Container()
    new_box.name = name
    new_box.position = position
    new_box.header_size = header_size
    new_box.content_size = size - header_size
    new_box.contents = load_multiple(
        fh, position + header_size, position + size)

    if new_box.contents is None:
        return None

    return new_box
Esempio n. 4
0
def load(fh, position, end):
    if position is None:
        position = fh.tell()

    fh.seek(position)
    header_size = 8
    size = struct.unpack(">I", fh.read(4))[0]
    name = fh.read(4).decode()

    is_box = name not in constants.CONTAINERS_LIST
    # Handle the mp4a decompressor setting (wave -> mp4a).
    if name == constants.TAG_MP4A and size == 12:
        is_box = True
    if is_box:
        if name == constants.TAG_SA3D:
            return sa3d.load(fh, position, end)
        return box.load(fh, position, end)

    if size == 1:
        size = struct.unpack(">Q", fh.read(8))[0]
        header_size = 16

    if size < 8:
        print("Error, invalid size", size, "in", name, "at", position)
        return None

    if (position + size) > end:
        print("Error: Container box size exceeds bounds.")
        return None

    padding = 0
    if name == constants.TAG_STSD:
        padding = 8
    if name in constants.SOUND_SAMPLE_DESCRIPTIONS:
        current_pos = fh.tell()
        fh.seek(current_pos + 8)
        sample_description_version = struct.unpack(">h", fh.read(2))[0]
        fh.seek(current_pos)

        if sample_description_version == 0:
            padding = 28
        elif sample_description_version == 1:
            padding = 28 + 16
        elif sample_description_version == 2:
            padding = 64
        else:
            print("Unsupported sample description version:",
                  sample_description_version)

    new_box = Container()
    new_box.name = name
    new_box.position = position
    new_box.header_size = header_size
    new_box.content_size = size - header_size
    new_box.padding = padding
    new_box.contents = load_multiple(fh, position + header_size + padding,
                                     position + size)

    if new_box.contents is None:
        return None

    return new_box