Unable to play a video in opencv3

asked 2017-08-23 00:06:43 -0600

Sowmya Shree gravatar image

updated 2017-08-23 00:07:08 -0600

Here is my new code.

int main(void) {

cv::VideoCapture capVideo;

cv::Mat imgFrame;

capVideo.open("C:\Users\sbv\Documents\MyVideo.avi");

if (!capVideo.isOpened()) {
std::cout << "\nerror reading video file" << std::endl << std::endl;
_getch();
return(0); }

if (capVideo.get(CV_CAP_PROP_FRAME_COUNT) < 1) { std::cout << "\nerror: video file must have at least one frame"; _getch(); return(0); }

capVideo.read(imgFrame);

char chCheckForEscKey = 0;

while (capVideo.isOpened() && chCheckForEscKey != 27) {

cv::imshow("imgFrame", imgFrame);

if ((capVideo.get(CV_CAP_PROP_POS_FRAMES) + 1) < capVideo.get(CV_CAP_PROP_FRAME_COUNT)) 
        {
        capVideo.read(imgFrame);                          
}
else 
        {
         std::cout << "end of video\n";
         break;                                              
}

chCheckForEscKey = cv::waitKey(1);      
    }

if (chCheckForEscKey != 27) {
cv::waitKey(0);
} return(0);

}

error is coming as 'Error reading video file'. please solve this issue

edit retag flag offensive close merge delete

Comments

make sure, that opencv_ffmpeg64.dll is on your PATH or next to your app

berak gravatar imageberak ( 2017-08-23 02:07:41 -0600 )edit