opencv: Building Opencv with ffmpeg built from source gives linking errors
Hi, I’m trying build opencv to used it on ASW Lambda. Opencv is going to be uploaded as a zip file so I’m doing a static build with BUILD_SHARED_LIBS=OFF. I set up WITH_FFMPEG=YES as i will process some video files. I didn’t want to install ffmpeg with apt-get as I want to have control on where my libraries are installed. I’ve downloaded ffmpeg and installed it from source to get the libavcodec, libavformat, libavutil and libswscale. I installed it as follow:
./configure --prefix=ffmpeg_build --disable-yasm --enable-shared --cc="gcc -fPIC"
I also did:
export LD_LIBRARY_PATH=/path/ffmpeg/ffmpeg_build/lib
export PKG_CONFIG_PATH=/path/ffmpeg/ffmpeg_build/lib/pkgconfig
I can see ffmpeg was well installed by running ./ffmpeg:
ffmpeg version N-77722-g3ec5d8f Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
configuration: --prefix=ffmpeg_build --disable-yasm --enable-shared --cc='gcc -fPIC'
libavutil 55. 12.100 / 55. 12.100
libavcodec 57. 22.100 / 57. 22.100
libavformat 57. 21.101 / 57. 21.101
libavdevice 57. 0.100 / 57. 0.100
libavfilter 6. 23.100 / 6. 23.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
Now I’m trying to build opencv and link ffmpeg but it looks like it can’t find it. Using the cmake UI i can even specify the path of the libraries as follow.
FFMPEG_CODEC_LIB /home/ubuntu/test_lambda/ffmpeg/ffmpeg_build/lib/libavcodec.so.57
FFMPEG_FORCE_TCP ON
FFMPEG_FORMAT_LIB /home/ubuntu/test_lambda/ffmpeg/ffmpeg_build/lib/libavformat.so.57
FFMPEG_INCLUDE_DIR /home/ubuntu/test_lambda/ffmpeg/ffmpeg_build/include
FFMPEG_LIB_DIR /home/ubuntu/test_lambda/ffmpeg/ffmpeg_build/include/../lib
FFMPEG_SWSCALE_LIB /home/ubuntu/test_lambda/ffmpeg/ffmpeg_build/lib/libswscale.so.4
FFMPEG_UTIL_LIB /home/ubuntu/test_lambda/ffmpeg/ffmpeg_build/lib/libavutil.so.55
But running the cmake command give the following:
Video I/O:
-- DC1394 1.x: NO
-- DC1394 2.x: NO
-- FFMPEG: YES
-- codec: NO
-- format: NO
-- util: NO
-- swscale: NO
Then if i still try to use make i get:
Linking CXX shared library ../../lib/libopencv_photo.so
In file included from /home/ubuntu/test_lambda/rb-opencv/modules/highgui/src/cap_ffmpeg.cpp:45:0:
/home/ubuntu/test_lambda/rb-opencv/modules/highgui/src/cap_ffmpeg_impl.hpp:71:6: error: #error "libswscale is necessary to build the newer OpenCV ffmpeg wrapper"
OpenCV can’t find my libavcodec etc… and I have no clue how to fix that. I don’t understand why it can’t find with all the steps I have done before. Any ideas? Thanks for your help.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 28 (13 by maintainers)
Just to add a solution because i ran throught the same problem of libswscale not being detected whereas it was installed on its latest version.
Problem is that cmake use
pkg-config
to check for modules presents and pkg-config does not know of all the package present in your system but only those which were compiled with pkg-config flagscc
pkg-config --cflags --libs x
-o myapp myapp.c (sorry for bad markdown but there are actually backquotes that surround pkg-config --cflags --libs xfrom freedesktop page
when typing
pkg-config --list-all
no libswscale was showing up. But you can easily add packages or libraries already present in your system to pkg-config. You just have to create a file called <package_name>.pc in /usr/share/pkgconfig/ directory and fill it with correct fields.So to add libswscale to pkg-config list, just do the following
it should now compile with ffmpeg support.
Thanks for opening up this issue. I have the same problem and due to academic stuffs, I need to stay with 2.4.11. So how do I build it on this version without moving on to OpenCV 3? (My project won’t involve video at all)
Thanks.
I fixed the problem with OpenCV 3. you were right about not using the cake UI! Some flags were wrong.
I’ve built opencv 3 without ffmpeg see if i can use the new motion jpeg codec but it can’t open a video capture.