opencv C++处理视频文件时遇到的问题
前言
opencv C++处理视频文件时遇到的问题简单记录
一、opencv 安装
1.下载opencv 4.5.1
git clone https://github.com/opencv/opencv
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D WITH_FFMPEG=ON -D OPENCV_GENERATE_PKGCONFIG=ON ..
make -j5
make install
2.下载ffmpg ffmpeg-4.4.3
官网: http://www.ffmpeg.org/
tar -zxvf ffmpeg-4.4.3.tar.gz
./configure --enable-shared --enable-avresample --prefix=/usr/
make -j$(nproc)
sudo make install
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar zxvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure
make && make install
二、问题解决
1.OpenCV编译的时候 ffmpeg库找不到
解决思路:库找不到,添加相关库路径即可。
find / -name libavutil*.so
vim /etc/ld.so.conf #将找到的路径添加后面,例如:/usr/lib
ldconfig
export PKG_CONFIG_PATH=/usr/lib/pkgconfig:$PKG_CONFIG_PATH
cmake -D CMAKE_BUILD_TYPE=RELEASE -D WITH_FFMPEG=ON -D OPENCV_GENERATE_PKGCONFIG=ON ..
make -j5
make install
三、 应用
const std::string source = "video1.mp4";
Mat frame;
VideoCapture capture(source);
int fps = capture.get(7);
std::cout << "1: " << fps << std::endl;
if(!capture.isOpened()) {
printf("can not open ...\n");
return -1;
}
while (capture.read(frame) {
// imshow("output", frame);
// waitKey(10);
totalFrameNumber++;
}
一切正常。