Ask Your Question

Revision history [back]

VideoWriter produces empty/broken files

We are working on a project and need to write video to a file, but the file produced by the videowriter will not play. It does however work when using a webcam. We have tried a bunch of different codecs and -1. -1 options cause memory exception, while defined fourcc just produces a broken file.

 VideoWriter output("D:/Video2.avi", CV_FOURCC('P', 'I', 'M', '1'), 24, s, true);


while (i <30){
    Mat frame;
    bool success = cap1.read(frame); 
    if (!success) 
    {
        cout << "ERROR" << endl;
        break;
    }

    output.write(frame);
    i++;
    if (waitKey(1) >= 0)break;
}

Where cap1 is a videocapture of an mp4 file. Also tried avi. And s is a 1080p size object. Any help would be appreciated.

System is running windows7, opencv v 2.4.8