Configure and Build OpenCV to Custom FFMPEG Install

前端 未结 4 1179
梦毁少年i
梦毁少年i 2021-02-05 16:37

I cannot seem to configure OpenCV to link to a non-/usr/lib set of FFMPEG libraries.

My LD_LIBRARY_PATH contains a direct link to the folder for the custom

4条回答
  •  梦谈多话
    2021-02-05 17:01

    For OpenCV 3.x and ffmpeg 3.x, I have to apply the following patch

    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.

提交回复
热议问题