I think my question is pretty basic, but I'm writing this code in OpenCV to simply capture video data from the webcam and save it to file. Now the problem is that the file gets made at the desired destination, it initially is about 286 bytes in size. Then when I assign the first frame to the pointer, the size increases to 414 bytes. However, when I run the whole code, the size of the saved video remains 414 bytes. Of course, as a result my media player cannot play the file and says " is not in a format that QuickTime Player understands." and the same happens with the VLC player.
Here is my code for the same:
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
int main( int argc, char** argv ) {
CvCapture* capture;
capture = cvCreateCameraCapture(0);
assert( capture != NULL );
IplImage* bgr_frame = cvQueryFrame( capture );
CvSize size = cvSize(
(int)cvGetCaptureProperty( capture,
CV_CAP_PROP_FRAME_WIDTH),
(int)cvGetCaptureProperty( capture,
CV_CAP_PROP_FRAME_HEIGHT)
);
cvNamedWindow( "Webcam", CV_WINDOW_AUTOSIZE );
CvVideoWriter *writer = cvCreateVideoWriter( "/Users/user/Desktop/OpenCV_trial/OpenCV_trial/vidtry.AVI",
CV_FOURCC('D','I','V','X'),
30,
size
);
while( (bgr_frame = cvQueryFrame( capture )) != NULL )
{
cvWriteFrame(writer, bgr_frame );
cvShowImage( "Webcam", bgr_frame );
char c = cvWaitKey( 33 );
if( c == 27 ) break;
}
cvReleaseVideoWriter( &writer );
cvReleaseCapture( &capture );
cvDestroyWindow( "Webcam" );
return( 0 );
}
I don't know why this is happening. I am using the mac OSX Lion and running Xcode.
Has anyone faced this problem before? If so, how could I solve it?
Thank you!
-Yash