about opencv 2 video opening error in visualstudio 2012

asked 2014-10-22 14:47:56 -0500

ashish gravatar image

in this programme i want to open the videofile that is in d drive so, i have written below code: ---------------------------------

#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
VideoCapture cap("D://ashish.mp4");
if(!cap.isOpened())
{system("pause");
cout<<"error "<<endl;
return 0;
}
namedWindow("MyVideo",CV_WINDOW_AUTOSIZE);
while (1)
{
Mat frame;
bool bSuccess = cap.read(frame); // read a new frame from video
if (!bSuccess) //if not success, break loop
{
cout << "Cannot read a frame from video stream" << endl;
break;
}
imshow("MyVideo", frame); //show the frame in "MyVideo" window
if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
{
cout << "esc key is pressed by user" << endl;
break;
}
}
return 0;

}

i'm getting an warning : error opening file <../../modules/highgui/src/cap_ffmpeg_impl.hpp:545>

edit retag flag offensive close merge delete

Comments

Double check the path and extension of the video and also check that you have the right to open that video , also try to use it like VideoCapture cap("D:\\ashish.mp4"); use \\

FLY gravatar imageFLY ( 2014-10-22 15:30:38 -0500 )edit