Ask Your Question
0

Video Recording is too fast

asked 2013-07-10 12:50:43 -0600

yohanrw gravatar image

updated 2013-07-10 12:51:57 -0600

Please note I am duplicating this questions because I did not get the answer I am seeking for.

Please have a look at the following code.

#include <iostream>
#include <opencv2/core/core.hpp>
#include <string>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/video/background_segm.hpp>

using namespace std;
using namespace cv;

double getMSE(const Mat& I1, const Mat& I2);

int main()
{
    Mat current;
    VideoCapture cam1;
    VideoWriter *writer = new VideoWriter();



    cam1.open(0);

    namedWindow("Normal");

    if(!cam1.isOpened())
    {
        cout << "Cam not found" << endl;
        return -1;
    }

    cam1>>current;
    Size *s = new Size((int)current.cols,current.rows);
    writer->open("D:/OpenCV Final Year/OpenCV Video/MyVideo.avi",CV_FOURCC('D','I','V','X'),10,*s,true);


    while(true)
    {
        //Take the input
        cam1 >> current;

        *writer << current;
        imshow("Normal",current);

        if(waitKey(30)>=0)
         {
               break;
         }


    }
}

This code runs fine, no issue. But, when I run the recorded video, it is super fast! Like it is fast forwarded. I really do not understand why. Please help.


In the previous question I was advised to use usleep() and I coudn't find it so I used Sleep(). But I got the same results! Anyway this is a real time application, so video should be displayed to the user real time. Using such methods disturb how the video is shown because video also displayed to the user after the specified number of milliseconds. you know, it is like watching a movie which gets stuck always.

Please help.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2013-07-11 00:26:19 -0600

vinayverma gravatar image

This is a probable mismatch between the fps of your cam and your output video (10). If you match the fps of VideoCapture and VideoWriter, the speed would be normal. I think that should work.

You can also verify if changing the fps in VideoWriter changes your output video speed.

edit flag offensive delete link more

Comments

Thank you for the reply. How to match those 2?

yohanrw gravatar imageyohanrw ( 2013-07-11 02:12:06 -0600 )edit

Use the following: writer->open("D:/OpenCV Final Year/OpenCV Video/MyVideo.avi",CV_FOURCC('D','I','V','X'), cam1.get(CV_CAP_PROP_FPS),*s,true);

This would not work if your cam doesn't support ioctl for getting fps. So just put a breakpoint and check if cam1.get(CV_CAP_PROP_FPS) returns 0.

If that is the case, I think you can still manually tweek the fps parameter and set it to the value for which your output video runs with normal speed (not a good way though).

vinayverma gravatar imagevinayverma ( 2013-07-11 06:31:34 -0600 )edit
0

answered 2014-08-20 22:24:38 -0600

keyvan gravatar image

updated 2014-08-20 22:44:07 -0600

I have buffer a few frame in ram and after an event occurred write 3 second buffered images and continue to 10 seconds write in a single file . but buffered image play backing is too fast of other part of video . the length of video is true but playback isn't true.

        writer->open(RecordPath , CV_FOURCC('M', '4', 'S', '2'), Fps, Width, Height, true);

        int delay = 1000 / Fps;
        for (int i = 0; i != buffer.Count-1; i++)
        {
            writer << (buffer[i]);
        }

        int frame_counter = 0;
        while (frame_counter < Recoerd_frame_size)
        {  
            WaitKey(delay);//wait for get new frame
            writer << (frame);
            frame_counter++;
        }
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-07-10 12:50:43 -0600

Seen: 13,882 times

Last updated: Aug 20 '14