// Open an AVI file public void Open(string fname) { // close previous file Close(); // open file if (Win32.AVIFileOpen(out file, fname, Win32.OpenFileMode.ShareDenyWrite, IntPtr.Zero) != 0) { throw new ApplicationException("Failed opening file"); } // get first video stream if (Win32.AVIFileGetStream(file, out stream, Win32.mmioFOURCC("vids"), 0) != 0) { throw new ApplicationException("Failed getting video stream"); } // get stream info Win32.AVISTREAMINFO info = new Win32.AVISTREAMINFO(); Win32.AVIStreamInfo(stream, ref info, Marshal.SizeOf(info)); width = info.rcFrame.right; height = info.rcFrame.bottom; position = info.dwStart; start = info.dwStart; length = info.dwLength; rate = (float)info.dwRate / (float)info.dwScale; codec = Win32.decode_mmioFOURCC(info.fccHandler); // prepare decompressor Win32.BITMAPINFOHEADER bih = new Win32.BITMAPINFOHEADER(); bih.biSize = Marshal.SizeOf(bih.GetType()); bih.biWidth = width; bih.biHeight = height; bih.biPlanes = 1; bih.biBitCount = 24; bih.biCompression = 0; // BI_RGB // get frame open object if ((getFrame = Win32.AVIStreamGetFrameOpen(stream, ref bih)) == IntPtr.Zero) { bih.biHeight = -height; if ((getFrame = Win32.AVIStreamGetFrameOpen(stream, ref bih)) == IntPtr.Zero) { throw new ApplicationException("Failed initializing decompressor"); } } }