1. 编译安装ffmpeg
下载源码,执行 ./configure --disable-yasm --enbale-shared --prefix=/usr/local/ffmpeg 即可。
2. 下载opencv并设置config
下载源码,并 git checkout 3.1.0,也可以是其他版本
cmake -D WITH_CUDA=OFF -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/home/packages/opencv/install -D WITH_IPP=OFF -D WITH_FFMPEG=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D INSTALL_PYTHON_EXAMPLES=OFF -D INSTALL_C_EXAMPLES=OFF -D PYTHON_EXECUTABLE=$(which python) -D BUILD_EXAMPLES=OFF ..
注意:
(1) 需要指定ffmpeg安装目录便于cmake找到, 否则会出现lib库找不到的问题,使得始终 FFMPEG:NO
https://blog.csdn.net/yangzhenzhen/article/details/62417021
export PKG_CONFIG_PATH=/home/packages/ffmpeg/lib/pkgconfig;$PKG_CONFIG_PATH
(2)设置ffmpeg的include路径到 bashrc文件中,并在ffmpeg/include目录下创建ffmpeg文件夹,将所有头文件拷到ffmpeg下,注意是拷贝文件不是文件夹。
(3)修改opencv中 modules/videoio/src/cap_ffmpeg_impl.hpp 代码,在最顶端添加宏定义
https://blog.csdn.net/guo_lei_lamant/article/details/81568346
#define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22) #define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER #define AVFMT_RAWPICTURE 0x0020
否则会出现以下错误
error: ‘CODEC_FLAG_GLOBAL_HEADER’ was not declared in this scope error: ‘AVFMT_RAWPICTURE’ was not declared in this scope error: ‘CODEC_FLAG_GLOBAL_HEADER’ was not declared in this scope for target ‘modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.cpp.o‘ failed make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.cpp.o] Error 1
原文地址:https://www.cnblogs.com/haiyang21/p/11029303.html
时间: 2024-10-02 10:31:13