def retimestamp_tags_inplace(f, fu):
    flv = FLV(f)
    offset = None

    for tag in flv.iter_tags():
        if offset is None and is_nonheader_media(tag):
            offset = tag.timestamp
            log.debug("Determined the offset to be %d", offset)

        # optimise for offset == 0, which in case of inplace updating is a noop
        if offset is not None and offset != 0:
            fu.seek(tag.offset + 4, os.SEEK_SET)
            fu.write(make_si32_extended(tag.timestamp - offset))
예제 #2
0
def retimestamp_tags_inplace(f, fu):
    flv = FLV(f)
    offset = None

    for tag in flv.iter_tags():
        if offset is None and is_nonheader_media(tag):
            offset = tag.timestamp
            log.debug("Determined the offset to be %d", offset)

        # optimise for offset == 0, which in case of inplace updating is a noop
        if offset is not None and offset != 0:
            fu.seek(tag.offset + 4, os.SEEK_SET)
            fu.write(make_si32_extended(tag.timestamp - offset))
def output_offset_tag(fi, fo, tag, offset):
    new_timestamp = tag.timestamp - offset
    # do not offset non-media and media header
    if not is_nonheader_media(tag):
        new_timestamp = tag.timestamp

    # write the FLV tag value
    fo.write(make_ui8(class_to_tag[tag.__class__]))
    # the tag size remains unchanged
    fo.write(make_ui24(tag.size))
    # wirte the new timestamp
    fo.write(make_si32_extended(new_timestamp))
    # seek inside the input file
    #   seek position: tag offset + tag (1) + size (3) + timestamp (4)
    fi.seek(tag.offset + 8, os.SEEK_SET)
    # copy the tag content to the output file
    #   content size:  tag size + stream ID (3) + previous tag size (4)
    fo.write(fi.read(tag.size + 7))
예제 #4
0
def output_offset_tag(fi, fo, tag, offset):
    new_timestamp = tag.timestamp - offset
    # do not offset non-media and media header
    if not is_nonheader_media(tag):
        new_timestamp = tag.timestamp

    # write the FLV tag value
    fo.write(make_ui8(class_to_tag[tag.__class__]))
    # the tag size remains unchanged
    fo.write(make_ui24(tag.size))
    # wirte the new timestamp
    fo.write(make_si32_extended(new_timestamp))
    # seek inside the input file
    #   seek position: tag offset + tag (1) + size (3) + timestamp (4)
    fi.seek(tag.offset + 8, os.SEEK_SET)
    # copy the tag content to the output file
    #   content size:  tag size + stream ID (3) + previous tag size (4)
    fo.write(fi.read(tag.size + 7))