opencv无法读取视频
cv2无法读取视频,也不报任何错误,经检查,问题出在ffmpeg上
python3 -c 'import cv2; print(cv2.getBuildInformation())'
显示如下:
可以看到,ffmpeg相关的配置均为False
解决方法:手动编译opencv
# 第一步
sudo apt-get update
sudo apt-get install build-essential cmake git
sudo apt-get install libavcodec-dev libavformat-dev libavutil-dev libswscale-dev
sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev# 第二步
git clone https://github.com/opencv/opencv.git
cd opencv
git clone https://github.com/opencv/opencv_contrib.git# 第三步
mkdir build
cd build# 第四步
cmake -D CMAKE_BUILD_TYPE=Release \-D CMAKE_INSTALL_PREFIX=/usr/local \-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \-D WITH_FFMPEG=ON \-D WITH_GSTREAMER=ON \..# 第五步
make -j 8
make install# 第六步,验证安装
import cv2
print(cv2.getBuildInformation())
如果一切顺利, 会显示如下所示结果: