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

sindhura8588
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
copied.
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");  
        exit(0);}
cvQueryFrame(capture); // this call is necessary to get correct        
// capture properties
int frameH    = (int) cvGetCaptureProperty(capture,
CV_CAP_PROP_FRAME_HEIGHT);
int frameW    = (int) cvGetCaptureProperty(capture,
CV_CAP_PROP_FRAME_WIDTH);
int fps       = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
int numFrames = (int) cvGetCaptureProperty(capture,
CV_CAP_PROP_FRAME_COUNT);
writer=cvCreateVideoWriter("D:\\out.avi",CV_FOURCC('P','I','M','1'),
                           fps,cvSize(frameW,frameH),isColor);
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