Ask Your Question
1

VideoCapture.read() count doesn't match CAP_PROP_FRAME_COUNT or output by FFMPEG

asked 2015-07-13 09:57:01 -0600

jackwayneright gravatar image

When I check my video frame count using CAP_PROP_FRAME_COUNT, it says there are 300 frames. Similarly, when I use FFMPEG to output the frames of the video, I also get 300 frames. However, when I use a regular VideoCapture read loop similar to the code below, I always get 296 frames. I'm guessing this has something to do with the video format being H264 and the way the data is compressed in such a video. But some of the data I'm using is given with the 300 frame count and my code relies on the OpenCV output which is giving me 296 frames. This discrepancy makes matching the two sets of data a headache. Can anyone explain why there is the difference in frame count/output and how to properly get the two sets of data to match up? In particular, is there just some specific setting I need to look into to get the read() loop to hand back the same 300 frames that FFMPEG would output? Thanks.

Code:

ret, frame = self.read()
frame_count = self.video_capture.get(cv2.CAP_PROP_FRAME_COUNT)
while True:
    if ret:
        # Do stuff with the frame here.
    else:
        break
    ret, frame = self.read()
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-04-10 01:17:36 -0600

got the same problem, confused

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2015-07-13 09:57:01 -0600

Seen: 1,113 times

Last updated: Jul 13 '15