示例#1
1
        public void Start()
        {
            Debug.WriteLine("Starting...");

            if (aviStream != null || aviManager != null)
            {
                Debug.WriteLine("AviManager is not null!");
            }

            Sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);

            string time = System.DateTime.Now.ToString("hh'-'mm'-'ss", CultureInfo.CurrentUICulture.DateTimeFormat);
            string path = Path.Combine(KissHelper.GetPath(), "kiss-" + time + ".avi");

            aviManager = new AviManager(path, false);

            BitmapEncoder encoder = new JpegBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(ColorBitmap));
            MemoryStream s = new MemoryStream();
            encoder.Save(s);
            Bitmap b = (Bitmap)Image.FromStream(s);
            Avi.AVICOMPRESSOPTIONS opts = new Avi.AVICOMPRESSOPTIONS();
            opts.fccType = 0; // (UInt32)Avi.mmioStringToFOURCC("mrle", 0);
            opts.fccHandler = 1684633187;// (UInt32)Avi.mmioStringToFOURCC("MRLE", 0);

            opts.dwKeyFrameEvery = 0;
            opts.dwQuality = 10000;  // 0 .. 10000
            opts.dwFlags = 10;  // AVICOMRPESSF_KEYFRAMES = 4
            opts.dwBytesPerSecond = 204800;
            opts.lpFormat = new IntPtr(0);
            opts.cbFormat = 0;
            opts.lpParms = new IntPtr(0);
            opts.cbParms = 4;
            opts.dwInterleaveEvery = 0;

            aviStream = aviManager.AddVideoStream(opts, 1000.0 / Properties.Settings.Default.TickMsec, b);

            if (OnStart != null) OnStart(null);

            Debug.WriteLine("Started.");
        }
示例#2
0
        /// <summary>Add an empty video stream to the file</summary>
        /// <remarks>Compresses the stream without showing the codecs dialog</remarks>
        /// <param name="compressOptions">Compression options</param>
        /// <param name="frameRate">Frames per second</param>
        /// <param name="firstFrame">Image to write into the stream as the first frame</param>
        /// <returns>VideoStream object for the new stream</returns>
        public VideoStream AddVideoStream(Avi.AVICOMPRESSOPTIONS compressOptions, double frameRate, Bitmap firstFrame)
        {
            VideoStream stream = new VideoStream(aviFile, compressOptions, frameRate, firstFrame);

            streams.Add(stream);
            return(stream);
        }
示例#3
0
        /// <summary>Create a compressed stream from an uncompressed stream</summary>
        private void CreateCompressedStream()
        {
            //display the compression options dialog...
            Avi.AVICOMPRESSOPTIONS_CLASS options = new Avi.AVICOMPRESSOPTIONS_CLASS();
            options.fccType  = (uint)Avi.streamtypeVIDEO;
            options.lpParms  = IntPtr.Zero;
            options.lpFormat = IntPtr.Zero;
            Avi.AVISaveOptions(IntPtr.Zero, Avi.ICMF_CHOOSE_KEYFRAME | Avi.ICMF_CHOOSE_DATARATE, 1, ref this.aviStream,
                               ref options);
            Avi.AVISaveOptionsFree(1, ref options);
            //..or set static options

            /*Avi.AVICOMPRESSOPTIONS opts = new Avi.AVICOMPRESSOPTIONS();
             *          opts.fccType         = (UInt32)Avi.mmioStringToFOURCC("vids", 0);
             *          opts.fccHandler      = (UInt32)Avi.mmioStringToFOURCC("CVID", 0);
             *          opts.dwKeyFrameEvery = 0;
             *          opts.dwQuality       = 0;  // 0 .. 10000
             *          opts.dwFlags         = 0;  // AVICOMRPESSF_KEYFRAMES = 4
             *          opts.dwBytesPerSecond= 0;
             *          opts.lpFormat        = new IntPtr(0);
             *          opts.cbFormat        = 0;
             *          opts.lpParms         = new IntPtr(0);
             *          opts.cbParms         = 0;
             *          opts.dwInterleaveEvery = 0;*/
            //get the compressed stream
            this.compressOptions = options.ToStruct();
            int result = Avi.AVIMakeCompressedStream(out this.compressedStream, this.aviStream, ref this.compressOptions,
                                                     0);

            if (result != 0)
            {
                throw new Exception("Exception in AVIMakeCompressedStream: " + result.ToString());
            }
            this.SetFormat(this.compressedStream);
        }
