简体   繁体   中英

Can't open .mp4 with cv::VideoCapture

I'm trying to run the following simple code

# cat VideoCaptureTest.cpp
#include <cstdlib>
#include <string>
#include <iostream>
#include <opencv2/videoio.hpp>

using namespace std;
int main(int argc, char** argv) {
  string input("/root/OpenCVTest/720p.mp4");
  cv::VideoCapture capture(input);
  if (!capture.isOpened()) {
    cout << "Failed to open " << input << endl;
    exit (1);
  }

  return 0;
}

It gets compiled successfully with

# g++ -ggdb VideoCaptureTest.cpp -lopencv_videoio -o VideoCaptureTest

but VideoCaptureTest couldn't open the specified .mp4 file though the file exists and could be inferred by ffmpeg -i /root/OpenCVTest/720p.mp4

# ./VideoCaptureTest
Failed to open /root/OpenCVTest/720p.mp4

I have compiled OpenCV with

cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \
-D BUILD_EXAMPLES=ON \
-D WITH_QT=OFF \
-D WITH_V4L=ON \
-D CMAKE_SHARED_LINKER_FILES=-wl,-Bsymbolic \
-D WITH_FFMPEG=1 \
-D WITH_CUDA=ON \
-D CUDA_GENERATION=Turing \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D WITH_CUBLAS=1 \
-D WITH_LAPACK=OFF \
-D BUILD_opencv_python2=OFF ..

could verify install using

# pkg-config --modversion opencv4
4.5.3

I'm running it on nvidia/cuda:10.0-devel-ubuntu18.04 docker container on an Ubuntu 20.04 GCP VM with a T4 GPU. It doesn't have any graphical environment.

https://github.com/justadudewhohacks/opencv4nodejs/issues/274 fixed the issue. I need to

apt install libavcodec-dev libavformat-dev libavutil-dev  libswscale-dev libavresample-dev

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM