How to get AVICOMPRESSOPTIONS without AVISaveOptions Dialog?

2.2k views Asked by At

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?

1

There are 1 answers

2
Ernest Mallett On BEST ANSWER

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.