You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Seek succeeds but any frame read is all zeros #349
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.
Why are you purposefully damaging the AVI file? If you open the same file with VLC it complains that the index is broken, and seeking will not work correctly..
Could you provide an un-damaged file which reproduces the error please?
I have yet another version of the script in question:
import logging
import numpy as np
import av
logging.basicConfig()
def process_video(container, start, count, use_seek=False):
global frame
if start:
if use_seek:
container.seek(start, backward=True, stream=container.streams.video[0])
else:
for i, _ in enumerate(container.decode(video=0)):
if i + 1 >= start:
break
for packet in container.demux(video=0):
print(packet)
for frame in packet.decode():
rgb_array = frame.to_ndarray(format='rgb24')
pal_array = np.array(frame.planes[0])
print(' ', frame)
print(' ', rgb_array.sum(), pal_array.sum())
if count is not None:
count -= 1
if count <= 0:
return
container = av.open('test2.avi')
process_video(container, 2, 1, use_seek=False)
container = av.open('test2.avi')
process_video(container, 2, 1, use_seek=True)
A few interesting things:
It doesn't matter if I seek in container time or stream time, or if it is bytes vs time mode, or backwards, or keyframes, or anything.
If I set count to None in the first pass, mine segfaults while getting the pal_array around frame 41.
Activity
jlaine commentedon Nov 7, 2018
Here is a simplified version of your code, which uses
seekand works fine for me:Could you please provide a sample video for which this does not work?
NOTE: it seems a bit strange to convert first to a PIL image then to a numpy array, why not use
frame.to_ndarraydirectly?gatagat commentedon Nov 8, 2018
Here is a small test file that triggers the issue. The file is cut to just 3MB using
dd. The output offfmpeg -towas not causing the error anymore.https://ufile.io/hl4bn
Use the following test to reproduce:
The output without seeking:
The output with seeking:
Concerning the to_image, the video is in pal8 which
to_ndarraycannot handle.gatagat commentedon Nov 8, 2018
I see the zero frames also with the current 6.0.0 release.
jlaine commentedon Nov 8, 2018
Why are you purposefully damaging the AVI file? If you open the same file with VLC it complains that the index is broken, and seeking will not work correctly..
Could you provide an un-damaged file which reproduces the error please?
mikeboers commentedon Nov 8, 2018
@gatagat Does this mean that you had a file which you weren't cutting with
ddthat was failing, and now it works fine (with newer PyAV)?gatagat commentedon Nov 8, 2018
The original file as well as the trimmed sample file both behave the same way, i.e., I get zero frames after a seek and correct frames without a seek.
I see the error in 6.0.0 as well.
gatagat commentedon Nov 8, 2018
@jlaine Here is a different test file that is tiny enough to share in full https://ufile.io/1lacy
mikeboers commentedon Nov 8, 2018
I have yet another version of the script in question:
A few interesting things:
counttoNonein the first pass, mine segfaults while getting the pal_array around frame 41.mikeboers commentedon Nov 8, 2018
If I am grabbing both RGB and PAL arrays, it segfaults at 41. If I'm just doing PAL, it segfaults at 85.
mikeboers commentedon Nov 8, 2018
I can trigger it via
np.array(plane),bytearray(plane), andplane.to_bytes().