示例#4
0
        /// <summary>Create a compressed stream from an uncompressed stream</summary>
        private void CreateCompressedStream(Avi.AVICOMPRESSOPTIONS options)
        {
            int result = Avi.AVIMakeCompressedStream(out this.compressedStream, this.aviStream, ref options, 0);

            if (result != 0)
            {
                throw new Exception("Exception in AVIMakeCompressedStream: " + result.ToString());
            }
            this.compressOptions = options;
            this.SetFormat(this.compressedStream);
        }
示例#5
0
 /// <summary>Copy all properties from one VideoStream to another one</summary>
 /// <remarks>Used by EditableVideoStream</remarks>
 /// <param name="frameSize"></param><param name="frameRate"></param>
 /// <param name="width"></param><param name="height"></param>
 /// <param name="countBitsPerPixel"></param>
 /// <param name="countFrames"></param><param name="compressOptions"></param>
 internal VideoStream(int frameSize, double frameRate, int width, int height, Int16 countBitsPerPixel, int countFrames, Avi.AVICOMPRESSOPTIONS compressOptions, bool writeCompressed)
 {
     this.frameSize         = frameSize;
     this.frameRate         = frameRate;
     this.width             = width;
     this.height            = height;
     this.countBitsPerPixel = countBitsPerPixel;
     this.countFrames       = countFrames;
     this.compressOptions   = compressOptions;
     this.writeCompressed   = writeCompressed;
     this.firstFrame        = 0;
 }
示例#6
0
        public void CaptureVideo()
        {
            b = new Bitmap(ScreenWidth, ScreenHeight);
            g = Graphics.FromImage(b);
            g.CopyFromScreen(Point.Empty, Point.Empty, Screen.PrimaryScreen.Bounds.Size);

            //auto set options for video recording
            //(description for each option availible at http://msdn.microsoft.com/en-us/library/windows/desktop/dd756832(v=vs.85).aspx)
            Avi.AVICOMPRESSOPTIONS aviOptions = new Avi.AVICOMPRESSOPTIONS();
            aviOptions.fccType = (uint)Avi.streamtypeVIDEO;
            //codec to use MSVC = Microsoft Video 1
            aviOptions.fccHandler = (uint)Avi.mmioStringToFOURCC("MSVC", 0);
            //quality option go from 0-10000
            aviOptions.dwQuality = 5000;

            //change aviOptions to "true" to enable the popup window asking for codec options eg. aviStream = aviManager.AddVideoStream(true, 4, b);
            aviStream = aviManager.AddVideoStream(aviOptions, 4, b);

            Bitmap tempBmp;

            while (!pause)
            {
                tempBmp = new Bitmap(ScreenWidth, ScreenHeight);
                g = Graphics.FromImage(tempBmp);
                g.CopyFromScreen(Point.Empty, Point.Empty, Screen.PrimaryScreen.Bounds.Size);
                g.FillEllipse(fillBrush, currentPoint.X, currentPoint.Y, 10, 10);
                g.FillRectangle(new SolidBrush(Color.Black), ScreenWidth - 100, ScreenHeight - 30, 100, 30);
                g.DrawString(elapsedTime, new Font("Arial", 12), new SolidBrush(Color.White), new PointF(ScreenWidth-95, ScreenHeight-25));

                if (tempBmp != null)
                {
                    try
                    {
                        aviStream.AddFrame(tempBmp);
                    }
                    catch
                    {
                        Bitmap bmp2 = tempBmp;
                        tempBmp.Dispose();
                        tempBmp = new Bitmap((Image)bmp2);
                        aviStream.AddFrame(tempBmp);
                    }
                }
                tempBmp.Dispose();
                Thread.Sleep(50);
            }
            aviManager.Close();
        }
示例#7
0
        private Avi.AVICOMPRESSOPTIONS createCompressedOptions()
        {
            Avi.AVICOMPRESSOPTIONS opts = new Avi.AVICOMPRESSOPTIONS();
            opts.fccType = (UInt32)Avi.mmioStringToFOURCC("vids", 0);
            opts.fccHandler = (UInt32)Avi.mmioStringToFOURCC("CVID", 0);
            opts.dwKeyFrameEvery = 0;
            opts.dwQuality = 0;  // 0 .. 10000
            opts.dwFlags = Avi.AVICOMPRESSF_DATARATE;  // AVICOMRPESSF_KEYFRAMES = 4
            opts.dwBytesPerSecond = 0;
            opts.lpFormat = new IntPtr(0);
            opts.cbFormat = 0;
            opts.lpParms = new IntPtr(0);
            opts.cbParms = 0;
            opts.dwInterleaveEvery = 0;

            return opts;
        }
示例#8
0
        /// <summary>Create a compressed stream from an uncompressed stream</summary>
        private void CreateCompressedStream(Avi.AVICOMPRESSOPTIONS options)
        {
            int result = Avi.AVIMakeCompressedStream(out compressedStream, aviStream, ref options, 0);
            if (result != 0) {
                throw new Exception("Exception in AVIMakeCompressedStream: " + result.ToString());
            }

            this.compressOptions = options;

            SetFormat(compressedStream);
        }
