Live Stream FPS problem

asked 2013-07-05 14:43:32 -0600

Evil Potato gravatar image

updated 2013-07-05 15:00:58 -0600

Hello, I wrote a code that records a live stream into avi file. It does output it, but for some reason, it plays really really slowly. Each frame takes about 1 ~ 2 seconds. I believe I have acquired the fps information by using cvGetCaptureProperty, so I am wondering why it is playing slowly. Would you help me please? Thank you. Sorry this is in C :(

#include "cv.h"
#include "highgui.h"
#include "cxcore.h"

int main(double fps, CvSize size, CvVideoWriter *writer, char c)
{
    CvCapture* capture = cvCreateCameraCapture(-1);

    cvNamedWindow("Live Stream", CV_WINDOW_AUTOSIZE);

    size = cvSize(
            (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH),
            (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT)
        );

    fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);

    writer = cvCreateVideoWriter(
            "C:\\Recorded.avi",
            -1,
            fps,
            size,
            1
        );

    while(1)
    {
        IplImage* frame = cvQueryFrame(capture);

        if(!frame)
            break;

        cvWriteFrame(writer, frame);

        cvShowImage("Live Stream", frame);

        c = cvWaitKey(33);

        if(c == 27)
        {
            cvReleaseVideoWriter(&writer);
            break;
        }

    }
    cvReleaseCapture(&capture);
    cvDestroyWindow("Live Stream");
}

update: so I manually replaced 'fps' variable with a value in cvCreateVideoWriter and that seems to solve the fps problem. However, I still would like to obtain the exact fps of the webcam I am using.

edit retag flag offensive close merge delete