Exemple #1
0
            private void AddBitmapInternal(Bitmap bitmap)
            {
                //flip it.
                bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);

                BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                                                  ImageLockMode.ReadOnly, bitmap.PixelFormat);


                IntPtr outputStream = _aviStreamRef;

                if (_aviCompressedStreamRef != IntPtr.Zero)
                {
                    outputStream = _aviCompressedStreamRef;
                }

                int result = Avi.AVIStreamWrite(outputStream, _frameCount++, 1, data.Scan0,
                                                (Int32)(data.Stride * data.Height), 0, 0, 0);

                bitmap.UnlockBits(data);

                //reset it.
                bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);

                if (result != 0)
                {
                    throw new VideoStreamWriterException("Error adding bitmap to video stream.");
                }
            }
Exemple #2
0
 private void ReleaseFile()
 {
     if (_aviFileRef != IntPtr.Zero)
     {
         int result = Avi.AVIFileRelease(_aviFileRef);
         if (result != 0)
         {
             throw new VideoStreamWriterException("Error releasing Avi file.");
         }
     }
 }
Exemple #3
0
 private void ReleaseStream()
 {
     if (_aviStreamRef != IntPtr.Zero)
     {
         int result = Avi.AVIStreamRelease(_aviStreamRef);
         if (result != 0)
         {
             throw new VideoStreamWriterException("Error releasing Avi stream.");
         }
     }
 }
Exemple #4
0
            private void SetFormat(IntPtr aviStream)
            {
                Avi.BITMAPINFOHEADER info = GetImageFormat();

                int result = Avi.AVIStreamSetFormat(aviStream, 0, ref info, info.biSize);

                if (result != 0)
                {
                    throw new VideoStreamWriterException("Avi stream format could not be set.");
                }

                GC.KeepAlive(info);
            }
Exemple #5
0
            private void MakeStreamCompressed()
            {
                Avi.AVICOMPRESSOPTIONS compressOptions = GetCompressOptions();

                int result = Avi.AVIMakeCompressedStream(out _aviCompressedStreamRef, _aviStreamRef, ref compressOptions, 0);

                if (result != 0)
                {
                    throw new Exception("Failed to create compressed stream.");
                }

                GC.KeepAlive(compressOptions);

                SetFormat(_aviCompressedStreamRef);
            }
Exemple #6
0
            private void Open()
            {
                Avi.AVIFileInit();
                _initialized = true;

                IntPtr aviFileRef;
                int    result = Avi.AVIFileOpen(out aviFileRef, _fileName, Avi.OF_WRITE | Avi.OF_CREATE, 0);

                if (result != 0)
                {
                    throw new VideoStreamWriterException("Avi file could not be created.");
                }

                _aviFileRef = aviFileRef;
                CreateStream();
            }
Exemple #7
0
            public void Close()
            {
                try
                {
                    ReleaseCompressedStream();
                    ReleaseStream();
                    ReleaseFile();
                }
                finally
                {
                    _aviCompressedStreamRef = IntPtr.Zero;
                    _aviStreamRef           = IntPtr.Zero;
                    _aviFileRef             = IntPtr.Zero;

                    if (_initialized)
                    {
                        _initialized = false;
                        Avi.AVIFileExit();
                    }
                }
            }
Exemple #8
0
            private void CreateStream()
            {
                Avi.AVISTREAMINFO streamInfo = GetStreamInfo();

                int result = Avi.AVIFileCreateStream(_aviFileRef, out _aviStreamRef, ref streamInfo);

                if (result != 0)
                {
                    throw new VideoStreamWriterException("Avi stream could not be created.");
                }

                GC.KeepAlive(streamInfo);

                if (!Codec.SupportsQuality)
                {
                    SetFormat(_aviStreamRef);
                }
                else
                {
                    MakeStreamCompressed();
                }
            }