title: Writing AVI files in OpenCV
body: <p>There example on the net and code given in Learn OpenCv,Orielly.</p>
  
  <p>After many attempts the out.avi file is written with 0 bytes.
  I wonder where i went wrong.</p>
  
  <p>The following are the code i used...</p>
  
  <pre><code>int main(int argc, char* argv[]) {
      CvCapture* input = cvCaptureFromFile(argv[1]);
      IplImage* image = cvRetrieveFrame(input);
  
      if (!image) {
          printf("Unable to read input");
          return 0;
      }
  
  
      CvSize imgSize;
      imgSize.width = image-&gt;width;
      imgSize.height = image-&gt;height;
  
  
  
      double fps = cvGetCaptureProperty(
              input,
              CV_CAP_PROP_FPS
              );
  
      CvVideoWriter *writer = cvCreateVideoWriter(
              "out.avi",
              CV_FOURCC('M', 'J', 'P', 'G'),
              fps,
              imgSize
              );
  
  
      IplImage* colourImage;
      //Keep processing frames...
      for (;;) {
  
          //Get a frame from the input video.
          colourImage = cvQueryFrame(input);
          cvWriteFrame(writer, colourImage);
  
      }
  
      cvReleaseVideoWriter(&amp;writer);
      cvReleaseCapture(&amp;input);
  
  }
  </code></pre>