Getting video i/o working with opencv and Ubuntu Jaunty (9.04)

3 May 2009

I was disappointed, crying, screaming, running around angry and banging my head against the wall when the video i/o functionality stopped working when I updated to the latest Ubuntu release (Jaunty). But since this is a open source world, I fixed this problem myself. Gentoo actually fixed this bug 1.5 year ago, so I used that patch and did some modifications.

If you are as frustrated as I am, don't seek any further. I made a Launchpad PPA for this new OpenCV package. I changed the includes to the new location and replaced the img_convert() function with the gentoo code as example. To install my packages open a console and run:

   sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com cafc44ee7f39098ce6ec229cca70e6a9087475a0
   

after that add the following line to your /etc/apt/sources.list:

   deb http://ppa.launchpad.net/gijzelaar/opencv/ubuntu jaunty main
   

After running a apt-get update you can install all the opencv packages, and they actually work.

By the way, if you use Python and OpenCV I advise you to check out the ctypes version of the python bindings. You can install them from my opencv repository by installing the python-opencv-ctypes package.

If you have any tips, comments or whatever please let me know in the comments.

Comments

1 Gijs Molenaar says...

Note that I still need to work a little bit on the layout of my blog :)

Posted at 6:23 p.m. on May 3, 2009

2 chris says...

opencv (1.0.0-6.1ubuntu3) works fine for me. thx :)

Posted at 12:49 a.m. on May 4, 2009

3 Thomas says...

I just installed Jaunty and added your repository to my sources.list. Then I upgraded the OpenCV packages and am now using version 1.0.0-6.1ubuntu3. I re-compiled my OpenCV programs. When I call:

 double fps = cvGetCaptureProperty( b_cam, CV_CAP_PROP_FPS );

I get the error:

HIGHGUI ERROR: V4L2: getting property #5 is not supported

When I call:

CvVideoWriter *b_writer = cvCreateVideoWriter( write_time, CV_FOURCC('M', 'J', 'P', 'G'), fps, cvGetSize( b_img ), is_color );

I get the error:

Output #0, avi, to 'stream/f20090504_103212.171590.avi': Stream #0.0: Video: MJPG / 0x47504A4D, yuv420p, 640x480, q=2-31, 800 kb/s, 90k tbn OpenCV ERROR: Bad argument (codec not found) in function cvCreateVideoWriter, cvcap_ffmpeg.cpp(579) Terminating the application...

Then the program terminates and gives a lot of:

called from cvUnregisterType, cxpersistence.cpp(4933)

messages. I have a frame grabber that I am reading video in from and I am trying to save that video to disk so that I can replay it later. Was your fix supposed to help with this? Do you have any suggestions? This was not working in Intrepid either. Thanks!

Posted at 7:46 p.m. on May 4, 2009

4 Gijs Molenaar says...

I don't think that has anything to do with my patch... :)

Posted at 7:58 p.m. on May 4, 2009

5 Naish says...

Hi Gijs,

Nice that you fixed this!! I think I do something wrong. I followed your instructions. After that I removed opencv

sudo apt-get remove libcv1

and installed it again: sudo apt-get install libcv1

I get the error: The following packages have unmet dependencies: libcv1: Depends: libavcodec52 (>= 3:0.svn20090303-1) but it is not installable or libavcodec-unstripped-52 (>= 3:0.svn20090303-1) but it is not installable Depends: libavformat52 (>= 3:0.svn20090303-1) but 3:0.svn20080206-12ubuntu3.1 is to be installed or libavformat-unstripped-52 (>= 3:0.svn20090303-1) but it is not going to be installed Depends: libavutil49 (>= 3:0.svn20090303-1) but 3:0.svn20080206-12ubuntu3.1 is to be installed or libavutil-unstripped-49 (>= 3:0.svn20090303-1) but it is not going to be installed Depends: libswscale0 (>= 3:0.svn20090303-1) but 3:0.svn20080206-12ubuntu3.1 is to be installed or libswscale-unstripped-0 (>= 3:0.svn20090303-1) but it is not going to be installed E: Broken packages

I am using Ubuntu: Linux omega 2.6.27-7-generic

Greets Naish (Tjerk :-))

Posted at 10:09 p.m. on May 11, 2009

6 switch says...

Hi Gijs,

Great job on the fix, however i have run into complications while trying to use the cvVideoWriter function, i keep getting the error.

Opencv Error: (no codec found)

Any ideas?

Posted at 8:07 p.m. on May 12, 2009

7 Owen says...

I am having trouble using:

double width = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);

When I use it with a capture device from my webcam it works fine, but when I capture a file it returns 0. This is very similar to the error that brought me to this page in the first place (i.e. works with CAM not with file, implies something wrong with codecs/FFMPEG). I should clarify that I have no problems with cvQueryFrame() and I am able to output the video file to a window. Are you sure this problem isn't related??

Posted at 10:55 p.m. on May 12, 2009

8 Gijs Molenaar says...

Thomas: getting property #5 is not supported. You are trying to retrieve a property from the camera that is not supported.

All people who have problems writing video's to output, I don't know if this is related yet, but I expect not.

