第一步,先安装ffmpeg
按该网页https://trac.ffmpeg.org/wiki/CompilationGuide/Centos一步步安装
仅其中git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git 地址无效
换https://github.com/webmproject/libvpx/releases 地址下载了libvpx-1.7.0.tar.gz
make时报错信息如下
third_party/libyuv/source/row_gcc.cc:831: Error: suffix or operands invalid for vpmaddubsw'
third_party/libyuv/source/row_gcc.cc:832: Error: suffix or operands invalid forvpmaddubsw’
third_party/libyuv/source/row_gcc.cc:833: Error: suffix or operands invalid for vpmaddubsw'
third_party/libyuv/source/row_gcc.cc:834: Error: suffix or operands invalid forvpmaddubsw’
third_party/libyuv/source/row_gcc.cc:836: Error: suffix or operands invalid for vphaddw'
third_party/libyuv/source/row_gcc.cc:837: Error: suffix or operands invalid forvphaddw’
…..
third_party/libyuv/source/row_gcc.cc:5321: Error: no such instruction: `vpermq $0xd8,%ymm0,%ymm0’
make[1]: * [third_party/libyuv/source/row_gcc.cc.o] Error 1
make: * [.DEFAULT] Error 2
按该博客方法https://blog.csdn.net/happybird100/article/details/50707026禁用avx2可解
摘录——“https://blog.csdn.net/happybird100/article/details/50707026
经过一番谷歌,找到一段话:
As a workaround if your hardware does not support avx2 (grep avx2
/proc/cpuinfo) you can disable it with –disable-avx2
也就是说,我的系统可能不支持avx2这个东东,grep avx2
/proc/cpuinfo果然没有, avx2是一个指令集,支持更多位数的浮点数运算,因此视频解码上更好 效率更高。但是系统不支持,所以得编译一个不包含avx2的VP8/VP9编解码库则可,最后用以下命令编译通过:
libvpx-v1.3.0.tar.bz2
./configure –enable-shared –disable-avx2
make && make install”
我的命令./configure --prefix="/usr/local/ffmpeg_build" --disable-avx2 --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm
安装完ffmpeg之后,配置环境变量:
echo $PKG_CONFIG_PATH 居然为空
export PKG_CONFIG_PATH=/usr/local/ffmpeg_build/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig
export PATH=$PATH:/usr/local/ffmpeg_build/bin
或者:vi /etc/profile
export PKG_CONFIG_PATH=/usr/local/ffmpeg_build/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig
export PATH=$PATH:/usr/local/ffmpeg_build/bin
export LD_LIBRARY_PATH="/usr/local/ffmpeg_build/lib"
source /etc/profile
进一步,把ffmpeg的库加入/etc/ld.so.conf中
cd /etc/ld.so.conf.d/
vi ffmpeg.conf
/usr/local/ffmpeg_build/lib
ldconfig
第二步: 编译opencv3.4.6 opencv_contrib3.4.6
https://github.com/opencv/opencv 下载opencv与opencv_contrib,版本必须相同
https://github.com/opencv/opencv/releases/tag/3.4.6
https://github.com/opencv/opencv_contrib/releases/tag/3.4.6
tar -zxvf /home/jello/Downloads/opencv-3.4.6.tar.gz -C /usr/local/
tar -zxvf /home/jello/Downloads/opencv_contrib-3.4.6.tar.gz -C /usr/local/
安装依赖项yum install cmake gcc gcc-c++ gtk+-devel gimp-devel gimp-devel-tools gimp-help-browser zlib-devel libjpeg-devel libpng-devel gstreamer-devel libavc1394-devel libraw1394-devel libdc1394-devel jasper-devel jasper-utils swig python libtool nasm
cd /usr/local/opencv-3.4.6
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_FFMPEG=ON -D OPENCV_EXTRA_MODULES_PATH=/usr/local/opencv_contrib-3.4.6/modules ..
make
make install
cmake若有相关错误可参考https://blog.csdn.net/lj402159806/article/details/84975294
我之前安装依赖项时装了libtiff-devel,cmake报错如下
grfmt_tiff.cpp:132:12: error: 'tmsize_t' does not name a type
grfmt_tiff.cpp:213:86: error: 'read' is not a member of 'cv::TiffDecoderBufHelper'
按上面博客方法yum remove libtiff-devel后重新编译成功
cmake成功后能看到ffmpeg为YES
Video I/O:
-- DC1394: YES (ver 2.1.2)
-- FFMPEG: YES
-- avcodec: YES (ver 58.53.101)
-- avformat: YES (ver 58.28.102)
-- avutil: YES (ver 56.30.100)
-- swscale: YES (ver 5.4.101)
-- avresample: NO
-- GStreamer: NO
补记:之前安装opencv3.2.0时,遇到了安装了各种版本和各种方式的ffmpeg, 并且配置好了PKG_CONFIG_PATH等环境变量,opencv3.2.0的cmake后ffmpeg始终为NO的情况,这是opencv3.2.0的源码bug,按下面博客方式解决
http://www.opencv.org.cn/forum.php?mod=viewthread&tid=264912
要在 /usr/local/include/libavutil/common.h 前边加上一行
#ifndef UINT64_C
#define UINT64_C(value) __CONCAT(value, ULL)
#endif
原因不理解,但是确实有效!
第三步: 最后按照自己2018/07/17博客安装配置qt即可。
在ldconfig配置动态链接库时遇到如下问题:
ldconfig: /usr/local/lib/libstdc++.so.6.0.18-gdb.py is not an ELF file - it has the wrong magic bytes at the start.
网搜直接删除该文件,是可解决,为预防,做了备份
mv /usr/local/lib/libstdc++.so.6.0.18-gdb.py /home/jello/libstdc++.so.6.0.18.gdb.py.bak