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
It helps a lot. Do you know how to utilize ffmpeg writing videos under XCode? I can’t make the VideoWriter work with the OpenCV 2.4.2. I hope you can help me out with this if you know the solution.
Sorry but I’ve never used ffmpeg to write videos. You should look at the oficial documentation for an example or something like that.
FFMPEG on MAC patch outlined above is still required for Open CV 2.4.3 as well.
GREAT STUFF!
Thanks for the tutorial .. I have successfully installed and have a working simple opencv videocapture application. The capture happens from a file, but I have been unsuccessfully in deploying this application onto a different computer the one without opencv or ffmpeg. More info the question here: http://stackoverflow.com/questions/15299691/opencv-ffmpeg-video-capture-filename-avi-crashes-on-a-non-development-machi
If it works in your development computer but does not in another computer it should be a problem in the libraries. You should try installing the exact same versions of OpenCV, ffmpeg and Qt in the other computer. I don’t know anything about otool and the deployment proccess of apps with it. Probably it’s a problem in the paths.
By the way, in your code you resize the image to 604×480 and I’m pretty sure you want to resize it to 640×480.
Hi enekochan,..Yes, if I install those libraries on the other system it works fine, its only when I try and package an application this happens. I have been going throught the app bundle for the last 8hours to make sure each of the dependency is correctly linked. Looks like a bug in the opencv ffmpeg, or the qt end.
And yes it was suppose to 640 x 480…thanks for pointing it out.
Hey thanks for the tutorial, I’ve been looking for something like this. I’m having a problem when i make faad.
ld: warning: ignoring file ../common/mp4ff/libmp4ff.a, file was built for archive which is not the architecture being linked (i386): ../common/mp4ff/libmp4ff.a
Undefined symbols for architecture i386:
“_main”, referenced from:
start in crt1.10.6.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
lipo: can’t open input file: /var/tmp//ccJylCwD.out (No such file or directory)
make[2]: *** [faad] Error 1
make[1]: *** [all-recursive] Error 1
Thanks,
Still usefull one year later
Thanks!
I can’t believe that the more “official” opencv web pages don’t mention any of this. One has to google to find such information.
You are a life saver man!
cheers