Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Video Writer

I use below code for VideoWriter.when I capture a video file,this code product an AVI video.but When I use my web cam for video capturing,this code product video but that video don't show anything.why this happen and what can I do for solve it?

`using namespace cv; using namespace std;

int main(int argc, char* argv[]) { VideoCapture cap(0); // open the video camera no. 0

if (!cap.isOpened())  // if not success, exit program
{
    cout << "Cannot open the video cam" << endl;
    return -1;
}

Mat frame;
namedWindow("MyVideo", CV_WINDOW_AUTOSIZE);

VideoWriter writer;
writer.open("test.avi", -1 ,20 ,frame.size());

while (1)
{


    bool bSuccess = cap.read(frame); // read a new frame from video

    if (!bSuccess)
    {
        cout << "Cannot read a frame from video stream" << endl;
        break;
    }

           writer.write(frame);
    if (waitKey(30) == 27) 
    {
        cout << "esc key is pressed by user" << endl;
        break;
    }
}

return 0;