I’m new to OpenCV and trying to record simple video with ffmpeg, but size is 0kb everytime… I got success with Cinepak codec, but video is recorded fast, or I set fps to 4 and cwWaitKey(20).. Here is the code what I’m trying..
cvNamedWindow("Webcam", CV_WINDOW_AUTOSIZE);
CvCapture *cap; cap = cvCreateCameraCapture(0);
IplImage *img; img = cvQueryFrame(cap);
CvVideoWriter *writer;
double fps = cvGetCaptureProperty(cap, CV_CAP_PROP_FPS);
int camWidth = (int)cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_WIDTH);
int camHeight = (int)cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_HEIGHT);
CvSize size = cvSize(camWidth, camHeight);
writer = cvCreateVideoWriter("record.avi", CV_FOURCC('M','J','P','G'), fps, size);
while(cvQueryFrame(cap))
{
img = cvRetrieveFrame(cap);
cvWriteFrame(writer, img);
cvShowImage("Webcam", img);
cvWaitKey(20);
}
//release stuff here.
Can someone tell me what I’m doing wrong? Thank you.
P.S I tried also other FOURCCs but still same result, file is 0 kbytes, nothing is written there.. help 🙁
FOURCCs tried: XVID, MP4V, FVFW, MPEG, MPG1/2, WM1/2.
P.P.S Using Windows 7 x64, installed both ffmpeg x86 and x64 versions.
Fixed.. I just downloaded DIVX codec, installed it and used DIVX fourcc, works like a charm.
But I still got problems for calculating number of frames hehe 🙂
10 fps would be 100 frames, but I fail with 25 fps.. doesn’t work 25*10.