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
2 chris says...
opencv (1.0.0-6.1ubuntu3) works fine for me. thx :)
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!
4 Gijs Molenaar says...
I don't think that has anything to do with my patch... :)
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 :-))
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?
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??
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.
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
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
12 jb says...
Can you post what you changed? (or a diff) I am trying to compile openCV from SVN with ffmpeg support.
Thanks
13 Gijs Molenaar says...
diff is on the PPA page. And it is not going to work for the svn version.
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.
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.
16 humbhenri says...
Doesn't work: OpenCV ERROR: Bad argument (codec not found)
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.
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.
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
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?
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
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.
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
24 Stéphane Paris says...
Hi Gijs, That's great! Thank you very much
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
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?
27 Vlad says...
Thanks a lot! You repository helped me (ubuntu 9.04 / amd64).
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
29 dim says...
worked perfect for me thx very much
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
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