videowriter [closed]

asked 2011-11-10 14:33:33 -0600

naleemom gravatar image

updated 2014-01-28 17:10:45 -0600

ngrennan gravatar image


i am the beginner of opencv and i've just written a first program for videocaptur and videowriter. i copied the source from the wiki and changed the only video file name, but it made error.

at first i expected there is no error because i did not write myself but copy from wiki.

next is the source of wiki.


int main(int, char**)

{ VideoCapture capture(1); // open the default camera

    if( !capture.isOpened() )  {

            printf("Camera failed to open!\n");

            return -1;

    Mat frame;

    capture >> frame; // get first frame for size

    // record video

    VideoWriter record("RobotVideo.avi", CV_FOURCC('D','I','V','X'), 30, frame.size(), true);

    if( !record.isOpened() ) {

            printf("VideoWriter failed to open!\n");

            return -1;




            // get a new frame from camera

            capture >> frame; 

            // show frame on screen

            imshow("video", frame); 

            // add frame to recorded video

            record << frame; 

            if(waitKey(30) >= 0) break;


    // the camera will be deinitialized automatically in VideoCapture destructor

    // the recorded video will be closed automatically in the VideoWriter destructor

    return 0;

} //////

with the source, i changed 2 parts as next

one is for VideoCapture. (i don't have tunercard or camera.)


    VideoCapture capture("C:/Users/Public/Videos/Sample Videos/WildlifeTest.wmv"); // open the default camera


and the other is for VideoWriter

      VideoWriter record("C:/Users/Public/Videos/Sample Videos/WildlifeRec.wmv",
         CV_FOURCC('W','M','V','1'), 30, 
        frame.size(), true);


and the part of error is

           // add frame to recorded video

            record << frame;

please show me what is my mistake!

edit retag flag offensive reopen merge delete

Closed for the following reason Question does not follow our guidelines for questions. Please see: for more details. by tfoote
close date 2012-02-29 14:17:33