示例#9
0
        /// <summary>Create a compressed stream from an uncompressed stream</summary>
        private void CreateCompressedStream()
        {
            //display the compression options dialog...
            Avi.AVICOMPRESSOPTIONS_CLASS options = new Avi.AVICOMPRESSOPTIONS_CLASS();
            options.fccType = (uint)Avi.streamtypeVIDEO;

            options.lpParms = IntPtr.Zero;
            options.lpFormat = IntPtr.Zero;
            Avi.AVISaveOptions(IntPtr.Zero, Avi.ICMF_CHOOSE_KEYFRAME | Avi.ICMF_CHOOSE_DATARATE, 1, ref aviStream, ref options);
            Avi.AVISaveOptionsFree(1, ref options);

            //..or set static options
            /*Avi.AVICOMPRESSOPTIONS opts = new Avi.AVICOMPRESSOPTIONS();
            opts.fccType         = (UInt32)Avi.mmioStringToFOURCC("vids", 0);
            opts.fccHandler      = (UInt32)Avi.mmioStringToFOURCC("CVID", 0);
            opts.dwKeyFrameEvery = 0;
            opts.dwQuality       = 0;  // 0 .. 10000
            opts.dwFlags         = 0;  // AVICOMRPESSF_KEYFRAMES = 4
            opts.dwBytesPerSecond= 0;
            opts.lpFormat        = new IntPtr(0);
            opts.cbFormat        = 0;
            opts.lpParms         = new IntPtr(0);
            opts.cbParms         = 0;
            opts.dwInterleaveEvery = 0;*/

            //get the compressed stream
            this.compressOptions = options.ToStruct();
            int result = Avi.AVIMakeCompressedStream(out compressedStream, aviStream, ref compressOptions, 0);
            if(result != 0) {
                throw new Exception("Exception in AVIMakeCompressedStream: "+result.ToString());
            }

            SetFormat(compressedStream);
        }
示例#10
0
 /// <summary>Copy all properties from one VideoStream to another one</summary>
 /// <remarks>Used by EditableVideoStream</remarks>
 /// <param name="frameSize"></param><param name="frameRate"></param>
 /// <param name="width"></param><param name="height"></param>
 /// <param name="countBitsPerPixel"></param>
 /// <param name="countFrames"></param><param name="compressOptions"></param>
 internal VideoStream(int frameSize, double frameRate, int width, int height, Int16 countBitsPerPixel, int countFrames, Avi.AVICOMPRESSOPTIONS compressOptions, bool writeCompressed)
 {
     this.frameSize = frameSize;
     this.frameRate = frameRate;
     this.width = width;
     this.height = height;
     this.countBitsPerPixel = countBitsPerPixel;
     this.countFrames = countFrames;
     this.compressOptions = compressOptions;
     this.writeCompressed = writeCompressed;
     this.firstFrame = 0;
 }
示例#11
0
 /// <summary>Create a new stream</summary>
 private void CreateStream(Avi.AVICOMPRESSOPTIONS options)
 {
     CreateStreamWithoutFormat();
     CreateCompressedStream(options);
 }
示例#12
0
 /// <summary>Initialize a new VideoStream and add the first frame</summary>
 /// <param name="aviFile">The file that contains the stream</param>
 /// <param name="writeCompressed">true: create a compressed stream before adding frames</param>
 /// <param name="frameRate">Frames per second</param>
 /// <param name="firstFrame">Image to write into the stream as the first frame</param>
 public VideoStream(int aviFile, Avi.AVICOMPRESSOPTIONS compressOptions, double frameRate, Bitmap firstFrame)
 {
     Initialize(aviFile, true, frameRate, firstFrame);
     CreateStream(compressOptions);
     AddFrame(firstFrame);
 }
        protected override void CreateProjectRecording()
        {
            aviManager = new AviManager(recordFileName, false);
            aviCompressOption = new Avi.AVICOMPRESSOPTIONS();
            //Xvid MPEG-4 Compression
            aviCompressOption.cbParms = 3532;
            aviCompressOption.fccHandler = 1684633208;

            // setting up initial buffer parameter
            tempFileStream = new FileStream(tempFile, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            jpgCodecInfo = GetEncoder(ImageFormat.Jpeg);
            myEncoder = System.Drawing.Imaging.Encoder.Quality;
            encParameters = new EncoderParameters(1);
            encParameter = new EncoderParameter(myEncoder, 50L);
            encParameters.Param[0] = encParameter;
            // end setting up initial buffer parameter
        }