Skip to content

Seek succeeds but any frame read is all zeros #349

@gatagat

Description

@gatagat

First of all, thanks for releasing this library!

I encountered a bug in seek, that causes the subsequently read frames to be constant zero. It would be simple to just linearly loop through the frames, but there is no indication of the error. It happens only with some AVI files, however these files play/seek as expected in e.g. VLC.

I would like to have something like the following process_video function that would allow processing a selected range of the video frames. I see the error if I call it with use_seek=True.

def frame_generator(demuxer):
    for packet in demuxer:
        for frame in packet.decode():
            img = frame.to_image()
            img = np.asarray(img)
            yield img

def process_video(in_container, process_frame, start, stop, use_seek=False):
    demuxer = in_container.demux(in_container.streams.video[0])
    generator = frame_generator(demuxer)
    if start > 0:
        if use_seek is True:
            in_container.streams.video[0].seek(start, 'frame', any_frame=True)
        else:
            i = 0
            while i < start:
                generator.next()
                i += 1
    if stop is None:
        max_frames = np.inf
    else:
        max_frames = stop - start

    for i, img in enumerate(generator):
        process_frame(start + i, img)
        if i + 1 >= max_frames:
            break

Python 2.7.13
av: 0.4.1 (from pypi)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions