Ask Your Question
1

Help with detecting a wrong video header giving wrong frame amount

asked 2013-08-07 02:51:42 -0600

I have received a video from a research partner containing 1440 frames, but it has been cut with a cheap free video cutting tool from a larger video file. Result of this is that openCV actually thinks there are 15056 frames in the image when retrieving the amount of frames through the corresponding parameter retrieval.

This gives problems in the following situation:

VideoCapture input_video ("C:\\data\\video_test.avi");
Mat frame;
int frame_count = (int)input_video.get(CV_CAP_PROP_FRAME_COUNT);
for(int i = 0; i < frame_count; i++){
   input_video >> frame;
   imshow("frame", frame); 
   int key = waitKey(10);
   if (key == 27){
    break;
   }
}

It crashes the minute we go over the 1440 frames, because the next frame read is actually rubbish. Error that I retrieve when trying to read the unexisting 1441 frame is:

image description

However, when leaving out the visualization part, and switching the code of imshow to an imwrite(), all of a sudden, it continuous processing after frame 1440 and just outputs corrupted images until frame 15056.

I would like to know if anyone has a suggestion on how to capture the fact that this frame is corrupted, so that I can add a break statement in my for loop.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2013-08-07 03:07:26 -0600

berak gravatar image

what about:

input_video >> frame;
if ( frame.empty() )
     break;
edit flag offensive delete link more

Comments

Ill see if this helps :)

StevenPuttemans gravatar imageStevenPuttemans ( 2013-08-07 03:12:37 -0600 )edit

@berak, you are my saviour! Was looking at the capture properties, instead of the frame properties ... good I didn't spend too much time on this.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-08-07 03:15:02 -0600 )edit

Question Tools

Stats

Asked: 2013-08-07 02:51:42 -0600

Seen: 848 times

Last updated: Aug 07 '13