0

I am compiling on Ubuntu 14.04 using OpenCV 3.1. When trying to open a video file it gives this error:

"Cannot open the video file"

I installed everything i could install : ffmpeg etc. Haven't found a solution checking out similar questions on StackOF.

What do ?

cv::VideoCapture cap(argv[1]);

Where argv[1] is the file name in the same directory as the executable.

edd
  • 21
  • 1
  • 6

1 Answers1

0

In case your constructor is failing, you may want to use the .open() method. So, if you want to open a file that is called "myVideo.mp4" that is in the folder of your project, you would do the following:

cv::VideoCapture cap;
cap.open("myVideo.mp4"); 

For more detailed informations about this method, check this documentation link Also, the book Learning OpenCV 3, from the O'Rilley media, on page 26 gives you a good example. Here is a Gist that I made to give you as an example.

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

int main() {
  cv::VideoCapture cap;
  cap.open("myVideo.mp4" );
  cv::namedWindow( "myVideo", cv::WINDOW_AUTOSIZE );
  cv::Mat frame;
  while(true) {
    cap >> frame;
    if( frame.empty() ){
      std::cout << "Could not load the video frames. \n";
      break;
    }
    cv::imshow( "myVideo", frame );
    if( cv::waitKey(27) >= 0 ){
      std::cout << "Escape pressed \n";
      break;
    }
  }
  return 0; 
}