I have a video that is 2:12 sec long according to QuickTime on MacOS (10.14 Mojave).
I have the following code:
import cv2
vid = cv2.VideoCapture("video.mov")
length = int(vid.get(cv2.CAP_PROP_FRAME_COUNT)) # = 3953
fps = int(vid.get(cv2.CAP_PROP_FPS)) # = 29
def frame_set(index):
success = vid.set(cv2.CAP_PROP_POS_FRAMES, index)
success, img = vid.read()
return img
def frame_walk(index):
success = vid.set(cv2.CAP_PROP_POS_FRAMES, 0)
for i in range(index):
vid.read()
success, img = vid.read()
return img
sum(abs(frame_set(0) - frame_walk(0))) # = 0
sum(abs(frame_set(29) - frame_walk(29))) # = 0
sum(abs(frame_set(30) - frame_walk(30))) # = <big number>
frame_set(3953 - 128) # = <image>
frame_set(3953 - 127) # = None
frame_set(3952) # = None
frame_walk(3953 - 127) # = <image>
frame_walk(3952) # = <image>
Clearly a misalignment between the "frame index" method starts as soon as "1 second" has elapsed in the video. What ends up happening is that valid frame indices do not return images for the index method.
Am I doing something wrong here?
I tried reporting a bug, but that link is dead so I came here.