Ask Your Question
0

Reading Video From File With Dropped Frames

asked 2013-11-19 10:34:29 -0600

smunn gravatar image

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.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-11-20 07:17:23 -0600

Ikarus79 gravatar image

Hi,

spontaneously I would try to use VideoCapture::get(CV_CAP_PROP_POS_FRAMES). If the return value differs more than one to he previous one, you can suggest this amount of missing frames at this position in the file. In your case, before grabbing the 14th image get should return 14, but before grabbing the 15 image get should return 16.

However, this is just a suggestion, I don't know what VideoCapture::get(CV_CAP_PROP_POS_FRAMES) returns in case. Give it a try. cheers greg

edit flag offensive delete link more

Comments

Thanks for the suggestion, I tried this. The strange thing is, when I call set(CV_CAP_PROP_POS_FRAMES) on each frame number (including drops), it goes to the correct frame and calling get(CV_CAP_PROP_POS_FRAMES) after tells me the "correct" frame (including drops), but if I don't use set and I call get(CV_CAP_PROP_POS_FRAMES) on each frame that is received, I get the "incorrect" frame number (disregards drops). In other words, get returns different answers in the two scenarios (calling set or just reading next) for the exact same frames.

smunn gravatar imagesmunn ( 2013-11-20 08:47:59 -0600 )edit

Sorry, I have no clue. Actually I would address the problem while writing the video file, but I guess you can't do it.

Best

Ikarus79 gravatar imageIkarus79 ( 2013-11-20 10:46:24 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-11-19 10:34:29 -0600

Seen: 3,602 times

Last updated: Nov 20 '13