OpenCV's VideoCapture is broken and hasn't been fixed for the last 5 years: opencv/opencv#9053
This is a PyAV based replacement. Unlike other implementations it can seek at any time.
How to use:
reader = VideoReader('video.mp4')
reader.seek(reader.total_frames - 100) # frame number
while True:
frame = reader.read()
if not frame:
break
# frame is an ndarray - do something with it
print(f'frame {reader.position}: {frame}')
reader.close()
what does RuntimeError('Did not find target within 100 frames of seek') mean?
Is 100 an arbitrary number to make sure the desired frame actually exists? Can't really make out how the seek function works?