private void ConfigureMediaWriter(int width, int height, Guid mediaSubType, short bitCount)
        {
            AMMediaType     mediaType = new AMMediaType();
            VideoInfoHeader videoInfo = new VideoInfoHeader();

            // Create the VideoInfoHeader using info from the bitmap
            videoInfo.BmiHeader.Size   = Marshal.SizeOf(typeof(BitmapInfoHeader));
            videoInfo.BmiHeader.Width  = width;
            videoInfo.BmiHeader.Height = height;
            videoInfo.BmiHeader.Planes = 1;

            // compression thru clrimportant don't seem to be used. Init them anyway
            videoInfo.BmiHeader.Compression   = 0;
            videoInfo.BmiHeader.ImageSize     = 0;
            videoInfo.BmiHeader.XPelsPerMeter = 0;
            videoInfo.BmiHeader.YPelsPerMeter = 0;
            videoInfo.BmiHeader.ClrUsed       = 0;
            videoInfo.BmiHeader.ClrImportant  = 0;

            mediaType.subType            = mediaSubType;
            videoInfo.BmiHeader.BitCount = bitCount;

            videoInfo.SrcRect             = new Rectangle(0, 0, width, height);
            videoInfo.TargetRect          = videoInfo.SrcRect;
            videoInfo.BmiHeader.ImageSize = width * height * (videoInfo.BmiHeader.BitCount / 8);
            videoInfo.BitRate             = videoInfo.BmiHeader.ImageSize * Constants.VideoFrameRate;
            videoInfo.BitErrorRate        = 0;
            videoInfo.AvgTimePerFrame     = 10000 * 1000 / Constants.VideoFrameRate;

            mediaType.majorType           = MediaType.Video;
            mediaType.fixedSizeSamples    = true;
            mediaType.temporalCompression = false;
            mediaType.sampleSize          = videoInfo.BmiHeader.ImageSize;
            mediaType.formatType          = FormatType.VideoInfo;
            mediaType.unkPtr     = IntPtr.Zero;
            mediaType.formatSize = Marshal.SizeOf(typeof(VideoInfoHeader));

            // Lock the videoInfo structure, and put the pointer
            // into the mediatype structure
            GCHandle handle = GCHandle.Alloc(videoInfo, GCHandleType.Pinned);

            try
            {
                // Set the inputprops using the structures
                mediaType.formatPtr = handle.AddrOfPinnedObject();
                MediaProperties.SetMediaType(mediaType);
            }
            finally
            {
                handle.Free();
                mediaType.formatPtr = IntPtr.Zero;
            }

            // Now take the inputprops, and set them on the file writer
            MediaWriter.SetInputProps(VideoChannelIndex, MediaProperties);
        }