cv::VideoCapture skips corrupted frames and spoils my algorithm

asked 2016-02-20 23:18:22 -0600

HesNotTheStig gravatar image

I understand that I can't expect cv::VideoCapture to always return pristine frames if the video is corrupted, but I have a video comparison algorithm that DEMANDS that videos track time from beginning to end.

When I'm calculating a signature for a video, Determine who many frames are between each key frame by taking the total number of frames listed for the video and dividing by the FPS to derive who many frames separate one second. Unfortunately, if cv::VideoCapture finds a broken frame, it seems to decide to skip to the next frame rather than just returning that broken frame. I'm find with the frame being broken. My algorithm can handle that. So long as most of the frames are intact, I'm fine.

Unfortunately, if the video contains a patch of broken frames early on, then cv::VideoCapture skips ahead in time and introduces an undeseriable time shift in the video signature. When it comes time to compare this signature to another signature, the frames don't line up and I get a false negative.

Is there some way to make cv::VideoCapture.readFrame(Mat) return Mat::zeros when it encounters a damaged frame rather than skip ahead? I know it isn't doing this because I can have two videos with identical content and an identical listed run time turn up vastly different numbers of key frames.

edit retag flag offensive close merge delete