Esempio n. 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);
        }
Esempio n. 2
0
        private int GetMaxEncodedSize()
        {
            var inHeader  = inBitmapInfo;
            var outHeader = outBitmapInfo;

            return(VfwApi.ICSendMessage(compressorHandle, VfwApi.ICM_COMPRESS_GET_SIZE, ref inHeader, ref outHeader));
        }
Esempio n. 3
0
        private void StartCompression()
        {
            var inHeader  = inBitmapInfo;
            var outHeader = outBitmapInfo;
            var result    = VfwApi.ICSendMessage(compressorHandle, VfwApi.ICM_COMPRESS_BEGIN, ref inHeader, ref outHeader);

            CheckICResult(result);

            needEnd           = true;
            framesFromLastKey = keyFrameRate;
        }
Esempio n. 4
0
        private void InitCompressFramesInfo(double fps, int frameCount)
        {
            var info = new VfwApi.CompressFramesInfo
            {
                StartFrame = 0,
                FrameCount = frameCount,
                Quality    = quality,
                KeyRate    = keyFrameRate,
            };

            AviUtils.SplitFrameRate((decimal)fps, out info.FrameRateNumerator, out info.FrameRateDenominator);

            var result = VfwApi.ICSendMessage(compressorHandle, VfwApi.ICM_COMPRESS_FRAMES_INFO, ref info, Marshal.SizeOf(typeof(VfwApi.CompressFramesInfo)));

            CheckICResult(result);
        }
Esempio n. 5
0
        private void EndCompression()
        {
            var result = VfwApi.ICSendMessage(compressorHandle, VfwApi.ICM_COMPRESS_END, IntPtr.Zero, IntPtr.Zero);

            CheckICResult(result);
        }