OpenCV VideoWriter won't set FPS correctly
In my program, I read a webcam or video file via OpenCV and display it via Qt. I get fps from video properties and set timer accordingly.
I have no problem reading the video, the fps calibration is good (since the webcam shows 0fps, I set it to 30) But when I record images, I set the fps output video the same as the original video, but when I read it in VLC or even Windows Media Player, the video is accelerated.
The most curious thing, when I play the recorded video in my program, the fps is good and the video is not accelerated.
This is how I do it:
Constructor()
{
// Initializing the video resources
cv::VideoCapture capture;
cv::VideoWriter writer;
cv::Mat frame;
int fps;
if (webcam)
{
capture.open(0);
fps = 30;
}
else
{
capture.open(inputFilePath);
fps = this->capture.get(CV_CAP_PROP_FPS);
}
// .avi
writer = cv::VideoWriter(outputFilePath, CV_FOURCC('M', 'J', 'P', 'G'), fps, frame.size());
// Defining the refresh timer;
QTimer timer = new QTimer();
connect(timer, SIGNAL(timeout()), this, SLOT(updateFeed()));
this->timer->start(1000 / fps);
}
updateFeed()
{
// ... display the image in a QLabel ... at a reasonnable speed.
writer.write(frame);
}
Now am I doing something wrong? Thanks to
+3
source to share
No one has answered this question yet
See similar questions:
or similar: