opencv grava saída da webcam em arquivo avi

Estou tentando criar um vídeo avi a partir da minha saída da webcam usando o opencv. Nenhuma exceção é lançada, no entanto, o arquivo avi criado possui 414 bytes de tamanho e não aumenta.

Também não será reproduzido com nenhum media player. Eu suspeito que há algo errado com a escrita da parte do arquivo.

Aqui está o código:

  CvCapture *capture = cvCaptureFromCAM( 0 );

  int width = ( int )cvGetCaptureProperty( capture, 
  CV_CAP_PROP_FRAME_WIDTH );

  int height = ( int )cvGetCaptureProperty( capture,
  CV_CAP_PROP_FRAME_HEIGHT );
  CvVideoWriter *writer = cvCreateVideoWriter("CamCapture.avi",                                                     
  -1,30, cvSize(  width, height ) );

  cvNamedWindow("capWindow", CV_WINDOW_AUTOSIZE);
  IplImage *frame = 0;

  // this returns 0 not sure why ??
  //double fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
  double fps = 30;

  while( 1 )
  {
      frame = cvQueryFrame( capture );
      cvShowImage("capWindow",frame);
      cvWriteFrame( writer, frame );
      char c = cvWaitKey(1000/fps);

      if( c == 27 ) break;
  }

   cvReleaseCapture( &capture );
   cvReleaseVideoWriter( &writer );
   cvDestroyWindow( "capWindow" );

Eu referenciei e tentei os seguintes exemplos sem sorte:

http://gipetrou.com/scc/2010/12/12/save-video-from-webcam-with-opencv-2-1/http://answers.oreilly.com/topic/1366-how-to-write-to-an-avi-file-with-opencv/https://www.cs.utexas.edu/~teammco/misc/udp_video/

questionAnswers(2)

yourAnswerToTheQuestion