title: How to add multi-image streams into a AVI file
body: <p>I'm making a AVI file from the image-frames by using C/C++ project as the following input:</p>
  
  <ol>
  <li>stream1: 
  <ul>
  <li>frame per second: 12 fps</li>
  <li>number of frames: 500</li>
  </ul></li>
  <li>stream2: 
  <ul>
  <li>frame per second: 10 fps</li>
  <li>number of frames: 600 </li>
  </ul></li>
  <li>stream3: 
  <ul>
  <li>frame per second: 15 fps</li>
  <li>number of frames: 700</li>
  </ul></li>
  </ol>
  
  <p>Using the <a href="http://www.wischik.com/lu/programmer/avi_utils.html" rel="nofollow">avi_utils</a> library, I've tried with the <code>AddAviFrame()</code> function to add these frames into the AVI file. By this way, I can only create a frame-stream with the frame rate corresponding. 
  <strong>Is it possible to add more than one stream with different frame rates into an AVI file? If it is then how can I do it</strong>. 
  I also tried to call the release function <code>AVIStreamRelease()</code> then open another stream <code>AVIFileCreateStream()</code> but it didn't work. Please show me how can I resolve this case.</p>
  
  <pre><code>HAVI CreateAvi(const char *AVIFileName, int frameperiod, const WAVEFORMATEX *wfx)
  { 
    IAVIFile *pfile;
    AVIFileInit();
    HRESULT hr = AVIFileOpen(&amp;pfile, AVIFileName, OF_WRITE|OF_CREATE, NULL);
    if (hr!=AVIERR_OK) {AVIFileExit(); return NULL;}
    TAviUtil *au = new TAviUtil;
    au-&gt;pfile = pfile;
    if (wfx==NULL) ZeroMemory(&amp;au-&gt;wfx,sizeof(WAVEFORMATEX)); else  CopyMemory(&amp;au-&gt;wfx,wfx,sizeof(WAVEFORMATEX));
    au-&gt;period = frameperiod;
    au-&gt;as=0; au-&gt;ps=0; au-&gt;psCompressed=0;
    au-&gt;nframe=0; au-&gt;nsamp=0;
    au-&gt;iserr=false;
    return (HAVI)au;
  }
  HRESULT AddAviFrame(HAVI avi, HBITMAP hbm)
  { 
    if (au-&gt;ps==0) // create the stream, if it wasn't there before
    { AVISTREAMINFO strhdr; ZeroMemory(&amp;strhdr,sizeof(strhdr));
      strhdr.fccType = streamtypeVIDEO;// stream type
      strhdr.fccHandler = 0; 
      strhdr.dwScale = au-&gt;period;
      strhdr.dwRate = 1000;
      strhdr.dwSuggestedBufferSize  = dibs.dsBmih.biSizeImage;
      SetRect(&amp;strhdr.rcFrame, 0, 0, dibs.dsBmih.biWidth, dibs.dsBmih.biHeight);
      HRESULT hr=AVIFileCreateStream(au-&gt;pfile, &amp;au-&gt;ps, &amp;strhdr);
      if (hr!=AVIERR_OK) {au-&gt;iserr=true; return hr;}
    }
    //Now we can add the frame
    HRESULT hr = AVIStreamWrite(au-&gt;psCompressed, au-&gt;nframe, 1, dibs.dsBm.bmBits, dibs.dsBmih.biSizeImage, AVIIF_KEYFRAME, NULL, NULL);
    if (hr!=AVIERR_OK) {au-&gt;iserr=true; return hr;}
    au-&gt;nframe++; return S_OK;
  } 
  </code></pre>
  
  <p>Thanks all.</p>