/// <summary>Initialize a VideoStream for an existing stream</summary> /// <param name="aviFile">The file that contains the stream</param> /// <param name="aviStream">An IAVISTREAM from [aviFile]</param> public VideoStream(int aviFile, IntPtr aviStream) { this.aviFile = aviFile; this.aviStream = aviStream; Avi.AVISTREAMINFO streamInfo = GetStreamInfo(aviStream); //Avi.BITMAPINFOHEADER bih = new Avi.BITMAPINFOHEADER(); //int size = Marshal.SizeOf(bih); Avi.BITMAPINFO bih = new Avi.BITMAPINFO(); int size = Marshal.SizeOf(bih.bmiHeader); Avi.AVIStreamReadFormat(aviStream, 0, ref bih, ref size); if (bih.bmiHeader.biBitCount < 24) { size = Marshal.SizeOf(bih.bmiHeader) + Avi.PALETTE_SIZE; Avi.AVIStreamReadFormat(aviStream, 0, ref bih, ref size); CopyPalette(bih.bmiColors); } this.frameRate = (float)streamInfo.dwRate / (float)streamInfo.dwScale; this.width = (int)streamInfo.rcFrame.right; this.height = (int)streamInfo.rcFrame.bottom; this.frameSize = bih.bmiHeader.biSizeImage; this.countBitsPerPixel = bih.bmiHeader.biBitCount; this.firstFrame = Avi.AVIStreamStart(aviStream.ToInt32()); this.countFrames = Avi.AVIStreamLength(aviStream.ToInt32()); }
/// <summary>Returns all data needed to copy the stream</summary> /// <remarks>Do not forget to call Marshal.FreeHGlobal and release the raw data pointer</remarks> /// <param name="streamInfo">Receives the header information</param> /// <param name="format">Receives the format</param> /// <param name="streamLength">Receives the length of the stream</param> /// <returns>Pointer to the wave data</returns> public IntPtr GetStreamData(ref Avi.AVISTREAMINFO streamInfo, ref Avi.PCMWAVEFORMAT format, ref int streamLength) { streamInfo = GetStreamInfo(); format = GetFormat(); //length in bytes = length in samples * length of a sample streamLength = Avi.AVIStreamLength(aviStream.ToInt32()) * streamInfo.dwSampleSize; IntPtr waveData = Marshal.AllocHGlobal(streamLength); int result = Avi.AVIStreamRead(aviStream, 0, streamLength, waveData, streamLength, 0, 0); if (result != 0) { throw new Exception("Exception in AVIStreamRead: " + result.ToString()); } return(waveData); }