Ask Your Question

Revision history [back]

opencv videowriter, whether the image had been write into vedio.

when I set the videowriter's fps is 10, but in for loop I get more than 10 images per second, but the vedio of output is 10fps, which image had been write into the vedio, or how the videowriter make the output vedio's fps is 10. thank you to give me some answer.

my program is: int main(int argc, char *argv) { VideoCapture cam(0);

cam.set(CV_CAP_PROP_FRAME_WIDTH, 1280);

cam.set(CV_CAP_PROP_FRAME_HEIGHT, 720);
if (!cam.isOpened()) {
    cout << "cam open failed!" << endl;
    return -1;
}

cout << "cam open success!" << endl;
namedWindow("cam");

Mat img;

VideoWriter vw;

vw.open("out.mp4",
    VideoWriter::fourcc('X', '2', '6', '4'),
    10,
    Size(cam.get(CAP_PROP_FRAME_WIDTH), cam.get(CAP_PROP_FRAME_HEIGHT))
    //Size(1280,720)
);
if (!vw.isOpened()) {
    cout << "VideoWriter open failed" << endl;
    return -1;
}

cout << "VideoWriter open Success" << endl;

for (;;) {
    cam.read(img);
    if (img.empty()) {
        break;
    }

    imshow("cam", img);
    vw.write(img);
    if (waitKey(5) == 'q') {
        break;
    }
}
waitKey(0);
return 0;

}