CMU-INF-DIVA / avi-r

AVI-R Package (formerly DIVA IO): A robust reader for AVI video files

Home Page:https://pypi.org/project/avi-r/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Assertion Error during enumerate video frames

junpeiz opened this issue · comments

I use video = VideoReader(video_file, fix_missing=False) and try to enumerate frames by
for frame_id, frame in enumerate(video).

But Got the error as shown below:
File "/home/junpeiz/Projects/prop_gen/MEVA_proposal_generate.py", line 153, in extract_proposal
for frame_id, frame in enumerate(video):
File "/home/junpeiz/Projects/prop_gen/diva_io/video/reader.py", line 65, in iter
yield from self._frame_gen
File "/home/junpeiz/Projects/prop_gen/diva_io/video/reader.py", line 222, in _get_frame_gen
assert prev_frame is not None
AssertionError

I also read your source code in reader.py and find:

        frame = None
        while frame is None and key_frame_index > 0:
            key_frame_index -= 1
            key_frame_id = self._key_frame_ids[key_frame_index]
            frame = self._decode(key_frame_id)
        prev_frame = frame
        assert prev_frame is not None

May I know in which situation the frame would be None after this while loop?

Hi,

Could provide the video name causing this issue? I tried your code but did not reproduce the error.

prev_frame could be None if the decode of the nearest key frame fails, but this typically should not happen if you read the video from the beginning.

The video is 128.2.208.7:/mnt/hdd6tb/junpeiz/drop-01-videos/2018-03-12.10-05-00.10-10-00.hospital.G436.avi

I have tested it with the following lines, and found the first frame will raise the error.

>>> video_file = '/mnt/hdd6tb/junpeiz/drop-01-videos/2018-03-12.10-05-00.10-10-00.hospital.G436.avi'
>>> for frame_id, frame in enumerate(video):
...     frame.numpy()
...     print(frame_id)

Traceback (most recent call last):
File "", line 1, in
File "/home/junpeiz/Projects/prop_gen/diva_io/video/reader.py", line 65, in iter
yield from self._frame_gen
File "/home/junpeiz/Projects/prop_gen/diva_io/video/reader.py", line 222, in _get_frame_gen
assert prev_frame is not None
AssertionError

I also download it to my local computer, and it could not be opened by QuickTime Player. Not sure if it dues to the file itself is broken.

I checked the video and it seemed that the reason was the decode failure at frame 0.

This video file is really weird as it fails when you decode frame 0 for the first time. And all the consecutive frames are not in the correct position.

I just pushed some updates that should work for this video.

The QuickTime Player does not support avi videos. You may use IINA on macOS.