public byte[] GetStreamData() { int streamLength; int samples; uint result = AviInterop.AVIStreamRead(StreamPointer, sampleOffset, AviInterop.AvistreamreadConvenient, IntPtr.Zero, 0, out streamLength, out samples); if (result != 0) { throw new Exception("Exception in AVIStreamRead: " + AviErrors.GetError(result)); } IntPtr waveData = Marshal.AllocHGlobal(streamLength); result = AviInterop.AVIStreamRead(StreamPointer, sampleOffset, samples, waveData, streamLength, out streamLength, out samples); if (result != 0) { throw new Exception("Exception in AVIStreamRead: " + AviErrors.GetError(result)); } sampleOffset += samples; var resultData = new byte[streamLength]; Marshal.Copy(waveData, resultData, 0, streamLength); Marshal.FreeHGlobal(waveData); return(resultData); }
public AudioStream(int filePtr, IntPtr streamPtr) : base(filePtr, streamPtr) { int size = Marshal.SizeOf(waveFormat); AviInterop.AVIStreamReadFormat(StreamPointer, 0, ref waveFormat, ref size); }
public void GetFrameClose() { isFrameOpen = false; if (getFrameObject != 0) { AviInterop.AVIStreamGetFrameClose(getFrameObject); getFrameObject = 0; } }
public void Close() { foreach (AviStream stream in streams) { stream.Close(); } AviInterop.AVIFileRelease(aviFile); AviInterop.AVIFileExit(); }
public AviFile(String filepath) { AviInterop.AVIFileInit(); uint result = AviInterop.AVIFileOpen(ref aviFile, filepath, AviInterop.OfRead, 0); if (result > 0) { throw new Exception("Exception in AVIFileOpen: " + AviErrors.GetError(result)); } }
protected AviInterop.StreamInfo GetStreamInfo() { var streamInfo = new AviInterop.StreamInfo(); uint result = AviInterop.AVIStreamInfo(StreamPointer, ref streamInfo, Marshal.SizeOf(streamInfo)); if (result != 0) { throw new Exception("Exception in VideoStreamInfo: " + AviErrors.GetError(result)); } return(streamInfo); }
public AudioStream GetAudioStream() { IntPtr aviStream; uint result = AviInterop.AVIFileGetStream(aviFile, out aviStream, AviInterop.StreamtypeAudio, 0); if (result > 0) { throw new Exception("Exception in AVIFileGetStream: " + AviErrors.GetError(result)); } var stream = new AudioStream(aviFile, aviStream); streams.Add(stream); return(stream); }
public void GetFrameOpen() { var bih = new AviInterop.BitmapInfoHeader { biBitCount = CountBitsPerPixel, biPlanes = 1 }; bih.biSize = Marshal.SizeOf(bih); getFrameObject = AviInterop.AVIStreamGetFrameOpen(StreamPointer, ref bih); if (getFrameObject == 0) { throw new CodecNotFoundException(); } isFrameOpen = true; }
public VideoStream(int filePtr, IntPtr streamPtr) : base(filePtr, streamPtr) { var bih = new AviInterop.BitmapInfoHeader(); int size = Marshal.SizeOf(bih); AviInterop.AVIStreamReadFormat(StreamPointer, 0, ref bih, ref size); AviInterop.StreamInfo streamInfo = GetStreamInfo(); FrameRate = streamInfo.dwRate / (float)streamInfo.dwScale; Width = streamInfo.rcFrame.right; Height = streamInfo.rcFrame.bottom; FrameSize = bih.biSizeImage; CountBitsPerPixel = CalculateBitsPerPixel(bih.biBitCount); FirstFrame = AviInterop.AVIStreamStart(StreamPointer); CountFrames = AviInterop.AVIStreamLength(StreamPointer); }
public byte[] GetStreamData(int position, out AviInterop.BitmapInfoHeader header) { if (!isFrameOpen) throw new Exception("GetFrameOpen needs to be called before GetStreamData!"); int dib = AviInterop.AVIStreamGetFrame(getFrameObject, FirstFrame + position); header = new AviInterop.BitmapInfoHeader(); header = (AviInterop.BitmapInfoHeader)Marshal.PtrToStructure((IntPtr)dib, header.GetType()); if (header.biSizeImage < 1) throw new Exception("Exception in VideoStreamGetFrame"); int bihSize = Marshal.SizeOf(header); var bitmapData = new byte[header.biSizeImage + (header.biBitCount < 16 ? PaletteSize : 0)]; Marshal.Copy((IntPtr)(dib + bihSize), bitmapData, 0, bitmapData.Length); return bitmapData; }
public byte[] GetStreamData(int position, out AviInterop.BitmapInfoHeader header) { if (!isFrameOpen) { throw new Exception("GetFrameOpen needs to be called before GetStreamData!"); } int dib = AviInterop.AVIStreamGetFrame(getFrameObject, FirstFrame + position); header = new AviInterop.BitmapInfoHeader(); header = (AviInterop.BitmapInfoHeader)Marshal.PtrToStructure((IntPtr)dib, header.GetType()); if (header.biSizeImage < 1) { throw new Exception("Exception in VideoStreamGetFrame"); } int bihSize = Marshal.SizeOf(header); var bitmapData = new byte[header.biSizeImage + (header.biBitCount < 16 ? PaletteSize : 0)]; Marshal.Copy((IntPtr)(dib + bihSize), bitmapData, 0, bitmapData.Length); return(bitmapData); }
public virtual void Close() { AviInterop.AVIStreamRelease(StreamPointer); }