opencv - 当我构建 OpenCV 时,它无法识别我安装的 ffmpeg
问题描述
我已经从https://pypi.org/project/opencv-python/下载了 OpenCV-python 源代码, 并试图在OpenSuse上构建它。
我已经安装了ffmpeg,如下所示,我希望使用这个安装的版本,而不是构建我自己的 ffmpeg:
/home/adminlinux/Downloads/build # ffmpeg -version
ffmpeg version 3.4.8 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 7 (SUSE Linux)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --incdir=/usr/include/ffmpeg
--extra-cflags='-fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g' --optflags='-fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g' --disable-htmlpages --enable-pic --disable-stripping --enable-shared --disable-static --enable-gpl --disable-openssl --enable-avresample --enable-libcdio --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libcelt --enable-libcdio --enable-libdc1394 --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libzimg --enable-libzvbi --enable-vaapi --enable-vdpau --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-version3 --enable-libx264 --enable-libx265 --enable-libxvid
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
当我使用以下 cmake 命令构建时:
cmake ../opencv-python-4.4.0.46/opencv/
我看到未检测到 FFMPEG:
Video I/O:
-- DC1394: NO
-- FFMPEG: NO
-- avcodec: NO
-- avformat: NO
-- avutil: NO
-- swscale: NO
-- avresample: NO
-- GStreamer: NO
-- v4l/v4l2: YES (linux/videodev2.h)
此链接表明我需要指出我的 ffmpeg 库在哪里: Configure and Build OpenCV to Custom FFMPEG Install
所以我尝试了以下标志,但仍然得到相同的输出:
cmake -DHAVE_FFMPEG=ON -DFFMPEG_LIBDIR="/usr/lib64" -DFFMPEG_INCLUDE_DIRS="/usr/lib64" ../opencv-python-4.4.0.46/opencv/
然后我尝试了以下标志(OPENCV_FFMPEG_SKIP_BUILD_CHECK 和 BUILD_SHARED_LIBS):
cmake -DHAVE_FFMPEG=ON -DFFMPEG_LIBDIR="/usr/lib64" -DFFMPEG_INCLUDE_DIRS="/usr/lib64" -D OPENCV_FFMPEG_SKIP_BUILD_CHECK=ON -D BUILD_SHARED_LIBS=OFF ../opencv-python-4.4.0.46/opencv/
这一次我注意到FFMPEG现在是开启的,但库是 NO:
Video I/O:
-- DC1394: NO
-- FFMPEG: YES
-- avcodec: NO
-- avformat: NO
-- avutil: NO
-- swscale: NO
-- avresample: NO
-- GStreamer: NO
-- v4l/v4l2: YES (linux/videodev2.h)
我还能做些什么来启用编解码器?在这个阶段,我在黑暗中刺伤。
编辑
我从https://opencv.org/opencv-4-4-0/下载了 open-cv(不是 opencv-python)的源代码
以下每个 cmake 命令都会产生相同的输出:
cmake ../opencv-4.4.0
cmake -DHAVE_FFMPEG=ON ../opencv-4.4.0
cmake -DHAVE_FFMPEG=ON -DWITH_FFMPEG=ON ../opencv-4.4.0
cmake -DHAVE_FFMPEG=ON -DWITH_FFMPEG=ON -DFFMPEG_LIBDIR="/usr/lib64/" ../opencv-4.4.0
cmake -DHAVE_FFMPEG=ON -DWITH_FFMPEG=ON -DFFMPEG_LIBDIR="/usr/lib64" -DFFMPEG_INCLUDE_DIRS="/usr/lib64/" ../opencv-4.4.0
结果:
Video I/O:
-- DC1394: NO
-- FFMPEG: NO
-- avcodec: NO
-- avformat: NO
-- avutil: NO
-- swscale: NO
-- avresample: NO
-- GStreamer: NO
-- v4l/v4l2: YES (linux/videodev2.h)
以及以下命令:
cmake -DHAVE_FFMPEG=ON -DWITH_FFMPEG=ON -DFFMPEG_LIBDIR="/usr/lib64" -DFFMPEG_INCLUDE_DIRS="/usr/lib64" -D OPENCV_FFMPEG_SKIP_BUILD_CHECK=ON ../opencv-4.4.0
cmake -DHAVE_FFMPEG=ON -DWITH_FFMPEG=ON -DFFMPEG_LIBDIR="/usr/lib64" -DFFMPEG_INCLUDE_DIRS="/usr/lib64" -D OPENCV_FFMPEG_SKIP_BUILD_CHECK=ON -D BUILD_SHARED_LIBS=OFF ../opencv-4.4.0
结果
Video I/O:
-- DC1394: NO
-- FFMPEG: YES
-- avcodec: NO
-- avformat: NO
-- avutil: NO
-- swscale: NO
-- avresample: NO
-- GStreamer: NO
-- v4l/v4l2: YES (linux/videodev2.h)
我需要/可以使用任何其他标志等吗?或者任何方式来调试为什么它没有检测到我的ffmpeg?
解决方案
OpenCV 通过检查 .pc 文件(用于 pkg-config)来查找 ffmpeg。如果您使用包管理器(例如 Ubuntu 上的 apt)安装了 ffmpeg 并且没有安装pkg-config
,请尝试sudo apt install pkg-config
重新安装 ffmepg sudo apt install ffmpeg
。这解决了我的问题。
推荐阅读
- reactjs - 如何在 reactjs 中集成 bootstrap 4 数据表?
- sendgrid - 我们可以限制电子邮件链接在 Sengrid 中编码吗?
- r - 如何将所有组设置为等于具有最小组长度(行数)的组?
- ios - 在 TableView 控制器中将视图显示为内部应用程序通知
- daml - 如何在 DAML 中为原始类型和记录指定默认值?
- python - 分组排除异常值的最有效方法是什么
- java - 需要解释 Java 中的行选择
- javascript - 从 vue 导入 {ref} 时出错?
- jquery - 使用jquery的Bootstrap Modal设置ID不起作用
- append - 函数中使用的全局变量是否需要在 def 块之前定义?