Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

videocapture is not working in opencv 3.4.0

I have an .mp4 video saved in the path (D:\Personal\workspace\FirstVideo.mp4) and in the code when i call videocapture cap("filepath") it is returning false everytime and prints "cannot open the video file". Below is the code snippet. I have added the libopencv_videoio340 library in my eclipse c++ settings. Everytime when i run my code, it always prints "cannot open the video file", I have no clue now how to proceed o this. Can anyone help me on this? Thanks in advance!!!

//================================== //Code snippet //================================== #include <opencv2 opencv.hpp="">

include <opencv2 core="" core.hpp="">

include <opencv2 highgui="" highgui.hpp="">

include <iostream>

using namespace cv; using namespace std;

int main( int argc, char** argv) { //open the video file for reading VideoCapture cap("D:\Personal\workspace\FirstVideo.mp4");

if(cap.isOpened() == false)
{
    cout<<"cannot open the video file"<<endl;
    cin.get();
    return -1;
}

//get the frames rate of the video
double fps = cap.get(CAP_PROP_FPS);
cout << "Frames per seconds : " << fps << endl;

// Create a window for display.
namedWindow( "First Test Video", WINDOW_AUTOSIZE );

while (true)
{
 Mat frame;
 bool bSuccess = cap.read(frame); // read a new frame from video

 //Breaking the while loop at the end of the video
 if (bSuccess == false)
 {
  cout << "Found the end of the video" << endl;
  break;
 }
 imshow( "First Test Video", frame );
 waitKey(0);
}

return 0; }

click to hide/show revision 2
None

updated 2018-02-14 09:57:25 -0600

berak gravatar image

videocapture is not working in opencv 3.4.0

I have an .mp4 video saved in the path (D:\Personal\workspace\FirstVideo.mp4) and in the code when i call videocapture cap("filepath") it is returning false everytime and prints "cannot open the video file". Below is the code snippet. I have added the libopencv_videoio340 library in my eclipse c++ settings. Everytime when i run my code, it always prints "cannot open the video file", I have no clue now how to proceed o this. Can anyone help me on this? Thanks in advance!!!

//==================================
//Code snippet
//==================================
 #include <opencv2 opencv.hpp=""> 

include <opencv2 core="" core.hpp="">

include <opencv2 highgui="" highgui.hpp="">

include <iostream>

<opencv2/opencv.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace cv; using namespace std;

std; int main( int argc, char** argv) { //open the video file for reading VideoCapture cap("D:\Personal\workspace\FirstVideo.mp4");

cap("D:\\Personal\\workspace\\FirstVideo.mp4");

    if(cap.isOpened() == false)
 {
     cout<<"cannot open the video file"<<endl;
     cin.get();
     return -1;
 }

 //get the frames rate of the video
 double fps = cap.get(CAP_PROP_FPS);
 cout << "Frames per seconds : " << fps << endl;

 // Create a window for display.
 namedWindow( "First Test Video", WINDOW_AUTOSIZE );

 while (true)
 {
  Mat frame;
  bool bSuccess = cap.read(frame); // read a new frame from video

  //Breaking the while loop at the end of the video
  if (bSuccess == false)
  {
   cout << "Found the end of the video" << endl;
   break;
  }
  imshow( "First Test Video", frame );
  waitKey(0);
    }
   return 0;
}

return 0; }