I cannot seem to configure OpenCV to link to a non-/usr/lib set of FFMPEG
libraries.
我似乎无法将OpenCV配置为链接到非/ usr / lib集的FFMPEG库。
My LD_LIBRARY_PATH contains a direct link to the folder for the custom install of FFMPEG:
我的LD_LIBRARY_PATH包含指向自定义安装FFMPEG的文件夹的直接链接:
LD_LIBRARY_PATH=/pathto/ffmpeg-0.10.2/lib
Additionally, I've configured pkgconfig as:
另外,我已将pkgconfig配置为:
PKG_CONFIG_PATH=/samepathto/ffmpeg-0.10.2/lib/pkgconfig/
Within CMake however I cannot find any setting for path to FFMPEG - either in basic or custom. The only setting related to FFMPEG appears to be WITH_FFMPEG
type setting (set to ON).
但是在CMake中,我无法找到FFMPEG路径的任何设置 - 无论是基本还是自定义。与FFMPEG相关的唯一设置似乎是WITH_FFMPEG类型设置(设置为ON)。
I can build OpenCV but it seems to link to the system libraries for libavcodec - this causes a conflict as the system libraries are version .52 and the version in my install of FFMPEG
are .53. Linking an app on a machine without the same system libraries seems to NOT link to my custom install of OpenCV (specifically the libavcodec) because of this (I'm installing these libraries on a shared network folder).
我可以构建OpenCV,但它似乎链接到libavcodec的系统库 - 这会导致冲突,因为系统库是版本.52,我安装的FFMPEG中的版本是.53。在没有相同系统库的机器上链接应用程序似乎没有链接到我的自定义安装的OpenCV(特别是libavcodec),因为这(我在共享网络文件夹上安装这些库)。
I am not sure if my problem is with building and linking to the wrong version of FFMPEG or if it is something with my environment after building (and then linking to the wrong ffmpeg).
我不确定我的问题是建立和链接到错误版本的FFMPEG,或者是否在构建之后与我的环境有关(然后链接到错误的ffmpeg)。
I am building on Linux, Redhat 6, OpenCV 2.3.1.
我在Linux,Redhat 6,OpenCV 2.3.1上构建。
2 个解决方案
#1
10
Something like
export LD_LIBRARY_PATH=/ffmpeg_install_path/lib/
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/ffmpeg_install_path/lib/pkgconfig
export PKG_CONFIG_LIBDIR=$PKG_CONFIG_LIBDIR:/ffmpeg_install_path/lib/
should work. At least it works for OpenCV 2.4.x on my Ubuntu.
应该管用。至少它适用于我的Ubuntu上的OpenCV 2.4.x.
#2
1
For OpenCV 3.x and ffmpeg 3.x, I have to apply the following patch
对于OpenCV 3.x和ffmpeg 3.x,我必须应用以下补丁
diff --git a/cmake/OpenCVFindLibsVideo.cmake b/cmake/OpenCVFindLibsVideo.cmake
index 13b62ac..bab9df3 100644
--- a/cmake/OpenCVFindLibsVideo.cmake
+++ b/cmake/OpenCVFindLibsVideo.cmake
@@ -228,6 +228,12 @@ if(WITH_FFMPEG)
if(FFMPEG_libavresample_FOUND)
ocv_append_build_options(FFMPEG FFMPEG_libavresample)
endif()
+ CHECK_MODULE(libavcodec HAVE_FFMPEG)
+ CHECK_MODULE(libavformat HAVE_FFMPEG)
+ CHECK_MODULE(libavutil HAVE_FFMPEG)
+ CHECK_MODULE(libswscale HAVE_FFMPEG)
+ CHECK_MODULE(libswresample HAVE_FFMPEG)
+ CHECK_MODULE(libavresample HAVE_FFMPEG)
if(HAVE_FFMPEG)
try_compile(__VALID_FFMPEG
"${OpenCV_BINARY_DIR}"
And with the following script to build
并使用以下脚本来构建
#!/bin/bash
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/Applications/ffmpeg/lib
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$HOME/Applications/ffmpeg/lib/pkgconfig
export PKG_CONFIG_LIBDIR=$PKG_CONFIG_LIBDIR:$HOME/Applications/ffmpeg/lib
cmake \
-D BUILD_EXAMPLES=ON \
-D BUILD_TESTS=OFF \
-D OPENCV_EXTRA_EXE_LINKER_FLAGS="-Wl,-rpath,$HOME/Applications/ffmpeg/lib" \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=$HOME/Applications/opencv \
/path/to/opencv
Also, when build ffmpeg, I have to enable flags --enable-avresample
.
另外,当构建ffmpeg时,我必须启用标志--enable-avresample。
#1
10
Something like
export LD_LIBRARY_PATH=/ffmpeg_install_path/lib/
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/ffmpeg_install_path/lib/pkgconfig
export PKG_CONFIG_LIBDIR=$PKG_CONFIG_LIBDIR:/ffmpeg_install_path/lib/
should work. At least it works for OpenCV 2.4.x on my Ubuntu.
应该管用。至少它适用于我的Ubuntu上的OpenCV 2.4.x.
#2
1
For OpenCV 3.x and ffmpeg 3.x, I have to apply the following patch
对于OpenCV 3.x和ffmpeg 3.x,我必须应用以下补丁
diff --git a/cmake/OpenCVFindLibsVideo.cmake b/cmake/OpenCVFindLibsVideo.cmake
index 13b62ac..bab9df3 100644
--- a/cmake/OpenCVFindLibsVideo.cmake
+++ b/cmake/OpenCVFindLibsVideo.cmake
@@ -228,6 +228,12 @@ if(WITH_FFMPEG)
if(FFMPEG_libavresample_FOUND)
ocv_append_build_options(FFMPEG FFMPEG_libavresample)
endif()
+ CHECK_MODULE(libavcodec HAVE_FFMPEG)
+ CHECK_MODULE(libavformat HAVE_FFMPEG)
+ CHECK_MODULE(libavutil HAVE_FFMPEG)
+ CHECK_MODULE(libswscale HAVE_FFMPEG)
+ CHECK_MODULE(libswresample HAVE_FFMPEG)
+ CHECK_MODULE(libavresample HAVE_FFMPEG)
if(HAVE_FFMPEG)
try_compile(__VALID_FFMPEG
"${OpenCV_BINARY_DIR}"
And with the following script to build
并使用以下脚本来构建
#!/bin/bash
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/Applications/ffmpeg/lib
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$HOME/Applications/ffmpeg/lib/pkgconfig
export PKG_CONFIG_LIBDIR=$PKG_CONFIG_LIBDIR:$HOME/Applications/ffmpeg/lib
cmake \
-D BUILD_EXAMPLES=ON \
-D BUILD_TESTS=OFF \
-D OPENCV_EXTRA_EXE_LINKER_FLAGS="-Wl,-rpath,$HOME/Applications/ffmpeg/lib" \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=$HOME/Applications/opencv \
/path/to/opencv
Also, when build ffmpeg, I have to enable flags --enable-avresample
.
另外,当构建ffmpeg时,我必须启用标志--enable-avresample。