Showing posts with label ffmpeg. Show all posts
Showing posts with label ffmpeg. Show all posts

11 June 2010

OpenCV 2.1.0 and FFMPEG compilation solution

I had been recently struggling to compile OpenCV 2.1.0 with FFMPEG support on GNU/Linux. The problem was that the OpenCV CMake script fails to detect the important component of ffmpeg it needs; like avcodec, swscale, avformat. The more idiotic thing is that if one uses ccmake, the log is not visible. It is only after building that one sees that ffmpeg support is not there. One has to use cmake. Anyways, after doing cmake ../OpenCV-2.1.0, noted that config log said “ffmpeg 0″ and also put zeros against the above mentioned components of ffmpeg. Well, I knew that ffmpeg existed in all its components. I had also made a directory called ffmpeg in /usr/local/include and made symbolic links for the respective header files. Now it was a clear case of cmake being unable to find these, either because of poor CMakeLists.txt or the cmake itself. At this point, I did not want to dig into the innards of CMake; unlike autoconf it has an annoying tendency to hide information; for example where it searches for ffmpeg and such things. Such blackbox approach suits Ubuntu users no doubt. I tried parsing through the CMakeLists.txt and could not find anything that I could rectify. However, I did know that CMakeCache.txt contained the configured values. After that it was a matter of putting manually the include, lib paths and the linker flags in this for each of the ffmpeg components. After running cmake again, I could immediately see that ffmpeg components were recognised and ffmpeg was turned to 1. make happily started building cvcap_ffmpeg which meant that ffmpeg was actually being used. However, the build process croaked at 99% when trying to link to the actual libavcodec/libavformat and libswscale. Clearly, the linker links I had passed as a guess had not worked. Now, I did cmake again and passed -L/usr/local/lib and -Wl, -rpath,/usr/local/lib. Voila! the compilation was complete. I build a test program to read and write videos. All worked ok. This was a rough sketch of the compilation solution. I will post the details of the CMakeCache.txt in case someone is interested.

22 June 2009

compilation of recent versions of opencv and ffmpeg

I downloaded a recent version of OpenCV from SVN. I also downloaded a recent SVN version of ffmpeg. This is an informal log of the installation “pains”. I have been using OpenCV since version 0.9.6 and my work fully relies on it. What follows is true for ffmpeg 0.5 also.

Short Version of how I did it

Install ffmpeg with ./configure –enable-shared. Then do ‘make’ & ‘make install’. Do ‘ldconfig’ after installation. check the ffmpeg version by ‘ffmpeg -version’. Note that ffmpeg dumps its header files in 5 header files like libavformat etc. Make a directory called ffmpeg under /usr/local/include., i.e., ‘mkdir /usr/local/include/ffmpeg’. Go to /usr/local/include. Copy ‘avcodec.h avformat.h avio.h avutil.h swscale.h’ from respective ‘lib’ directories to ffmpeg. I prefer sym-linking it.

Then download the latest SVN version of opencv from sourceforge. It is available as a tarball in case you do not feel inclined to run the SVN from command line. After gunzipping and untarring it, we get a directory called opencv. Change directory to opencv. Make the file ‘configure’ by doing ‘chmod +x configure’. Then do ‘./configure –without-1394libs –without-python –disable-apps’. These arguments disable 1394/Firewire libraries, python support and building of applications. I have not faced major limitations by disabling these. There should be a series of messages. Confirm that ffmpeg is recognised and will be used. This will be indicated by a line “Use ffmpeg: yes”. If this does not happen, go back to the step of ffmpeg installation. If you are sure that ffmpeg is installed correctly and you are able to see files in /usr/local/include/ffmpeg/, then one way of checking whether opencv finds the header files is that you search for the keyword ffmpeg in the output of ‘./configure’ typed exactly as previously. In other words, you do ‘./configure –without-1394libs –without-python –disable-apps | grep ffmpeg’. You should get the lines which confirm or deny the existence of the headers ‘ffmpeg/avcodec.h’ availability. If these headers are not found, then your linking or copying is not ok. If on the other hand, ffmpeg has been found, do ‘make’ and ‘make install’ and then ‘ldconfig’.

** For x86-64 users: the configure script has a peculiar tendency of identifying all intel CPUs as pentium4. if you run ‘make’ after ‘./configure’, then you will run into compilation errors saying that architecture specified cannot be compiled. Do not lose heart but open the config.status file and search for the word ‘pentium4′ in this file. You should get something like ‘-march=pentium4′ along with other options. Change ‘-march=pentium4′ to ‘-march=native’ or you can even delete the whole thing. If you have a recent version of gcc, you can enable openmp by adding ‘-fopenmp’ in the same line where you found the previous expression.

The above worked for me. I hope it does for you.