Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        private void SetupVideo(DisplayFormat videoFormat, VideoCompressor compressor, int fps)
        {
            int colorDepth = Bitmap.GetPixelFormatSize(videoFormat.PixelFormat);
            int width      = videoFormat.Width;
            int height     = videoFormat.Height;
            // Calculate pitch
            int bytesPerPixel = colorDepth / 8;
            int pitch         = width * bytesPerPixel;
            int pitch_factor  = 4;

            if (pitch % pitch_factor != 0)
            {
                pitch = pitch + pitch_factor - pitch % pitch_factor;
            }
            // Create AVI Stream
            Avi32Interop.AVISTREAMINFO asf = new Avi32Interop.AVISTREAMINFO();
            asf.dwRate = fps;
            asf.dwSuggestedBufferSize = pitch * height * bytesPerPixel;
            asf.dwScale = 1;
            asf.fccType = Avi32Interop.streamtypeVIDEO;
            asf.szName  = null;
            asf.rcFrame = new Avi32Interop.RECT(0, 0, width, height);
            int hr = Avi32Interop.AVIFileCreateStream(this.pAviFile, out this.pVideoStream, ref asf);

            if (hr != 0)
            {
                throw new AviException("AVIFileCreateStream", hr);
            }
            // Set stream format
            Avi32Interop.BITMAPINFOHEADER bih = new Avi32Interop.BITMAPINFOHEADER();
            bih.biBitCount    = (ushort)colorDepth;
            bih.biCompression = 0; // BI_RGB
            bih.biHeight      = videoFormat.Height;
            bih.biPlanes      = 1;
            bih.biSize        = (uint)Marshal.SizeOf(bih);
            bih.biSizeImage   = (uint)(pitch * height * (colorDepth / 8));
            bih.biWidth       = videoFormat.Width;
            if (compressor != null && !compressor.Equals(VideoCompressor.None))
            {
                // Setup compressor
                this.SetupVideoCompressor(compressor);
                hr = Avi32Interop.AVIStreamSetFormat(this.pAviCompressedStream, 0, ref bih, Marshal.SizeOf(bih));
            }
            else
            {
                hr = Avi32Interop.AVIStreamSetFormat(this.pVideoStream, 0, ref bih, Marshal.SizeOf(bih));
            }
            if (hr != 0)
            {
                throw new AviException("AVIStreamSetFormat", hr);
            }
        }
 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);
      }
 }
Beispiel #4
0
 public static int ICCompressQuery(IntPtr hic, ref Avi32Interop.BITMAPINFOHEADER lpbiInput, IntPtr lpbiOutput)
 {
     return(Avi32Interop.ICSendMessage(hic, Avi32Interop.ICM_COMPRESS_QUERY, ref lpbiInput,
                                       (UIntPtr)((ulong)lpbiOutput)));
 }
Beispiel #5
0
 private void SetupVideo(DisplayFormat videoFormat, VideoCompressor compressor, int fps)
 {
     int colorDepth = Bitmap.GetPixelFormatSize(videoFormat.PixelFormat);
      int width = videoFormat.Width;
      int height = videoFormat.Height;
      // Calculate pitch
      int bytesPerPixel = colorDepth / 8;
      int pitch = width * bytesPerPixel;
      int pitch_factor = 4;
      if (pitch % pitch_factor != 0) {
     pitch = pitch + pitch_factor - pitch % pitch_factor;
      }
      // Create AVI Stream
      Avi32Interop.AVISTREAMINFO asf = new Avi32Interop.AVISTREAMINFO();
      asf.dwRate = fps;
      asf.dwSuggestedBufferSize = pitch * height * bytesPerPixel;
      asf.dwScale = 1;
      asf.fccType = Avi32Interop.streamtypeVIDEO;
      asf.szName = null;
      asf.rcFrame = new Avi32Interop.RECT(0, 0, width, height);
      int hr = Avi32Interop.AVIFileCreateStream(this.pAviFile, out this.pVideoStream, ref asf);
      if (hr != 0) {
     throw new AviException("AVIFileCreateStream", hr);
      }
      // Set stream format
      Avi32Interop.BITMAPINFOHEADER bih = new Avi32Interop.BITMAPINFOHEADER();
      bih.biBitCount = (ushort)colorDepth;
      bih.biCompression = 0; // BI_RGB
      bih.biHeight = videoFormat.Height;
      bih.biPlanes = 1;
      bih.biSize = (uint)Marshal.SizeOf(bih);
      bih.biSizeImage = (uint)(pitch * height * (colorDepth / 8));
      bih.biWidth = videoFormat.Width;
      if (compressor != null && !compressor.Equals(VideoCompressor.None)) {
     // Setup compressor
     this.SetupVideoCompressor(compressor);
     hr = Avi32Interop.AVIStreamSetFormat(this.pAviCompressedStream, 0, ref bih, Marshal.SizeOf(bih));
      }
      else {
     hr = Avi32Interop.AVIStreamSetFormat(this.pVideoStream, 0, ref bih, Marshal.SizeOf(bih));
      }
      if (hr != 0) {
     throw new AviException("AVIStreamSetFormat", hr);
      }
 }