Ask Your Question
1

Try to read AVI file

asked 2012-11-16 11:34:12 -0600

pascal gravatar image

updated 2012-11-18 01:59:13 -0600

Adi gravatar image

I try to open an AVI file. The return of the open method is false, although the file exists.
Here below the snippet code. Any idea, suggestion is welcome.

#include "opencv2/opencv.hpp"

using namespace cv;
using namespace std;
int main(int argc , char* argv []) {
     VideoCapture cap(0); 
     bool ok = cap.open (argv [1]);
     if (ok == false) {
         cout << "Problem when opening file." << endl;
         return -1;
     } 
     return(0);
 }
edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
1

answered 2012-11-18 21:06:19 -0600

Hi Pascal,

I have tried your code and it works for me (with OpenCV 2.3.1).

Are you sure that the codec used to generate your video is supported in your system? (I have tried with an avi video encoded with MJPG codec and it works)

Also, this should not be an issue, but when you initialize your video capture:

VideoCapture cap(0);

The parameter 0 that you are passing to the constructor means that the capture device should be "the first webcam found in the system". It might be better to initialize it just as

VideoCapture cap;

But, again, I don't think this is the issue in your case. You should make sure that you have the proper codecs installed.

edit flag offensive delete link more
1

answered 2012-11-19 00:02:25 -0600

Mahdi gravatar image

Hi have you installed suitable codecs!?

if you are in linux you may do the following and install your opencv again:

cd ~
wget http://ffmpeg.org/releases/ffmpeg-0.7-rc1.tar.gz
tar -xvzf ffmpeg-0.7-rc1.tar.gz
cd ffmpeg-0.7-rc1
./configure --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libxvid --enable-x11grab --enable-swscale --enable-shared
make
sudo make install

If you are still concerned about the installation use this: link

edit flag offensive delete link more

Comments

Hi Mahdi. I work under Linux (REdHat) and use OpenCV 2.4.0. I have used a AVI file which can be read by MPlayer and also Windows Media Player. How can I know if I have installed proper codecs????? Here below the output of ffmpeg : ffmpeg -i /disc1/users/pklein/Pictures/fault_synth_45d/fault_synth_45d.avi ffmpeg version 1.0.git-83cab07 Copyright (c) 2000-2012 the FFmpeg developers built on Nov 16 2012 14:45:29 with gcc 4.1.2 (GCC) 20080704 (Red Hat 4.1.2-50) configuration: --disable-yasm libavutil 52. 7.100 / 52. 7.100 libavcodec 54. 71.100 / 54. 71.100 libavformat 54. 36.100 / 54. 36.100 libavdevice 54. 3.100 / 54. 3.100 libavfilter 3. 23.100 / 3. 23.100 libswscale 2. 1.102 / 2. 1.102 libswresample 0. 16.100 / 0. 16.100 Input #0, avi, from '/disc1/users/pklein/Pictures/fault_synth_45d/fault_synth_45d.avi': Duration: 00 ...(more)

pascal gravatar imagepascal ( 2012-11-23 08:02:13 -0600 )edit

I think you have not installed correctly 'cause your configuration is different from what I answered! I recommend you to isntall ffmpeg again and then rebuild and install OpenCV! Use the link I gave in my answers! I you my answer correct please mark is as correct. The marker is at the left side of the answer!:)

Mahdi gravatar imageMahdi ( 2012-11-27 13:55:00 -0600 )edit
0

answered 2012-11-23 07:25:06 -0600

pascal gravatar image

Hi everyone, I work under Linux and use OpenCV 2.4.0. I have made the test for a AVI file which can read by MPlayer. How to know if I have installed proper codecs?

Here below the output of launching ffmpeg on this AVI file :

ffmpeg -i /disc1/users/pklein/Pictures/fault_synth_45d/fault_synth_45d.avi ffmpeg version 1.0.git-83cab07 Copyright (c) 2000-2012 the FFmpeg developers built on Nov 16 2012 14:45:29 with gcc 4.1.2 (GCC) 20080704 (Red Hat 4.1.2-50) configuration: --disable-yasm libavutil 52. 7.100 / 52. 7.100 libavcodec 54. 71.100 / 54. 71.100 libavformat 54. 36.100 / 54. 36.100 libavdevice 54. 3.100 / 54. 3.100 libavfilter 3. 23.100 / 3. 23.100 libswscale 2. 1.102 / 2. 1.102 libswresample 0. 16.100 / 0. 16.100 Input #0, avi, from '/disc1/users/pklein/Pictures/fault_synth_45d/fault_synth_45d.avi': Duration: 00:00:03.10, start: 0.000000, bitrate: 24072 kb/s Stream #0:0: Video: msvideo1 (CRAM / 0x4D415243), rgb555le, 504x536, 10 tbr, 10 tbn, 10 tbc At least one output file must be specified

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-11-16 11:34:12 -0600

Seen: 2,011 times

Last updated: Nov 23 '12