OpenCV cvWriteFrame, cvWriteToAVI

The problem is the following I want to read a video file from disk and convert it every frame to shades of gray and write it to a new video file I use the following code to do this

CvCapture* capture = cvCreateFileCapture( "/root/tree.avi");
if (!capture){
    return -1;
}
...
CvVideoWriter* writer = 
cvCreateVideoWriter("/root/output.avi",CV_FOURCC('D','I','V','X'),fps,size);
   ...
  IplImage* gray_frame = cvCreateImage(
    size,
    IPL_DEPTH_8U,
    1
  );

  while( (bgr_frame=cvQueryFrame(capture)) != NULL ) {
    cvShowImage( "Example2_10", bgr_frame );

    cvCvtColor(bgr_frame,gray_frame,CV_RGB2GRAY);

    cvShowImage( "B&W result", gray_frame );
    cvWriteFrame( writer, gray_frame);
    char c = cvWaitKey(10);
    if( c == 27 ) break;
}
...

The problem is that the program works fine, but it is not possible to write frames to output.avi and creats only an empty output.avi file is only 5.5KB

One more thing: I cannot write only gra_frame using cvWriteFrame, and if I try to write bgr_frame, it will successfully write the output.avi file.

Please if anyone knows a solution let me know

+5
source share
2 answers

is_color=0 cvCreateVideoWriter, . - .

cvCreateVideoWriter, 1:

CvVideoWriter* cvCreateVideoWriter(const char* filename, int fourcc, double fps, CvSize frame_size, int is_color=1)
+3

, a CvVideoWriter , , , cvWriteFrame. OpenCV, OpenCV 2.4

0

All Articles