Esempio n. 1
0
        /// <summary>Opens an AVI file and creates a GetFrame object</summary>
        /// <param name="fileName">Name of the AVI file</param>
        public void Open(string fileName)
        {
            //Intitialize AVI library
            Avi.AVIFileInit();

            //Open the file
            int result = Avi.AVIFileOpen(
                ref aviFile, fileName,
                Avi.OF_SHARE_DENY_WRITE, 0);

            if (result != 0)
            {
                throw new Exception("Exception in AVIFileOpen: " + result.ToString());
            }

            //Get the video stream
            result = Avi.AVIFileGetStream(
                aviFile,
                out aviStream,
                Avi.StreamtypeVIDEO, 0);

            if (result != 0)
            {
                throw new Exception("Exception in AVIFileGetStream: " + result.ToString());
            }

            firstFrame  = Avi.AVIStreamStart(aviStream.ToInt32());
            countFrames = Avi.AVIStreamLength(aviStream.ToInt32());

            streamInfo = new Avi.AVISTREAMINFO();
            result     = Avi.AVIStreamInfo(aviStream.ToInt32(), ref streamInfo, Marshal.SizeOf(streamInfo));

            if (result != 0)
            {
                throw new Exception("Exception in AVIStreamInfo: " + result.ToString());
            }

            //Open frames

            Avi.BITMAPINFOHEADER bih = new Avi.BITMAPINFOHEADER();
            bih.biBitCount      = 24;
            bih.biClrImportant  = 0;
            bih.biClrUsed       = 0;
            bih.biCompression   = 0;           //BI_RGB;
            bih.biHeight        = (Int32)streamInfo.rcFrame.bottom;
            bih.biWidth         = (Int32)streamInfo.rcFrame.right;
            bih.biPlanes        = 1;
            bih.biSize          = (UInt32)Marshal.SizeOf(bih);
            bih.biXPelsPerMeter = 0;
            bih.biYPelsPerMeter = 0;

            getFrameObject = Avi.AVIStreamGetFrameOpen(aviStream, ref bih);             //force function to return 24bit DIBS
            //getFrameObject = Avi.AVIStreamGetFrameOpen(aviStream, 0); //return any bitmaps
            if (getFrameObject == 0)
            {
                throw new Exception("Exception in AVIStreamGetFrameOpen!");
            }
        }
Esempio n. 2
0
        /// <summary>Creates a new video stream in the AVI file</summary>
        private void CreateStream()
        {
            Avi.AVISTREAMINFO strhdr = new Avi.AVISTREAMINFO();
            strhdr.fccType               = fccType;
            strhdr.fccHandler            = fccHandler;
            strhdr.dwScale               = 1;
            strhdr.dwRate                = frameRate;
            strhdr.dwSuggestedBufferSize = (UInt32)(height * stride);
            strhdr.dwQuality             = 10000;             //highest quality! Compression destroys the hidden message
            strhdr.rcFrame.bottom        = (UInt32)height;
            strhdr.rcFrame.right         = (UInt32)width;
            strhdr.szName                = new UInt16[64];

            int result = Avi.AVIFileCreateStream(aviFile, out aviStream, ref strhdr);

            if (result != 0)
            {
                throw new Exception("Error in AVIFileCreateStream: " + result.ToString());
            }

            //define the image format
            Avi.BITMAPINFOHEADER bi = new Avi.BITMAPINFOHEADER();
            bi.biSize      = (UInt32)Marshal.SizeOf(bi);
            bi.biWidth     = (Int32)width;
            bi.biHeight    = (Int32)height;
            bi.biPlanes    = 1;
            bi.biBitCount  = 32;
            bi.biSizeImage = (UInt32)(stride * height);
            oldStream      = aviStream;
            aviStream      = CreateCompressedStream(aviStream);
            result         = Avi.AVIStreamSetFormat(aviStream, 0, ref bi, Marshal.SizeOf(bi));
            if (result != 0)
            {
                throw new Exception("Error in AVIStreamSetFormat: " + result.ToString());
            }
        }