CvVideoWriter *write = 0;
int isColor = 1;
int fps = 25;
int frameW = 768;
int frameH = 576;
CvSize size = cvSize(
(int)cvGetCaptureProperty(myvideo.m_pcapture,CV_CAP_PROP_FRAME_WIDTH)
,(int)cvGetCaptureProperty(myvideo.m_pcapture,CV_CAP_PROP_FRAME_HEIGHT)
);
//write = cvCreateVideoWriter("out.avi",CV_FOURCC('M','J','P','G'),fps,size,isColor);
write = cvCreateVideoWriter("D:/out.avi",CV_FOURCC('X','V','I','D'),fps,size,isColor);
IplImage *img = 0;
int nFrames = 50;
IplImage * pImageWrite = cvCreateImage(size,8,3);
for (int i = 0;i<nFrames;i++)
{
img = cvQueryFrame(myvideo.m_pcapture);
cvCopy(img,pImageWrite);
//img = cvRetrieveFrame(myvideo.m_pcapture);
cvWriteFrame(write,pImageWrite);
}
cvReleaseImage(&pImageWrite);
cvWaitKey(20);
cvReleaseVideoWriter(&write);
原来cvQueryFrame返回的img是可读的不能修改,img只是指向m_pcapture的一个指针,必须把这块内存复制出来才能运行成功,否则cvWriteFrame就会出错。。。