Para instalar OpenCV 2.4.2 con soporte ffmpeg tenemos que instalar primero lamemp3, faac, faad y por supuesto ffmpeg. He añadido un nuevo script en mi repositorio installation-scripts de Github pero voy a poner de todas formas aquí como se instala cada librería paso a paso.
Recuerda también que para poder compilar desde la linéa de comandos con Xcode 4.4 hay que instalar antes las “Command Line Tools”. Echa un vistazo a “No puedo configurar con cmake en Mac OS X 10.8 con Xcode 4.4” antes de continuar con la instalación.
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 (observar que solo se compila para 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.1.tar.gz tar xzvf ffmpeg-0.11.1.tar.gz cd ffmpeg-0.11.1 ./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
Si configuramos y compilamos OpenCV 2.4.2 tal cual nos aparecerá un error de linkado más o menos al 34% del proceso de compilación de esta manera:
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
Para resolver este problema tenemos que modificar el fichero modules/highgui/CMakeLists.txt
y añadir lo siguiente justo antes de if(HAVE_FFMPEG)
(en la línea 158):
if(APPLE) list(APPEND HIGHGUI_LIBRARIES ${BZIP2_LIBRARIES} -lmp3lame -lfaac -lbz2) endif(APPLE)
O podemos aplicar el siguiente parche a OpenCV 2.4.2:
--- modules/highgui/CMakeLists.txt.old 2012-06-19 19:17:35.000000000 +0200 +++ modules/highgui/CMakeLists.txt 2012-06-19 22:48:58.000000000 +0200 @@ -145,6 +145,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})
Ahora ya podemos configurar, compilar e instalar OpenCV como siempre. Si quieres saber más acerca de los parámetros de configuración de cmake
para OpenCV puedes echar un vistazo a “Instalar OpenCV 2.3.1a en Mac OS X 10.6“.
mkdir build cmake .. make sudo make install cd ..
Fuente: http://blog.yageek.net/2012/06/compile-opencv-241-on-mac-os-x-lion.html