Naish/Tjerk you just have some dependency problem. Try to remove all packages listed in your comment with dpkg -P and try again. There is a package blocking the installation.

Posted at 10 p.m. on May 13, 2009

9 steffen says...

Hi Gijs!

thanks for your fix. I installed it as described on your website, but nothing really changed. do I have to change the include paths as well?! opencv says still: ~$ pkg-config --libs opencv -L/usr/local/lib -lcxcore -lcv -lhighgui -lcvaux -lml
~$ pkg-config --cflags opencv -I/usr/local/include/opencv
~$

But I get in eclipse the same error log message as before: Invoking: GCC C++ Linker g++ -L/usr/local/lib -lcxcore -lcv -lhighgui -lcvaux -lml -o"ComputerVision" ./one.o ./src/image.o ./src/imgRectification.o ./src/main.o -lcv -lhighgui /usr/bin/ld: warning: libavcodec.so.51, needed by /usr/local/lib/libcxcore.so, not found (try using -rpath or -rpath-link) /usr/local/lib/libhighgui.so: undefined reference to `img_convert' collect2: ld gab 1 als Ende-Status zurück make: * [ComputerVision] Fehler 1

would be very helpful if you could give me any advise how to fix that problem :)

thanks!

steffen

Posted at 1:15 p.m. on May 15, 2009

10 gmatta says...

Hello !

Hi Owen, I have the same problem than you. Have you fixed it ?

Thanks.

Posted at 8:54 p.m. on May 15, 2009

11 Gijs Molenaar says...

@steffen

are you sure you are using my package? I see you are using a opencv installation from /usr/local. My package doesn't install to /usr/local

Posted at 9:11 p.m. on May 15, 2009

12 jb says...

Can you post what you changed? (or a diff) I am trying to compile openCV from SVN with ffmpeg support.

Thanks

Posted at 8:10 p.m. on May 17, 2009

13 Gijs Molenaar says...

diff is on the PPA page. And it is not going to work for the svn version.

Posted at 7:50 p.m. on May 18, 2009

14 Dan Halbert says...

I have a jaunty x86_64 system, and have successfully built the OpenCV svn trunk version (as of 18-May-09) without any patches using the cmake build.

I already had the stock ffpmeg, libavcodec-dev, libavformat-dev, and lib-avutil packages installed from the jaunty repositories. That worked up to a point, but I was getting img_convert undeclared.

After reading through the CMake files and cvconfig.h, I saw I was missing the libswscale-dev package. I installed it and rebuilt. The build worked all the way through, and "make test" also was successful.

Posted at 7:14 p.m. on May 19, 2009

15 jb says...

Thank you, it worked with cmake and the latest version. The old configure script is broken. I use also a jaunty x86_68 system.

Posted at 9:47 p.m. on May 19, 2009

16 humbhenri says...

Doesn't work: OpenCV ERROR: Bad argument (codec not found)

Posted at 12:41 a.m. on May 25, 2009

17 Kyu says...

Hi, thanks for your effort. However, it doesn't work here too (but problem ONLY occurs when writing to a video; reading WORKS!): Output #0, avi, to 'out.avi': Stream #0.0: Video: MJPG / 0x47504A4D, yuv420p, 176x144, q=2-31, 800 kb/s, 90k tbn, 25 tbc OpenCV ERROR: Bad argument (codec not found) in function cvCreateVideoWriter, cvcap_ffmpeg.cpp(579)

This occurs when I try to call CvVideoWriter* vw=cvCreateVideoWriter(outvideo,CV_FOURCC('M','J','P','G'),fps,cvSize(frameW,frameH),1);

where frameH, frameW, fps are valid int numbers.

I also tried DIVX, XVID format in FOURCC, but got the same error.

However, I verified that reading-related functions were working OK. (cvCaptureFromFile, cvQueryFrame, cvGetCaptureProperty, cvGrabFrame, and cvRetrieveFrame)

I was trying hard to install opencv with both 1394 input + ffmpeg video support for a long time but still didn't get to the point yet. I use Jaunty 9.04 with additional standard ffmpeg-related dev packages installed from synaptics. (libavcodec-dev, libavformat-dev, libavutil-dev, libswscale-dev)

With your package installed, only writing-related functions are not working. Do you have any hint? Thanks.

Posted at 11:22 p.m. on May 25, 2009

18 Gijs Molenaar says...

No sorry, I didn't have a look at that (yet). I think we should wait for some good real debian/ubuntu solution.

Posted at 11:23 a.m. on May 26, 2009

19 stefie10 says...

Hi,

I'm also seeing "OpenCV ERROR: Bad argument (codec not found)" when I call cvCreateVideoWriter. Could it be related to this bug? http://www.lavrsen.dk/twiki/bin/view/Motion/BugReport2007...

I tried installing libavcodec-unstripped-52 but it removed libavcodec-dev and the opencv packages because they depend on libavcodec-dev.

Stefanie

Posted at 4:01 p.m. on June 2, 2009

20 kayss says...

Hi, Thank you for your work,

Sorry, but I don't recieve answer from the server and I don't recieve the keys.

Please, Can you help me?

Posted at 6:23 p.m. on June 9, 2009

21 John says...

Hi Gijs,

Thanks for your work, but it doesn't seem to work for me either. I'm afraid I'm a bit of a Linux n00b. I can install libcv1 and dependencies (v1.0.0.6.1ubuntu3) from your repository, and I am able to compile my own code, but it does not play any video. (It used to work fine on my old Ubuntu 8.04 machine).

Any suggestions would be greatly appreciated!

John

Posted at 5:52 a.m. on June 17, 2009

22 Gijs Molenaar says...

John; I don't think it has something to do with this problem. Please make sure the code you are using actually is working with opencv.

Posted at 4:04 p.m. on June 17, 2009

23 John says...

Hi Gijs,

Thanks for responding so quickly. I ran the exact same code on a different machine (running 8.04) and it worked fine. As before, I'd appreciate any ideas you might have.

John

Posted at 9:40 p.m. on June 18, 2009

24 Stéphane Paris says...

Hi Gijs, That's great! Thank you very much

Posted at 6:33 p.m. on June 23, 2009

25 Benoit R says...

Same problem for writing video output:

OpenCV ERROR: Bad argument (codec not found) in function cvCreateVideoWriter, cvcap_ffmpeg.cpp(579)

Does this work for you?

Where are installed the libavi* libraries on your computer:

On mine I have using find /usr/ -iname "libav*"

/usr/lib/libavahi-core.so.5.0.5
/usr/lib/libavdevice.so.52
/usr/lib/libavcodec.so
/usr/lib/libavutil.so
/usr/lib/libavformat.so
/usr/lib/libavahi-glib.so.1
/usr/lib/libavfilter.so.0
/usr/lib/libavfilter.so.0.4.0
/usr/lib/libavahi-qt3.so.1
/usr/lib/libavcodec.so.52.20.0
/usr/lib/i686/cmov/libavdevice.so.52
/usr/lib/i686/cmov/libavcodec.so
/usr/lib/i686/cmov/libavutil.so
/usr/lib/i686/cmov/libavformat.so
/usr/lib/i686/cmov/libavfilter.so.0
/usr/lib/i686/cmov/libavfilter.so.0.4.0
/usr/lib/i686/cmov/libavcodec.so.52.20.0
/usr/lib/i686/cmov/libavutil.so.49.15.0
/usr/lib/i686/cmov/libavutil.so.49
/usr/lib/i686/cmov/libavformat.so.52.31.0
/usr/lib/i686/cmov/libavdevice.so.52.1.0
/usr/lib/i686/cmov/libavformat.so.52
/usr/lib/i686/cmov/libavcodec.so.52
/usr/lib/libavahi-gobject.so.0
/usr/lib/libavahi-qt3.so.1.0.2
/usr/lib/libavutil.so.49.15.0
/usr/lib/libavutil.so.49
/usr/lib/vlc/codec/libavcodec_plugin.so
/usr/lib/vlc/demux/libavformat_plugin.so
/usr/lib/vlc/demux/libavi_plugin.so
/usr/lib/libavc1394.so.0.3.0
/usr/lib/libavahi-glib.so.1.0.1
/usr/lib/libavahi-client.so.3.2.4
/usr/lib/libavahi-core.so.5
/usr/lib/libavc1394.so.0
/usr/lib/openoffice/basis3.0/program/libavmediagst.so /usr/lib/openoffice/basis3.0/program/libavmediali.so /usr/lib/libavformat.so.52.31.0
/usr/lib/libavahi-ui.so.0.1.0
/usr/lib/libavahi-common.so.3.5.0
/usr/lib/libavformat.a
/usr/lib/libavdevice.so.52.1.0
/usr/lib/libavahi-common.so.3
/usr/lib/libavahi-ui.so.0
/usr/lib/pkgconfig/libavcodec.pc
/usr/lib/pkgconfig/libavutil.pc
/usr/lib/pkgconfig/libavformat.pc
/usr/lib/libavcodec.a /usr/lib/libavahi-gobject.so.0.0.1 /usr/lib/libavahi-client.so.3 /usr/lib/libavformat.so.52 /usr/lib/libavutil.a /usr/lib/libavcodec.so.52

Posted at 11:51 a.m. on June 24, 2009

26 Rob says...

Hi, I have the same problem like jhon... how can I make sure which codecs are suported to write video, from my opencv version?

Posted at 3:33 p.m. on June 30, 2009

27 Vlad says...

Thanks a lot! You repository helped me (ubuntu 9.04 / amd64).

Posted at 12:20 p.m. on July 2, 2009

28 Zenko says...

Thanks man I was completly disapointed so now I owe you a big one, I will send you by fedex the next hot chick I met xD

Thankssss

Posted at 11:36 a.m. on July 22, 2009

29 dim says...

worked perfect for me thx very much

Posted at 11:36 a.m. on July 22, 2009

30 kayss says...

Hi Gijs,

I don't recieve the keys. Is a very big problem for my!

There are another way to update my OpenCv library with your modification.

kayss

Posted at 12:10 p.m. on August 5, 2009

Comments are closed due to spamming. I'll enable it again when I wrote a better spam filter.