#include <cv.h>
#include <highgui.h>
#include <stdio.h>
#include <windows.h>
int main()
{
CvCapture *capture;
IplImage *frame;
// capture=cvCreateCameraCapture(0);
capture = cvCaptureFromCAM(0);
cvQueryFrame(capture);
cvNamedWindow("Webcam",0);
CvVideoWriter *writer;
char AviFileName[]="c:\\Output.avi";
int AviForamt = -1;
int FPS = 25;
int i=0;
// CvSize AviSize = cvSize(640,480);
int AviColor = 1;
int nFrames=90;
int frameH=(int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT);
int frameW=(int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH);
writer=cvCreateVideoWriter(AviFileName,/*AviForamt*/CV_FOURCC('X', 'V', 'I', 'D'), FPS,cvSize(frameW,frameH),AviColor);
while(true)
{
frame = cvQueryFrame(capture);
cvWriteFrame(writer,frame);
cvShowImage("Webcam",frame);
printf("%d\n",i);
if(cvWaitKey(20)>0) break;
i++;
}
/*
for ( i = 0; i < nFrames; i++)
{
cvGrabFrame(capture);
frame = cvRetrieveFrame(capture);
cvShowImage("Webcam",frame);
cvWaitKey(20);
cvWriteFrame(writer,frame);
}
*/
cvReleaseCapture(&capture);
cvReleaseVideoWriter(&writer);
cvDestroyWindow("Webcam");
return 1;
}