Beispiel #1
0
        private static IntPtr GetCompressor(VfwApi.BitmapInfoHeader inBitmapInfo, VfwApi.BitmapInfoHeader outBitmapInfo, out VfwApi.CompressorInfo compressorInfo)
        {
            // Using ICLocate is time-consuming. Besides, it does not clean up something, so the process does not terminate on exit.
            // Instead open a specific codec and query it for needed features.

            var compressorHandle = VfwApi.ICOpen((uint)KnownFourCCs.CodecTypes.Video, outBitmapInfo.Compression, VfwApi.ICMODE_COMPRESS);

            if (compressorHandle != IntPtr.Zero)
            {
                var inHeader  = inBitmapInfo;
                var outHeader = outBitmapInfo;
                var result    = VfwApi.ICSendMessage(compressorHandle, VfwApi.ICM_COMPRESS_QUERY, ref inHeader, ref outHeader);

                if (result == VfwApi.ICERR_OK)
                {
                    var infoSize = VfwApi.ICGetInfo(compressorHandle, out compressorInfo, Marshal.SizeOf(typeof(VfwApi.CompressorInfo)));
                    if (infoSize > 0 && compressorInfo.SupportsFastTemporalCompression)
                    {
                        return(compressorHandle);
                    }
                }

                VfwApi.ICClose(compressorHandle);
            }

            compressorInfo = new VfwApi.CompressorInfo();
            return(IntPtr.Zero);
        }
Beispiel #2
0
        /// <summary>
        /// Releases all unmanaged resources used by the encoder.
        /// </summary>
        public void Dispose()
        {
            if (!isDisposed)
            {
                if (needEnd)
                {
                    EndCompression();
                }

                if (compressorHandle != IntPtr.Zero)
                {
                    VfwApi.ICClose(compressorHandle);
                }

                isDisposed = true;
                GC.SuppressFinalize(this);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Gets info about the supported codecs that are installed on the system.
        /// </summary>
        public static CodecInfo[] GetAvailableCodecs()
        {
            var result = new List <CodecInfo>();

            var inBitmapInfo = CreateBitmapInfo(8, 8, 32, KnownFourCCs.Codecs.Uncompressed);

            inBitmapInfo.ImageSize = (uint)4;

            foreach (var codec in DefaultCodecPreference)
            {
                var outBitmapInfo = CreateBitmapInfo(8, 8, 24, codec);
                VfwApi.CompressorInfo compressorInfo;
                var compressorHandle = GetCompressor(inBitmapInfo, outBitmapInfo, out compressorInfo);
                if (compressorHandle != IntPtr.Zero)
                {
                    VfwApi.ICClose(compressorHandle);
                    result.Add(new CodecInfo(codec, compressorInfo.Description));
                }
            }

            return(result.ToArray());
        }