0

I am trying to play in avi file using opencv c++ in ubuntu but i am getting no output. The code im using is a standard code that i found online that is used to play an avi video but im seeing no output. And yes the video is in the same directory as my src code folder. The only thing im seeing is that on the first iteration of the while loop, frame is empty and hence breaks. but i do not know why it is happening as the video is working on vlc. I would really appreciate some help here as i have been stuck on it for the past 4-5 hours. #include "cv.h" // include it to used Main OpenCV functions. #include "highgui.h" //include it to use GUI functions.

int main(int argc, char** argv)
{
cvNamedWindow("Example3", CV_WINDOW_AUTOSIZE);

//CvCapture* capture = cvCreateFileCapture("20051210-w50s.flv");
CvCapture* capture = cvCreateFileCapture("tree.avi");
/* if(!capture)
    {
        std::cout <<"Video Not Opened\n";
        return -1;
    }*/
IplImage* frame = NULL;

while(1) {

    frame = cvQueryFrame(capture);
    //std::cout << "Inside loop\n";
    if (!frame)
        break;
    cvShowImage("Example3", frame);
    char c = cvWaitKey(33);
    if (c == 27) break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("Example3");
std::cout << "Hello!";
return 0;
}
ueg1990
  • 1,003
  • 2
  • 19
  • 39
  • Your code works well in my PC. – Haris Oct 26 '13 at 13:09
  • really?? could there be anything to do with ffmpeg?? – ueg1990 Oct 26 '13 at 13:22
  • You need to have ffmpeg. Is it installed on your system? Was it installed when you installed OpenCV? Why did you comment out the `if (!capture) {}` block? If it says that video could not be opened, it is either that the filename is wrong or you don't have support for ffmpeg installed. – JonasVautherin Oct 26 '13 at 22:42

2 Answers2

0

Are you running in Debug or release mode? In openCV 2.4.4 there is only a opencv_ffmpeg244.dll (the release .dll) but not one for debug. try switching to release mode.

MrSansoms
  • 31
  • 4
0

Remove the code lines:

char c = cvWaitKey(33);
if (c == 27) break;

and instead of these, just add :

cvWaitKey(33);

May be this could help.Here is the python code, that worked fine for me:

import cv
if __name__ == '__main__':
  capture = cv.CreateFileCapture('Wildlife.avi')
  loop = True
  while(loop):
    frame = cv.QueryFrame(capture)
    if (frame == None):
            break;
    cv.ShowImage('Wild Life', frame)
    char = cv.WaitKey(33)
    if (char != -1):
        if (ord(char) == 27):
            loop = False

Or this could be helpful.

Community
  • 1
  • 1
Maham
  • 432
  • 1
  • 8
  • 22