Reading Video From File With Dropped Frames
I am using OpenCV 2.4.6 on Windows 7. I am trying to read frames from a video file in sequence as fast as possible. I am using VideoCapture with grab() then retrieve() for each frame, which does read very fast. The problem is this method skips over my dropped frames (frames that were missed during recording). My AVI file has 2710 frames, with 21 dropped frames. When I use VideoCapture::set(CV_CAP_PROP_POS_FRAMES,frameNumber) before each grab(), I get the correct frame, including drops. For instance, if during creation of the AVI, frame 15 was dropped and I set to frame 15, I get frame 14 again. This is the behavior that I want. However, calling "set" on the frame number is significantly slower then just continuously reading the next frame. If I don't call "set", the dropped frames are skipped. For instance, if I request frame 15 (the first dropped/missing frame), it gives me frame 16. When I loop through all frames, I get 2689 frames (the number of non-dropped frames) which span the whole video file (as in, frame 2689 in this case is actually frame 2710). When I call set on each frame (set 1, set 2, etc... set 2710), I get 2710 frames, the way I want (but again, its too slow). I tried checking the current time on each frame (hoping that frame 16 would report that it was 2 frame durations past frame 14) via get(CV_CAP_PROP_POS_MSEC) but that did not solve the problem (it appears to just return the "non-dropped" frame number * the time). Does anyone have any suggestions on how I can detect these dropped frames (so that I can return a duplicate of the previous frame) to maintain the correct total number of frames, including drops? I'm thinking I may have to preprocess the video to determine which frames numbers are dropped but hoping there might be a faster way. Any suggestions are greatly appreciated.