Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to find FFMPEG (4) on Mac now that brew defaults to FFMPEG 5 #21600

Closed
stottle opened this issue Feb 11, 2022 · 5 comments
Closed

Fails to find FFMPEG (4) on Mac now that brew defaults to FFMPEG 5 #21600

stottle opened this issue Feb 11, 2022 · 5 comments

Comments

@stottle
Copy link

stottle commented Feb 11, 2022

System information (version)
  • OpenCV => 4.5.5
  • Operating System / Platform => macOS Big Sur
  • Compiler => Xcode
Detailed description

I was successfully building OpenCV from source with Xcode earlier. However, I did a brew update which replaced ffmpeg (4.4.1) with ffmpeg (5), which is now the default https://formulae.brew.sh/formula/ffmpeg. I see that ffmpeg 5 is not supported, but when I uninstall ffmpeg (5) and brew install ffmpeg@4, the OpenCV cmake setup is failing to find ffmpeg.

Steps to reproduce
With ffmpeg in path and the following command

cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Release -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_DOCS=OFF -DWITH_CUDA=OFF -DBUILD_EXAMPLES=OFF -DOPENCV_EXTRA_MODULES_PATH=<path>/opencv_contrib/modules -DBUILD_opencv_world=ON -DBUILD_opencv_java=OFF -DBUILD_opencv_python=OFF -DWITH_FFMPEG=ON -DWITH_QT=ON -DWITH_OPENGL=ON -DQT5_DIR=<path>/lib/cmake/Qt5 -DBUILD_opencv_cvv=OFF -DWITH_PROTOBUFF=ON -DBUILD_PROTOBUF=OFF -DPROTOBUF_UPDATE_FILES=ON ..

With old brew install of ffmpeg (4, before ffmpeg5 was the default):  FFMPEG detected and build succeeds
With new brew install of ffmpeg (5, now that it is the default):  FFMPEG detected but build fails
With brew install of ffmpeg@4 (requested specifically from brew):  FFMPEG not detected
Issue submission checklist
  • [ x] I report the issue, it's not a question
  • [x ] I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found any solution
  • [x ] I updated to the latest OpenCV version and the issue is still there
  • [ x] There is reproducer code and related data files: videos, images, onnx, etc
@stottle
Copy link
Author

stottle commented Feb 12, 2022

@alalek Why did you label this incomplete? I can't easily add more information if I don't know what is missing

@alalek
Copy link
Member

alalek commented Feb 12, 2022

With new brew install of ffmpeg (5, now that it is the default): FFMPEG detected but build fails

There are already tickets about FFmpeg 5 build issues: #21455 #20147


With brew install of ffmpeg@4 (requested specifically from brew): FFMPEG not detected

Build logs related to FFmpeg detection are necessary (look for av* libraries). Between switching of dependencies versions ensure to reset CMake cache or clean build directory.
Looks like there is some incompatibility in homebrew (because case1 works). Not sure how this problem could be resolved in OpenCV.

@stottle
Copy link
Author

stottle commented Feb 12, 2022

I was able, after digging into the pkg-config processing of cmake itself, to figure out how to tell OpenCV's cmake scripts how to find ffmpeg. I needed to add -D CMAKE_PREFIX_PATH=/usr/local/Cellar/ffmpeg@4/4.4.1 to the cmake options.

The logs (even with --debug-find) didn't help, as they simply said the required libraries were missing until the right place to search for the library .pc files was given to cmake.

@stottle stottle closed this as completed Feb 12, 2022
@alalek
Copy link
Member

alalek commented Feb 12, 2022

By default OpenCV uses pkg-config for FFmpeg detection.

Check pkg-config --list-all / pkg-config --path libavutil

with and without export PKG_CONFIG_PATH=/usr/local/Cellar/<path to ffmpeg@4 .pc files>


-D CMAKE_PREFIX_PATH=/usr/local/Cellar/ffmpeg@4/4.4.1

Consider using FFMPEG_DIR or similar variable to avoid side-effects.

CMake's find_package(FFMPEG) could be forces by OPENCV_FFMPEG_USE_FIND_PACKAGE=ON variable.

@stottle
Copy link
Author

stottle commented Feb 12, 2022

I was unable to find any alternative other than -D CMAKE_PREFIX_PATH=/usr/local/Cellar/ffmpeg@4/4.4.1.

Exporting PKG_CONFIG_PATH will help on the command line/shell when running pkg-config. It only returned libavutil when I manually added the path to that environment variable. However, cmake ignores that variable, instead creating its own list of paths to check (see macro(_pkg_set_path_internal) in /usr/local/Cellar/cmake/3.21.3/share/cmake/Modules/FindPkgConfig.cmake (path from my system). CMAKE_PREFIX_PATH is what allows cmake's search paths to be extended, not PKG_CONFIG_PATH.

I don't believe OPENCV_FFMPEG_USE_FIND_PACKAGE=ON or setting FFMPEG_DIR help, those rely on find_package() IIUC, which in turn requires a file FFMPEGConfig.cmake to exist somewhere, which FFMPEG (at least 4.4.1) doesn't provide. Am I wrong about this? I'd like to know if there is a better option that doesn't have potential side effects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants