5

I am attempting to programmatically generate a AVI file from Bitmaps using an example I found somewhere online (can't remember the exact source).

Here is my code to get the options

    unsafe private void SetOptions() {

        AVICOMPRESSOPTIONS opts = new AVICOMPRESSOPTIONS();
        opts.fccType           = 0; //fccType_;
        opts.fccHandler        = 541215044;//0;//fccHandler_;
        opts.dwKeyFrameEvery   = 0;
        opts.dwQuality         = 0;  // 0 .. 10000
        opts.dwFlags           = 8;//0;  // AVICOMRPESSF_KEYFRAMES = 4
        opts.dwBytesPerSecond  = 0;
        opts.lpFormat          = (System.IntPtr)0; //new IntPtr(0);
        opts.cbFormat          = 0;
        opts.lpParms           = (System.IntPtr)0; //new IntPtr(0);
        opts.cbParms           = 3232;//0;
        opts.dwInterleaveEvery = 0;


        AVICOMPRESSOPTIONS* p = &opts;
        AVICOMPRESSOPTIONS** pp = &p;

        IntPtr x       = ps_;
        IntPtr* ptr_ps = &x;

        AVISaveOptions(0,0,1,ptr_ps,pp);

        // TODO: AVISaveOptionsFree(...)

        int hr = AVIMakeCompressedStream(out psCompressed_, ps_, ref opts, 0);
        if (hr != 0) {
            throw new AviException("AVIMakeCompressedStream");
        }

        BITMAPINFOHEADER bi    = new BITMAPINFOHEADER();
        bi.biSize         = 40;
        bi.biWidth        = (Int32) width_;
        bi.biHeight       = (Int32) height_;
        bi.biPlanes       = 1;
        bi.biBitCount     = 24;
        bi.biCompression  = 0;  // 0 = BI_RGB
        bi.biSizeImage    = stride_*height_;
        bi.biXPelsPerMeter= 0;
        bi.biYPelsPerMeter= 0;
        bi.biClrUsed      = 0;
        bi.biClrImportant = 0;

        hr = AVIStreamSetFormat(psCompressed_, 0, ref bi, 40);
        if (hr != 0) {
            throw new AviException("AVIStreamSetFormat",hr);
        }
    }

However I do not want to display the AVISaveOptions dialoge, and would much preffer to do it all in the backend, I have searched for hours but so far turned up nothing very helpful with the exception of this: https://groups.google.com/forum/#!topic/microsoft.public.win32.programmer.mmedia/jH0d3H2orOo

So my question is, how would I go about this without displaying a dialog, and/or how would I populate the compression options programmatically?

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • I also just came across [this article](http://msdn.microsoft.com/en-us/magazine/hh580739.aspx). Would it work if I created a similar function, serialized the data to a file, and then included this file with the assembly? – Ernest Mallett Dec 26 '13 at 11:56
  • You have all APIs for this, e.g. [Locating and Opening Compressors and Decompressors](http://msdn.microsoft.com/en-us/library/windows/desktop/dd757137%28v=vs.85%29.aspx). – Roman R. Dec 26 '13 at 17:18

1 Answers1

0

Wound up getting a list of all installed codecs through the registry and then creating a FourCC and using that to set the fccType and fccHandler.

  • 2
    @Emest Mallett: may you give some code that how you solved this? because I am also facing same problem – Aabha Aug 11 '14 at 05:15
  • @Emest Mallett: How you are setting values AVICOMPRESSION object ie. fccType, fccHandler etc? – Aabha Aug 11 '14 at 05:32