Inheritance: AForge.Video.VFW.AVIWriter
Exemplo n.º 1
0
        private void StopCapture()
        {
            mMutexCapture.WaitOne();
            mCaptureElapse        = 0;
            this.mIntervalsToSave = 0;
            if (mAVIWriter != null)
            {
                try
                {
                    FileInfo fi = new FileInfo(mAVIWriter.FileName);
                    mAVIWriter.Dispose();
                    mAVIWriter = null;

                    this.CaptureCount++;

                    DateTime n = DateTime.Now;
                    string   s = "" + n.Hour + ":" + n.Minute + ":" + n.Second;
                    this.toolStripStatusLabelCapture.Text = string.Format(Translator.Instance.T("录像结束({0})"), s);

                    this.CameraClass.Capturing = false;

                    AVIClass avi = new AVIClass(fi.FullName, this.CameraClass);
                    avi.Mark = RecordMark.UNREAD;

                    this.OnCameraViewRecordFinished(new CameraViewCaptureEventArgs(this));
                }
                catch (Exception)
                {
                }
            }
            mMutexCapture.ReleaseMutex();
        }
Exemplo n.º 2
0
        private void StopCapture()
        {
            mMutexCapture.WaitOne();
            mCaptureElapse = 0;
            this.mIntervalsToSave = 0;
            if (mAVIWriter != null)
            {
                try
                {
                    FileInfo fi = new FileInfo(mAVIWriter.FileName);
                    mAVIWriter.Dispose();
                    mAVIWriter = null;

                    this.CaptureCount++;

                    DateTime n = DateTime.Now;
                    string s = "" + n.Hour + ":" + n.Minute + ":" + n.Second;
                    this.toolStripStatusLabelCapture.Text = string.Format(Translator.Instance.T("录像结束({0})"), s);

                    this.CameraClass.Capturing = false;

                    AVIClass avi = new AVIClass(fi.FullName, this.CameraClass);
                    avi.Mark = RecordMark.UNREAD;

                    this.OnCameraViewRecordFinished(new CameraViewCaptureEventArgs(this));
                }
                catch (Exception)
                {
                }
            }
            mMutexCapture.ReleaseMutex();
        }
