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);
        }
Beispiel #3
0
 public void GetFrameClose()
 {
     isFrameOpen = false;
     if (getFrameObject != 0)
     {
         AviInterop.AVIStreamGetFrameClose(getFrameObject);
         getFrameObject = 0;
     }
 }
Beispiel #4
0
        public void Close()
        {
            foreach (AviStream stream in streams)
            {
                stream.Close();
            }

            AviInterop.AVIFileRelease(aviFile);
            AviInterop.AVIFileExit();
        }
Beispiel #5
0
        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));
            }
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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;
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
		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;
		}
Beispiel #11
0
        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);
        }
Beispiel #12
0
 public virtual void Close()
 {
     AviInterop.AVIStreamRelease(StreamPointer);
 }