Beispiel #1
0
def move_header_to_front(f):
    aftype, amoov, alist = read_iso_file(f)

    moov_idx = find_atom(alist, 'moov')
    mdat_idx = find_atom(alist, 'mdat')

    if moov_idx < mdat_idx:
        # nothing to be done
        return None

    adict = atoms.atoms_dict(alist)
    mdat = alist[mdat_idx]

    new_moov_idx = mdat_idx
    if 'wide' in adict:
        # if 'wide' atom preceeds 'mdat', let's keep it that way
        for wide in adict['wide']:
            if wide.offset + wide.size == mdat.offset:
                new_moov_idx -= 1
                break

    # for the moment assuming rewriting offsets in moov won't change
    # the atoms sizes - could happen if:
    #   2**32 - 1 - last_chunk_offset < moov.size
    data_offset = amoov.get_size()

    change_chunk_offsets(amoov, data_offset)

    del alist[moov_idx]
    alist[new_moov_idx:new_moov_idx] = [amoov]

    return alist
Beispiel #2
0
def read_iso_file(fobj):
    fobj.seek(0)

    al = list(atoms.read_atoms(fobj))
    ad = atoms.atoms_dict(al)
    aftyp, amoov, mdat = select_atoms(ad, ('ftyp', 1, 1), ('moov', 1, 1),
                                      ('mdat', 1, None))
    # print '(first mdat offset: %d)' % mdat[0].offset

    return aftyp, amoov, al