title: OpenCV VideoWriter won't write anything, although cvWriteToAVI does
body: <p>I'm been trying to capture video from a cam and write it into an AVI file. I'm using Qt 4.8.2 with MSVC 2010 (x86) on Windows 7. I have 2 versions of the code: one using cv::Mat and the other using IplImage*. However, only the IplImage* version is working. Here's my code using cv::Mat:</p>
  
  <pre><code>#include &lt;opencv2/core/core.hpp&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  
  using namespace cv;
  
  int main() {
      VideoCapture* capture2 = new VideoCapture( CV_CAP_DSHOW );
      Size size2 = Size(640,480);
      int codec = CV_FOURCC('M', 'J', 'P', 'G');
      VideoWriter* writer2 = new VideoWriter("video.avi",codec,15,size2);
  
      int a = 100;
      Mat frame2;
      while ( a &gt; 0 ) {
          capture2-&gt;read(frame2);
          writer2-&gt;write(frame2);
          a--;
      }
  
      writer2-&gt;release();
      capture2-&gt;release();
      return 0;
  }
  </code></pre>
  
  <p>And here's the code using IplImage*:</p>
  
  <pre><code>#include &lt;opencv2/core/core.hpp&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  
  int main() {
      CvCapture* capture = cvCaptureFromCAM( CV_CAP_DSHOW );
      CvSize size = cvSize(640,480);
      int codec = CV_FOURCC('M', 'J', 'P', 'G');
      CvVideoWriter* writer = cvCreateVideoWriter("video.avi",codec,15,size);
  
      int a = 100;
      while ( a &gt; 0 ) {
          IplImage* frame = cvQueryFrame( capture );
          cvWriteToAVI(writer,frame);
          a--;
      }
  
      cvReleaseVideoWriter(&amp;writer);
      cvReleaseCapture( &amp;capture );
      return 0;
  }
  </code></pre>
  
  <p>It's basically the same, or at least it looks like the same thing to me. It reads 100 frames and should write them into "video.avi". It compiles and runs without errors, but the cv::Mat version doesn't write anything, and the IplImage* version works perfectly.</p>
  
  <p>Does someone have any idea on what's going on?</p>