-1

I want to open a *.avi file and read its frames . But it didn't work . I think it's because myopencv don't support this kind of avi file. What can I do to make it capable?

VideoCapture capture("part.avi");
if(!capture.isOpened()){
    cout<<"failed to read the *.avi"<<endl;
    return -1;
}
double rate = capture.get(CV_CAP_PROP_FPS);
Size videoSize(capture.get(CV_CAP_PROP_FRAME_WIDTH),
               capture.get(CV_CAP_PROP_FRAME_HEIGHT));
long nFrame=static_cast<long>(capture.get(CV_CAP_PROP_FRAME_COUNT));
cout<<"FPS:"<<rate<<endl;
cout<<"width:"<<videoSize.width<<" height:"<<videoSize.height<<" number of frames:"<<nFrame<<endl;
Mat frame;
namedWindow("display");
long frameToStart = 500;
capture.set(CV_CAP_PROP_POS_FRAMES,frameToStart);
capture>>frame;
if(frame.empty()) return -1;

RESULTS:

FPS:23.0769

width:1280 height:720 number of frames:42202

Program ended with exit code: 255

  • Welcome to SO. So we can help you quickly, please give the question some context, tell us what you have tried already, and add an actual question. – Ramzi Khahil Jan 15 '15 at 15:08
  • I want to read frames for the avi file and it didn't work . – user3903457 Jan 15 '15 at 16:54
  • I want to open a *.avi file and read its frames . But it didn't work . I think it's because myopencv don't support this kind of avi file. What can I do to make it capable? – user3903457 Jan 15 '15 at 17:00

1 Answers1

0

I strongly recommend you read opencv documentation first. It is not the problem of opencv but your code. Videos are made of continous frames and you should place

capture>>frame;
if(frame.empty()) return -1;

within a loop like this:

while(1){
    capture>>frame;
    if(frame.empty()) return -1;
    imshow("display", frame);  //don't forget to show
}
Ramzi Khahil
  • 4,932
  • 4
  • 35
  • 69
Qmick Zh
  • 555
  • 3
  • 8