コード例 #1
0
ファイル: AviFile.cs プロジェクト: thaolt/screenrecorder
        private void SetupVideoCompressor(VideoCompressor compressor)
        {
            Avi32Interop.AVICOMPRESSOPTIONS compressorOptions = new Avi32Interop.AVICOMPRESSOPTIONS();
            uint fccHandler = compressor.FccHandler;

            compressorOptions.fccType    = Avi32Interop.ICTYPE_VIDEO;
            compressorOptions.fccHandler = fccHandler;
            compressorOptions.dwQuality  = (uint)compressor.Quality;
            // Open compressor
            IntPtr hic = Avi32Interop.ICOpen(Avi32Interop.ICTYPE_VIDEO, fccHandler, Avi32Interop.ICMODE_QUERY);

            if (hic == IntPtr.Zero)
            {
                int errorCode = Marshal.GetLastWin32Error();
                throw new AviException(errorCode, string.Format("ICOpen failed, error code = 0x{0:X8}.", errorCode));
            }
            // Get number of bytes required for params
            uint   cbParams = (uint)Avi32Interop.ICGetState(hic, IntPtr.Zero, 0);
            IntPtr pParams  = Marshal.AllocHGlobal((int)cbParams);

            try {
                // Get params
                int retval = Avi32Interop.ICGetState(hic, pParams, cbParams);
                compressorOptions.cbParms = cbParams;
                // If the Xvid Video Codec is selected, hack params to hide status window!
                if (string.Equals(compressor.FccHandlerString, xvidCodec))
                {
                    ModifyXvidParams(pParams, (int)cbParams);
                }
                compressorOptions.lpParms = pParams;
                compressorOptions.dwFlags = Avi32Interop.AVICOMPRESSF_VALID;
                // Close compressor
                Avi32Interop.ICClose(hic);
                // Make compressed stream
                int hr = Avi32Interop.AVIMakeCompressedStream(out this.pAviCompressedStream, this.pVideoStream,
                                                              ref compressorOptions, 0);
                if (hr != 0)
                {
                    throw new AviException(hr, string.Format("AVIMakeCompressedStream failed, error code = 0x{0:X8}.",
                                                             hr));
                }
            }
            finally {
                if (pParams != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(pParams);
                }
            }
        }
コード例 #2
0
ファイル: AviFile.cs プロジェクト: bspkrs/screenrecorder
 private void SetupVideoCompressor(VideoCompressor compressor)
 {
     Avi32Interop.AVICOMPRESSOPTIONS compressorOptions = new Avi32Interop.AVICOMPRESSOPTIONS();
      uint fccHandler = compressor.FccHandler;
      compressorOptions.fccType = Avi32Interop.ICTYPE_VIDEO;
      compressorOptions.fccHandler = fccHandler;
      compressorOptions.dwQuality = (uint)compressor.Quality;
      // Open compressor
      IntPtr hic = Avi32Interop.ICOpen(Avi32Interop.ICTYPE_VIDEO, fccHandler, Avi32Interop.ICMODE_QUERY);
      if (hic == IntPtr.Zero) {
     int errorCode = Marshal.GetLastWin32Error();
     throw new AviException(errorCode, string.Format("ICOpen failed, error code = 0x{0:X8}.", errorCode));
      }
      // Get number of bytes required for params
      uint cbParams = (uint)Avi32Interop.ICGetState(hic, IntPtr.Zero, 0);
      IntPtr pParams = Marshal.AllocHGlobal((int)cbParams);
      try {
     // Get params
     int retval = Avi32Interop.ICGetState(hic, pParams, cbParams);
     compressorOptions.cbParms = cbParams;
     // If the Xvid Video Codec is selected, hack params to hide status window!
     if (string.Equals(compressor.FccHandlerString, xvidCodec)) {
        ModifyXvidParams(pParams, (int)cbParams);
     }
     compressorOptions.lpParms = pParams;
     compressorOptions.dwFlags = Avi32Interop.AVICOMPRESSF_VALID;
     // Close compressor
     Avi32Interop.ICClose(hic);
     // Make compressed stream
     int hr = Avi32Interop.AVIMakeCompressedStream(out this.pAviCompressedStream, this.pVideoStream,
                                                   ref compressorOptions, 0);
     if (hr != 0) {
        throw new AviException(hr, string.Format("AVIMakeCompressedStream failed, error code = 0x{0:X8}.",
                                                 hr));
     }
      }
      finally {
     if (pParams != IntPtr.Zero) {
        Marshal.FreeHGlobal(pParams);
     }
      }
 }