Ejemplo 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!");
            }
        }
Ejemplo n.º 2
0
        private UInt32 fccHandler = 1668707181;          //"Microsoft Video 1" - Use CVID for default codec: (UInt32)Avi.mmioStringToFOURCC("CVID", 0);

        /// <summary>Creates a new AVI file</summary>
        /// <param name="fileName">Name of the new AVI file</param>
        /// <param name="frameRate">Frames per second</param>
        /// <param name="width">Width</param><param name="height">Height</param>
        public void Open(string fileName, UInt32 frameRate)
        {
            this.frameRate = frameRate;

            Avi.AVIFileInit();

            int hr = Avi.AVIFileOpen(
                ref aviFile, fileName,
                4097 /* OF_WRITE | OF_CREATE (winbase.h) */, 0);

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