Exemplo n.º 3
0
        // On new frame
        private void camera_NewFrame(object sender, System.EventArgs e)
        {
            this.mHasFrame = true;
            if (this.EditMode == true || this.CameraClass == null || (this.CameraClass.Capture == CAPTUREFLAG.NOCAPTURE))
            {
                return;
            }

            mMutexCapture.WaitOne();
            if ((this.mIntervalsToSave > 0) || (this.CameraClass.Capture == CAPTUREFLAG.ALWAYS))
            {
                // lets save the frame
                if (mAVIWriter == null && MotionConfiguration.Instance.StorageIsValid)
                {
                    // create file name
                    Motion.Core.DateTimeEx date = new Motion.Core.DateTimeEx();
                    String fileName             = String.Format("{0}.{1}.{2}.avi", this.CameraClass.ID, (int)RecordMark.INVALID, date.TimeStamp);
                    try
                    {
                        // create AVI writer
                        mAVIWriter = new AVIWriterEx(this.CameraClass.Codec);
                        // open AVI file
                        mAVIWriter.Open(MotionConfiguration.Instance.StorageAVI + @"\" + fileName, cameraWindow.Camera.Width, cameraWindow.Camera.Height);

                        DateTime n = DateTime.Now;
                        string   s = "" + n.Hour + ":" + n.Minute + ":" + n.Second;
                        this.toolStripStatusLabelCapture.Text = string.Format(Translator.Instance.T("录像开始 ({0})"), s);
                        this.CameraClass.Capturing            = true;
                        this.OnCameraViewRecordStarted(new CameraViewCaptureEventArgs(this));

                        mCaptureElapse = date.TimeStamp;
                    }
                    catch (Exception)
                    {
                        if (mAVIWriter != null)
                        {
                            mAVIWriter.Dispose();
                            mAVIWriter = null;
                        }
                        this.toolStripStatusLabelCapture.Text = Translator.Instance.T("录像失败");
                        this.CameraClass.Capturing            = false;
                        this.mCaptureElapse = 0;
                        mMutexCapture.ReleaseMutex();
                        return;
                    }
                }

                Camera camera = cameraWindow.Camera;
                if (camera != null && mAVIWriter != null)
                {
                    Bitmap b = camera.LastFrame;
                    if (b != null)
                    {
                        try
                        {
                            if (this.ShowBanner)
                            {
                                Bitmap bmp = CameraBanner.Render(b, this.CameraClass.Name, true);
                                mAVIWriter.AddFrame(bmp);
                            }
                            else
                            {
                                mAVIWriter.AddFrame(b);
                            }
                        }
                        catch (Exception)
                        {
                            this.toolStripStatusLabelCapture.Text = Translator.Instance.T("录像失败");
                            //OnCameraViewLog(new CameraViewLogEventArgs(Motion.Core.LogLevel.LOG_ERROR, ex.Message, this));
                            //MessageBox.Show(ex.Message + "\n" + ex.StackTrace.ToString(), this.Camera.Name);
                        }
                    }
                }
            }
            mMutexCapture.ReleaseMutex();
        }
Exemplo n.º 4
0
        // On new frame
        private void camera_NewFrame(object sender, System.EventArgs e)
        {
            this.mHasFrame = true;
            if (this.EditMode == true || this.CameraClass == null || (this.CameraClass.Capture == CAPTUREFLAG.NOCAPTURE))
            {
                return;
            }

            mMutexCapture.WaitOne();
            if ((this.mIntervalsToSave > 0) || (this.CameraClass.Capture == CAPTUREFLAG.ALWAYS))
            {
                // lets save the frame
                if (mAVIWriter == null && MotionConfiguration.Instance.StorageIsValid)
                {
                    // create file name
                    Motion.Core.DateTimeEx date = new Motion.Core.DateTimeEx();
                    String fileName = String.Format("{0}.{1}.{2}.avi", this.CameraClass.ID, (int)RecordMark.INVALID, date.TimeStamp);
                    try
                    {
                        // create AVI writer
                        mAVIWriter = new AVIWriterEx(this.CameraClass.Codec);
                        // open AVI file
                        mAVIWriter.Open(MotionConfiguration.Instance.StorageAVI + @"\" + fileName, cameraWindow.Camera.Width, cameraWindow.Camera.Height);

                        DateTime n = DateTime.Now;
                        string s = "" + n.Hour + ":" + n.Minute + ":" + n.Second;
                        this.toolStripStatusLabelCapture.Text = string.Format(Translator.Instance.T("录像开始 ({0})"), s);
                        this.CameraClass.Capturing = true;
                        this.OnCameraViewRecordStarted(new CameraViewCaptureEventArgs(this));

                        mCaptureElapse = date.TimeStamp;
                    }
                    catch (Exception)
                    {
                        if (mAVIWriter != null)
                        {
                            mAVIWriter.Dispose();
                            mAVIWriter = null;
                        }
                        this.toolStripStatusLabelCapture.Text = Translator.Instance.T("录像失败");
                        this.CameraClass.Capturing = false;
                        this.mCaptureElapse = 0;
                        mMutexCapture.ReleaseMutex();
                        return;
                    }
                }

                Camera camera = cameraWindow.Camera;
                if (camera != null && mAVIWriter != null)
                {
                    Bitmap b = camera.LastFrame;
                    if (b != null)
                    {
                        try
                        {
                            if (this.ShowBanner)
                            {
                                Bitmap bmp = CameraBanner.Render(b, this.CameraClass.Name, true);
                                mAVIWriter.AddFrame(bmp);
                            }
                            else
                            {
                                mAVIWriter.AddFrame(b);
                            }
                        }
                        catch (Exception)
                        {
                            this.toolStripStatusLabelCapture.Text = Translator.Instance.T("录像失败");
                            //OnCameraViewLog(new CameraViewLogEventArgs(Motion.Core.LogLevel.LOG_ERROR, ex.Message, this));
                            //MessageBox.Show(ex.Message + "\n" + ex.StackTrace.ToString(), this.Camera.Name);
                        }
                    }
                }
            }
            mMutexCapture.ReleaseMutex();
        }