unable to write frames to video file

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

unable to write frames to video file

i have to write a video file from frames captured. i'm able to grab
frames, get all the capture propertyand also able to create the video
file. but the created videofile is of 0 bytes. frames are not getting
iv used the following code

typedef struct CvCapture CvCapture;
CvVideoWriter *writer = 0;
int isColor = 1;
CvCapture* capture = cvCaptureFromFile("D:\\samplevideo.avi");
IplImage* img = 0;
if(!cvGrabFrame(capture)){    // capture a frame
        printf("Could not grab a frame\n\7");  
cvQueryFrame(capture); // this call is necessary to get correct        
// capture properties
int frameH    = (int) cvGetCaptureProperty(capture,
int frameW    = (int) cvGetCaptureProperty(capture,
int fps       = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
int numFrames = (int) cvGetCaptureProperty(capture,
for(int i=0;i<numFrames;i++){
 cvSetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES, i);          
  img=cvRetrieveFrame(capture);  // retrieve the captured frame
  cvWriteFrame(writer,img);      // add the frame to the file

output: out.avi file is created with 0 bytes content.

hoping for help..thanks