private VideoCompressor(uint fccHandler) { // Init bitmap info header Avi32Interop.BITMAPINFOHEADER bih = new Avi32Interop.BITMAPINFOHEADER(); bih.Init(); bih.biBitCount = bitCount; bih.biCompression = 0; bih.biWidth = bih.biHeight = biHeight; bih.biPlanes = 1; // Open compressor IntPtr hic = Avi32Interop.ICOpen(Avi32Interop.ICTYPE_VIDEO, fccHandler, Avi32Interop.ICMODE_QUERY); if (hic == IntPtr.Zero) { int errorCode = Marshal.GetLastWin32Error(); throw new AviException("ICOpen", errorCode); } try { // Check if compressor supports specified format int hr = Avi32Interop.ICCompressQuery(hic, ref bih, IntPtr.Zero); if (hr != Avi32Interop.ICERR_OK) { throw new AviException("ICCompressQuery", hr); } // Get compressor info Avi32Interop.ICINFO ici = new Avi32Interop.ICINFO(); ici.Init(); hr = Avi32Interop.ICGetInfo(hic, out ici, ici.biSize); if (hr != 0) { this.name = ici.szDescription; // Check quality support bool supportsQuality = (ici.dwFlags & Avi32Interop.VIDCF_QUALITY) == Avi32Interop.VIDCF_QUALITY; if (supportsQuality) { if (Avi32Interop.ICERR_OK == Avi32Interop.ICGetDefaultQuality(hic, ref this.quality)) { this.supportsQuality = true; } } else { this.quality = defaultQuality; } this.fccHandler = fccHandler; this.fccHandlerString = FccHandlerToString(fccHandler); } else { throw new AviException("ICGetInfo", hr); } } finally { Avi32Interop.ICClose(hic); } }
public bool Configure(IntPtr owner) { IntPtr hic = Avi32Interop.ICOpen(Avi32Interop.ICTYPE_VIDEO, this.fccHandler, Avi32Interop.ICMODE_QUERY); if (hic != IntPtr.Zero) { bool result = Avi32Interop.ICERR_OK == Avi32Interop.ICConfigure(hic, owner); Avi32Interop.ICClose(hic); return(result); } return(false); }
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); } } }