Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

VideoCapture and VideoWriter are not synchronized at all. if you told the witer to have a final 10 fps, it will just do so, no matter how many you write per second in real life.

so, timing is everything here. you can either drop frames, or try to adjust the sleep time:

while(true)
{
    int64 start = getTickCount();

    cap >> frame;
    writer.write(frame);
    imshow("ocv",frame);

    int64 end = getTickCount();

    float sec = (end-start) / getTickFrequency();
    float t = (1.0 / fps) - sec;
    int ticks = t * 1000;
    cerr << sec << "  " << t << " " << ticks << endl;
    int k = waitKey(ticks>1 ? ticks : 10);
    if (k==27) break;  // esc. pressed
}