Tag Archives: 2.4.2

Install OpenCV 2.4.2 with ffmpeg support in Mac OS X 10.8

In order to install OpenCV 2.4.2 with ffmpeg support we have to first install lamemp3, faac, faad and of course ffmpeg. I’ve added a new script in my installation-scripts repository in Github but I’m going to write down here installing one by one all the libraries.

Also remember that you need to install the “Command Line Tools” in order to compile from the command line if you are using Xcode 4.4 or above. Have a look at “Can’t configure with cmake in Mac OS X 10.8” before continuing the installation process.

mp3lame:

$ curl -L -o lame-3.99.5.tar.gz http://sourceforge.net/projects/lame/files/lame/3.99/lame-3.99.5.tar.gz/download
$ tar xzvf lame-3.99.5.tar.gz
$ cd lame-3.99.5
$ ./configure --disable-dependency-tracking CFLAGS="-arch i386 -arch x86_64" LDFLAGS="-arch i386 -arch x86_64"
$ make
$ sudo make install
$ cd ..

faac (notice that only compiles for x86_64):

$ curl -L -o faac-1.28.tar.gz http://sourceforge.net/projects/faac/files/faac-src/faac-1.28/faac-1.28.tar.gz/download
$ tar xzvf faac-1.28.tar.gz
$ cd faac-1.28
$ ./configure --disable-dependency-tracking CFLAGS="-arch x86_64" LDFLAGS="-arch x86_64"
$ make
$ sudo make install
$ cd ..

faad:

$ curl -L -o faad2-2.7.tar.gz http://sourceforge.net/projects/faac/files/faad2-src/faad2-2.7/faad2-2.7.tar.gz/download
$ tar xvzf faad2-2.7.tar.gz
$ cd faad2-2.7
$ ./configure --disable-dependency-tracking CFLAGS="-arch i386 -arch x86_64" LDFLAGS="-arch i386 -arch x86_64"
$ make
$ sudo make install
$ cd ..

ffmpeg:

$ curl -O http://ffmpeg.org/releases/ffmpeg-0.11.5.tar.gz
$ tar xzvf ffmpeg-0.11.5.tar.gz
$ cd ffmpeg-0.11.5
$ ./configure --enable-libmp3lame --enable-libfaac --enable-nonfree --enable-shared --enable-pic --disable-mmx --arch=x86_64
$ make
$ sudo make install
$ cd ..

OpenCV 2.4.2:

$ curl -L -o OpenCV-2.4.2.tar.bz2 http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.2/OpenCV-2.4.2.tar.bz2/download
$ tar xvzf OpenCV-2.4.2.tar.bz2
$ cd OpenCV-2.4.2

If we configure and compile OpenCV 2.4.2 as it comes we will get a linker error at about 34% of the compilation process like this:

Linking CXX shared library ../../lib/libopencv_highgui.dylib
Undefined symbols for architecture x86_64:
  "_faacEncClose", referenced from:
      _Faac_encode_close in libavcodec.a(libfaac.o)
      _Faac_encode_init in libavcodec.a(libfaac.o)
  "_faacEncEncode", referenced from:
      _Faac_encode_frame in libavcodec.a(libfaac.o)
  "_faacEncGetCurrentConfiguration", referenced from:
      _Faac_encode_init in libavcodec.a(libfaac.o)
  "_faacEncGetDecoderSpecificInfo", referenced from:
      _Faac_encode_init in libavcodec.a(libfaac.o)
  "_faacEncOpen", referenced from:
      _Faac_encode_init in libavcodec.a(libfaac.o)
  "_faacEncSetConfiguration", referenced from:
      _Faac_encode_init in libavcodec.a(libfaac.o)
  "_lame_close", referenced from:
      _mp3lame_encode_close in libavcodec.a(libmp3lame.o)
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_encode_buffer", referenced from:
      _mp3lame_encode_frame in libavcodec.a(libmp3lame.o)
  "_lame_encode_buffer_float", referenced from:
      _mp3lame_encode_frame in libavcodec.a(libmp3lame.o)
  "_lame_encode_buffer_int", referenced from:
      _mp3lame_encode_frame in libavcodec.a(libmp3lame.o)
  "_lame_encode_buffer_interleaved", referenced from:
      _mp3lame_encode_frame in libavcodec.a(libmp3lame.o)
  "_lame_encode_flush", referenced from:
      _mp3lame_encode_frame in libavcodec.a(libmp3lame.o)
  "_lame_get_encoder_delay", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_get_framesize", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_init", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_init_params", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_set_VBR", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_set_VBR_quality", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_set_bWriteVbrTag", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_set_brate", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_set_disable_reservoir", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_set_in_samplerate", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_set_mode", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_set_num_channels", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_set_out_samplerate", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
  "_lame_set_quality", referenced from:
      _mp3lame_encode_init in libavcodec.a(libmp3lame.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib/libopencv_highgui.2.4.2.dylib] Error 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make: *** [all] Error 2

To solve this problem we have to change modules/highgui/CMakeLists.txt and add just before if(HAVE_FFMPEG) (on line 158) the following text:

if(APPLE)
  list(APPEND HIGHGUI_LIBRARIES ${BZIP2_LIBRARIES} -lmp3lame -lfaac -lbz2)
endif(APPLE)

Or we could apply this patch to OpenCV 2.4.2:

--- modules/highgui/CMakeLists.txt.old  2012-07-27 15:46:52.000000000 +0200
+++ modules/highgui/CMakeLists.txt      2012-07-27 15:47:05.000000000 +0200
@@ -155,6 +155,10 @@
   list(APPEND HIGHGUI_LIBRARIES m3api)
 endif(HAVE_XIMEA)
 
+if(APPLE)
+  list(APPEND HIGHGUI_LIBRARIES ${BZIP2_LIBRARIES} -lmp3lame -lfaac -lbz2)
+endif(APPLE)
+
 if(HAVE_FFMPEG)
   if(UNIX AND BZIP2_LIBRARIES)
     list(APPEND HIGHGUI_LIBRARIES ${BZIP2_LIBRARIES})

Now we can configure, compile and install it as usual. If you want to know more configuration options of cmake for OpenCV you can have a look at “Install OpenCV 2.3.1a in Mac OS X 10.6“.

$ mkdir build
$ cd build
$ cmake ..
$ make
$ sudo make install
$ cd ..

Source: http://blog.yageek.net/2012/06/compile-opencv-241-on-mac-os-x-lion.html