tags:

views:

3653

answers:

1

I am trying to save a video file with openCV under Mandriva Linux 2009.1. Unfortunately cvCreateVideoWriter always returns null although I could see and modify both and mpeg fiels, in other words cvCaptureFromCam, cvCaptureFromAvi, cvRetrieveFrame is working.

I tried all the possible codecs from this tutorial and this codec page. I also tried 0 for uncompressed avi and -1 for a selection box in the fourcc parameter, but no choice has popped up and nothing happened. I also modified isColor to 0.

I also have write permissions in the working directory.

Here is the relevant code snippet:

    CvVideoWriter *writer = 0;
    int isColor = 1;
    int fps = 25;
    int frameW = 640;
    int frameH = 480;


    if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0])))
        capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - '0' : 0 );
    else if( argc == 2 ) {
        printf("argc == 2 :%s:\n", argv[1] );
        capture = cvCaptureFromFile( argv[1] );
    }

    cvInitSystem(argc,argv);

 writer = cvCreateVideoWriter("out.avi",CV_FOURCC('I','Y','U','V'),fps,cvSize(frameW,frameH),isColor);

What could be the problem?

+1  A: 

This will depend on how your OpenCV library was configured. In particular I believe HAVE_FFMPEG must be defined in order for the 'IYUV' FOURCC value to be handled. Was your library built with HAVE_FFMPEG defined?

The default writer object (which is created when fourcc is zero, or the fourcc value is not handled by one of the available handlers) creates an image file per frame. In this case the filename needs to be something like "file%04d.foo" or "file0001.foo", otherwise writer creation fails. You might try passing something like "test0001.png" for the filename parameter as an experiment to verify that the default image writer is created successfully (this won't help directly, but might be a way to confirm that your fourcc value is not being recognized by an available writer.)

According to documentation, the option to open a selection dialog when the fourcc equal -1 is Windows-specific.

Lance Richardson
Thanks for the response. Although I am not "there", I could go further.I am using the built-in mandriva opencv-devel-1.1.0-0.pre1.2mdv2009.1 package. As cvCaptureFromAvi and Cam is working and I can see video in a window I guess that the FFMPEG support is OK.You are right. When I try the test0001.png as filename parameter then it works and creates lots of images in the working directory. So there must be something wrong with the available writers.I also read that -1 for fourcc is Windows only, it was just a try.
rics
According to highgui.h #define CV_FOURCC_DEFAULT -1 /* Use default codec for specified filename (Linux only) */So it should work with the default codec on Linux as well.
rics
Interestingly printf("fourcc: %lf\n",cvGetCaptureProperty(capture,CV_CAP_PROP_FOURCC)); returns 0 for a capture from an mpeg-2 file while opencv could show the original and the motion detected version of the movie in separate windows.
rics
I never managed to get the video writer to work in OpenCV 1. Either i got NULL for the writer, or it produced corrupt frames. Upgrading to OpenCV 2 solved both of these problems.
David