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!");
            }
        }