views:

366

answers:

2

Hi , I’m trying to use OpenCV to write a video file. I have a simple program that loads frames from a video file then accepts to save them

At first the cvCreateVideoWrite always return NULL. I got a answer from your group saying it returns separate images and to try to change the file name to test0001.png, this worked.

But now the cvWriteFrame function always fails, the code is

 CString path;
 path="d:\\mice\\Test_Day26_2.avi";

   CvCapture* capture = cvCaptureFromAVI(path);
   IplImage* img = 0; 

 CvVideoWriter *writer = 0;
 int isColor = 1;
 int fps     = 25;  // or 30
 int frameW  = 640; // 744 for firewire cameras
 int frameH  = 480; // 480 for firewire cameras
 writer=cvCreateVideoWriter("d:\\mice\\test0001.png",CV_FOURCC('P','I','M','1'),
                           fps,cvSize(frameW,frameH),isColor);
 if (writer==0)
  MessageBox("could not open writter"); 

int nFrames = 50;
for(int i=0;i<nFrames;i++){
  if (!cvGrabFrame(capture))
   MessageBox("could not grab frame"); 
  img=cvRetrieveFrame(capture);  // retrieve the captured frame
  if (img==0)
   MessageBox("could not retrive data"); 
  if (!cvWriteFrame(writer,img) )
   MessageBox("could not write frame"); 
}
cvReleaseVideoWriter(&writer);

Any help would be GREAT - Ted

A: 

Try CV_FOURCC('D', 'I', 'V', 'X'), CV_FOURCC('f', 'f', 'd', 's') (with *.avi filename) or CV_FOURCC_DEFAULT (with *.mpg). Video writing is still quite messy in opencv >_>

Cfr
A: 

I have a similar question here on SOF. The response and the comments may help you.

rics