videocapture is not working in opencv 3.4.0

asked 2018-02-14 09:48:24 -0600

inn@nav8 gravatar image

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

berak gravatar image

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;
}
edit retag flag offensive close merge delete

Comments

make sure opencv_ffmpeg340.dll is on the PATH (since all video file functionality is taken from there)

berak gravatar imageberak ( 2018-02-14 09:58:42 -0600 )edit

I found this lib in the path (D:\Personal\opencv_3.4\opencv\build\bin\opencv_ffmpeg340.dll) Shall i add this lib from the above path into eclipse (project->properties->C++ Settings->C++ Linker->Libraries)

inn@nav8 gravatar imageinn@nav8 ( 2018-02-14 10:12:20 -0600 )edit

no, add the containing folder to the system's environment PATH variable

(your ide is entirely irrelevant here)

berak gravatar imageberak ( 2018-02-14 10:17:35 -0600 )edit

I added this into my system PATH variable. No Progress, still videocapture cap() is returning false and printing "cannot open the video file"

inn@nav8 gravatar imageinn@nav8 ( 2018-02-14 10:25:40 -0600 )edit

check again 32 / 64 bit

berak gravatar imageberak ( 2018-02-14 10:37:14 -0600 )edit

Yes i checked it again, it's added in the PATH variable. It is 64 bit. Can you confirm the ffmpeg lib path (D:\Personal\opencv_3.4\opencv\build\bin\opencv_ffmpeg340.dll), is this what i should refer to the path or is there any other path where i can found ffmpeg lib?

inn@nav8 gravatar imageinn@nav8 ( 2018-02-14 10:43:48 -0600 )edit

opencv_ffmpeg340_64.dll , then.

and, you'll probably have to restart your shell / ide , after changing env vars.

berak gravatar imageberak ( 2018-02-14 11:29:00 -0600 )edit

I tried restarting my system too, videocapture is still not working :(

inn@nav8 gravatar imageinn@nav8 ( 2018-02-15 01:16:57 -0600 )edit

Can anyone help me in resolving the issue?

inn@nav8 gravatar imageinn@nav8 ( 2018-02-15 08:22:11 -0600 )edit

@inn@nav8. R u running visual studio c++?

supra56 gravatar imagesupra56 ( 2018-02-15 22:03:40 -0600 )edit