第一步,先安裝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
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