VideoCapture is very slower when opening videoFile why??
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;
}
first try
probably you will ask another question "how to slow down". could you share a small video recorded with your phone.
Hi @sturkmen i tried to add if (cv::waitKey(1)>=0) but nothing changed
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.