How to extract frames at 10 fps?
I am trying to extract and save frames at 10 fps, but using the following code, it is extracting every frames(25 fps). How can I set the fps to 10 fps so that i can extract and save the frames at 10 fps instead of 25 fps? Can somebody please help..
#include "opencv2/opencv.hpp"
#include <time.h>
#include <stdio.h>
#include<string>
#include<ctime>
using namespace cv;
using namespace std;
const char* videofilename = "C:/Users/Desktop/Movements/Passing/2.outside of the foot.mp4";
VideoCapture cap(videofilename); // open a video file
int main(int argc, char** argv)
{
if (!cap.isOpened()) // check if succeeded
{
cout << "file " << videofilename << " not found or could not be opened" << endl;
return -1;
}
namedWindow("output");
unsigned long counter = 0;
//double fps = cap.set(CV_CAP_PROP_FPS, 10);//set the fps of video
double fps = cap.get(CV_CAP_PROP_FPS);
cout << "Frame per seconds : " << fps << endl;
Mat frame;
// read frames until end of video:
while (cap.read(frame))
{
// display frame
imshow("output", frame);
waitKey(25); // remove this line if you don't need the live output
// adjust the filename by incrementing a counter
std::stringstream filename(std::stringstream::in | std::stringstream::out);
filename << "image" << counter++ << ".jpg";
std::cout << "writing " << filename.str().c_str() << " to disk" << std::endl;
// save frame to file: image0.jpg, image1.jpg, and so on...
imwrite(filename.str().c_str(), frame);
}
return 0;
}