Ask Your Question
0

VideoCapture is very slower when opening videoFile why??

asked 2018-01-24 02:55:07 -0600

bincos gravatar image

updated 2018-01-24 20:35:32 -0600

This is a simple code to read Video from File

My problem is that Why when trying to read a Video, the video is very very slower?? I'm trying to read a Video recorded with My Phone thee video file format is mp4;

How Can I solve this problem?? to convert that video in an other Video Format?? which one??

I want openCv to read my video File with the normal speed as when I'm reading the Video File in a Video Media player

simple url for the video link: from Youtube int main() {

///Video Lecture

 const string sourceReference = "K:/OpenCv/DataSetCar/WP.mp4";

 // Open the video file
 cv::VideoCapture capture(sourceReference);
 // check if video successfully opened
 if (!capture.isOpened())
 return 1;
 // Get the frame rate
 double rate= capture.get(CV_CAP_PROP_FPS);
 bool stop(false);

 cv::Mat frame; // current video frame
 cv::namedWindow("Extracted Frame",WINDOW_AUTOSIZE);


 // Delay between each frame in ms
 // corresponds to video frame rate
 int delay= 1000/rate;
 // for all frames in video
 while (!stop) {
 // read next frame if any
 if (!capture.read(frame))
 break;
 cv::imshow("Extracted Frame",frame);
 // introduce a delay
 // or press key to stop
 if (cv::waitKey(delay)>=0)
 stop= true;
 }
 // Close the video file.
 // Not required since called by destructor
 capture.release();


return 0;

}

edit retag flag offensive close merge delete

Comments

first try

if (cv::waitKey(1)>=0)

probably you will ask another question "how to slow down". could you share a small video recorded with your phone.

sturkmen gravatar imagesturkmen ( 2018-01-24 03:44:53 -0600 )edit

Hi @sturkmen i tried to add if (cv::waitKey(1)>=0) but nothing changed

bincos gravatar imagebincos ( 2018-01-24 04:33:31 -0600 )edit

You are probably limited by how fast your memory is. So you have waitKey(delay), which means the gap is how long it take to read + delay. So you shrink delay, like sturkmen said. You shouldn't add a new line, but change the existing one.

Tetragramm gravatar imageTetragramm ( 2018-01-24 17:50:40 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-01-25 02:59:11 -0600

bincos gravatar image

updated 2018-01-29 07:23:00 -0600

Thank You for Every One, I used Only this simple Code and All this is good, This one worked perfect *The problem was that I was using a video of * 1280 X 768 *then I reduced the Size to * 640X480 and this solved my problem int main() {

  VideoCapture cap("K:/OpenCv/DataSetCar/WP.mp4");
         if(!cap.isOpened())  // check if we succeeded
             return -1;

         Mat edges;
         namedWindow("myFrame",1);
         for(;;)
         {
             Mat frame;
             cap >> frame; // get a new frame from camera
               imshow("edges", frame);
             if(waitKey(30) >= 0) break;
         }           
         return 0;

}

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-01-24 02:55:07 -0600

Seen: 3,736 times

Last updated: Jan 24 '18