Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Writing video fail with no error

Hello I am using QT and OpenCV 3.1.0 on a Win7 PC.

I am trying to record my camera and i don't know why but the file is always empty. i tired using other codec but it's always fails. any idea?

int main(int argc, char *argv[])

{

cv::VideoCapture cap(0);
cv::VideoWriter rec;
bool first = true;
for(;;)
{
    cv::Mat frame;

    cap >> frame;
    if (first)
    {
        qDebug()<< "init";
        rec.open("C:/Project/outi.avi", CV_FOURCC('X','V','I','D'), 24, cv::Size(frame.size().height,frame.size().width));
        if (!rec.isOpened())
        {
            qDebug()<< "open record fail";
            return 0;
        }
        first = false;
    }
    rec << frame;
    cv::imshow("test", frame);
    if (cv::waitKey(30) == 'q')
    {
        break;
    }
}
return 0;

}