Ask Your Question

Help to Open Video File

asked 2013-11-24 20:49:08 -0500

dmcenan gravatar image

Hi Folks, When I use the code below to open a video, 0 is always returned for the cap.isOpened() function call. I tried numerous videos and formats and below I am using a sample AVI file from an official openCV tutorial so I know the format/codec is not an issue. I am using Linux Mint 15 with ffmpeg 0.8.9 installed and OpenCV 2.5. For an IDE I am using Eclipse Juno.

I have placed the avi video in the same folder as the exe (the Debug folder) and also in the project directory (when I store images in the project directory they always load so I don't think it is an issue on OpenCV not being able to locate the video file).

Does anyone know why the code below does not work? Does the code below work for anyone else, even with using a different video?

int main()
VideoCapture cap;"Megamind.avi");
cout<<cap.isOpened()<<endl; //ALWAYS returns 0!

Mat frame;


        imshow("Video", frame);

        if(waitKey(33) >= 0)
edit retag flag offensive close merge delete


Your code works perfectly in my PC. Have your tried command line to run the code ?.

Haris gravatar imageHaris ( 2013-11-24 23:27:50 -0500 )edit

Thanks Haris, I tried the code on a Windows PC and it ran fine. There must be some difference with my Linux setup but I am not sure far as I can see I have all the requirements for the code to run. I'll see if I can figure it out.

dmcenan gravatar imagedmcenan ( 2013-11-25 13:18:31 -0500 )edit

Did you find the answer for this problem?

Mariusz gravatar imageMariusz ( 2013-12-12 03:52:34 -0500 )edit

I have exactly the same problem, and no clue what causes the problem. Recompiling OpenCV might not be the point, because I didn't compile it in first place. I just used the compiled libs from the homepage.

Matthias gravatar imageMatthias ( 2013-12-20 11:23:24 -0500 )edit

The video works on my computer but I get no sound. I am using Mint 14 mate 64 bit .

I compile the program from the terminal.

ffmpeg is a sound library software but is this program suppose to play sound too?

keghn gravatar imagekeghn ( 2014-01-26 18:26:48 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2013-12-17 11:45:47 -0500

miks gravatar image

I had the same issue. I recompiled the OpenCV using the official instructions: And now it works fine. It might have been some problems when you don't compile in Release, or libraries are missing. Check your CMakeCache.txt if HAVE_FFMPEG is non-zero.

edit flag offensive delete link more

answered 2014-01-26 13:31:09 -0500

blengabs gravatar image

hi can i ask a question? where did you stored the video Megamind.avi. i have stores the video in my visual studio project. but the program can not read the file. i can read an image when i stored the image at the same place. or i give the path of video, but again i can not read the video by using the code above

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2013-11-24 20:49:08 -0500

Seen: 370 times

Last updated: Jan 26 '14