Example #1
0
 private void Window_Closed(object sender, EventArgs e)
 {
     //Stop and free the webcam object if application is closing
     if (videoSource != null && videoSource.IsRunning)
     {
         videoSource.SignalToStop();
         videoSource = null;
     }
     if (CaptureSource != null)
     {
         CaptureSource.SignalToStop();
         CaptureSource = null;
     }
 }
Example #2
0
 private void btParse_Click(object sender, RoutedEventArgs e)
 {
     btBegin.Visibility = Visibility.Visible;
     btParse.Visibility = Visibility.Collapsed;
     isParsing          = true;
     videoStreamer.SignalToStop();
 }
        public static void Stop()
        {
            if (!Assistant.Engine.CDepPresent)
            {
                return;
            }

            try
            {
                if (m_videostream != null)
                {
                    m_videostream.SignalToStop();
                    m_videostream.WaitForStop();
                    m_videostream = null;
                }

                if (m_filewriter != null)
                {
                    m_filewriter.Close();
                    m_filewriter = null;
                }
            }
            catch { }
            m_recording = false;
        }
Example #4
0
        private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            if (this._isRecording)
            {
                this._frameCount++;
                this._writer.WriteVideoFrame(eventArgs.Frame);

                this.lb_1.Invoke(new Action(() =>
                {
                    lb_1.Text = string.Format(@"Frames: {0}", _frameCount);
                }));

                this.lb_stopWatch.Invoke(new Action(() =>
                {
                    this.lb_stopWatch.Text = _stopWatch.Elapsed.ToString();
                }));
            }
            else
            {
                _stopWatch.Reset();
                Thread.Sleep(500);
                _streamVideo.SignalToStop();
                Thread.Sleep(500);
                _writer.Close();
            }
        }
        private void StopRecordingButton_Click(object sender, EventArgs e)
        {
            stream.SignalToStop();
            writer.Close();

            Application.Exit();
        }
Example #6
0
        private void Video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            if (_isRecording)
            {
                _frameCount++;

                Bitmap frame = eventArgs.Frame;


                Graphics graphics = Graphics.FromImage(frame);


                CURSORINFO pci;
                pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));

                if (GetCursorInfo(out pci))
                {
                    if (pci.flags == CURSOR_SHOWING)
                    {
                        int x = pci.ptScreenPos.x - screenLeft;
                        int y = pci.ptScreenPos.y - screenTop;

                        Color c      = Color.Yellow;
                        float width  = 2;
                        int   radius = 30;
                        if ((MouseButtons & MouseButtons.Left) != 0 || (MouseButtons & MouseButtons.Right) != 0)
                        {
                            c      = Color.OrangeRed;
                            width  = 4;
                            radius = 35;
                        }
                        Pen p = new Pen(c, width);

                        graphics.DrawEllipse(p, x - radius / 2, y - radius / 2, radius, radius);
                        DrawIcon(graphics.GetHdc(), x, y, pci.hCursor);
                        graphics.ReleaseHdc();
                    }
                }
                if (useArea)
                {
                    var destRect  = new Rectangle(Convert.ToInt32((_width - frame.Width) / 2), Convert.ToInt32((_height - frame.Height) / 2), frame.Width, frame.Height);
                    var destImage = new Bitmap(_width, _height);
                    destImage.SetResolution(frame.HorizontalResolution, frame.VerticalResolution);

                    graphics = Graphics.FromImage(destImage);
                    graphics.DrawImage(frame, destRect, 0, 0, frame.Width, frame.Height, GraphicsUnit.Pixel, null);
                    frame = destImage;
                }
                _writer.WriteVideoFrame(frame);
            }
            else
            {
                _stopWatch.Reset();
                Thread.Sleep(500);
                _streamVideo.SignalToStop();
                Thread.Sleep(500);
                _writer.Close();
            }
        }
Example #7
0
 /// <summary>
 /// 暂停按钮点击事件
 /// </summary>
 private void btParse_Click(object sender, RoutedEventArgs e)
 {
     btBegin.Visibility = Visibility.Visible;
     btParse.Visibility = Visibility.Collapsed;
     IsParsing          = true;
     parseTime          = DateTime.Now; //记录下暂停时间点
     VideoStreamer.SignalToStop();      //停止捕获桌面
 }
Example #8
0
 public void Stop()
 {
     _ScreenSource.SignalToStop();
     _ScreenSource.Stop();
     _CameraSource.SignalToStop();
     _CameraSource.Stop();
     _Writer.Close();
     _Writer.Dispose();
 }
        private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            if (this._isRecording)
            {
                this._frameCount++;

                //Get and save URL data
                this.GetURL();

                //Video time
                this._VideoTime = (int)Math.Round((double)this._frameCount * (double)1000 / (double)this._FPS);

                //Get data
                this._isGettingData = true;

                this._writer.WriteVideoFrame(eventArgs.Frame);

                this.lb_1.Dispatcher.Invoke(new Action(() =>
                {
                    lb_1.Content = string.Format(@"Frames: {0}", _frameCount);
                }));

                this.lb_stopWatch.Dispatcher.Invoke(new Action(() =>
                {
                    this.lb_stopWatch.Content = _stopWatch.Elapsed.ToString();
                }));
            }
            else
            {
                this._isGettingData = false;

                _stopWatch.Reset();
                Thread.Sleep(100);
                _streamVideo.SignalToStop();
                Thread.Sleep(100);
                _writer.Close();

                //Close Mouse and Keyboard Event
                Thread.Sleep(100);
                MouseKeyUnsubscribe();

                //Close Mouse and Eye Timer
                Thread.Sleep(100);
                _MouseGazeTimer.Stop();

                //Close DB save
                Thread.Sleep(100);
                this._DBSaver.DBDisconnect();

                System.Windows.Forms.MessageBox.Show("File saved!", "INFO");
            }
        }
Example #10
0
 private void closeScreenSource()
 {
     if (ScreenStream != null)
     {
         if (ScreenStream.IsRunning)
         {
             pBox_preview.SizeMode   = PictureBoxSizeMode.Normal;
             this.pBox_preview.Image = global::MorseCodeDecoder.Properties.Resources.startup;
             ScreenStream.SignalToStop();
             ScreenStream = null;
             processes    = null;
         }
     }
 }
 private void button1_Click(object sender, EventArgs e)
 {
     if (button1.Text.Equals("rec"))
     {
         videoStreamer.SignalToStop();
         stopWatch.Stop();
         //videoStreamer.WaitForStop();
         button1.Text = "sto";
     }
     else
     {
         videoStreamer.Start();
         stopWatch.Start();
         button1.Text = "rec";
     }
 }
Example #12
0
 private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
 {
     if (this._isRecording)
     {
         this._frameCount++;
         this._writer.WriteVideoFrame(eventArgs.Frame);
     }
     else
     {
         _stopWatch.Reset();
         Thread.Sleep(500);
         _streamVideo.SignalToStop();
         Thread.Sleep(500);
         _writer.Close();
     }
 }
Example #13
0
        private void NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            if (isRecording)
            {
                Bitmap filterderImage = AddFilter(eventArgs.Frame);
                Bitmap cloneImage     = (Bitmap)filterderImage.Clone();
                if (App.Current != null)
                {
                    App.Current.Dispatcher.BeginInvoke((Action)(() =>
                                                                this.sampleImage.Source = BitmapToImageSource(cloneImage)));
                }
                try
                {
                    this.writer.WriteVideoFrame(filterderImage);
                }
                catch (Exception exception) { }
            }
            else
            {
                if (isScreenCapture)
                {
                    streamScreen.SignalToStop();
                }
                else
                {
                    streamDevice.SignalToStop();
                }
                if (isScreenCapture)
                {
                    streamScreen = null;
                }
                else
                {
                    streamDevice = null;
                }

                writer.Close();

                if (App.Current != null)
                {
                    App.Current.Dispatcher.BeginInvoke((Action)(() =>
                                                                this.sampleImage.Source = new BitmapImage(new Uri(@"Common/Default.png", UriKind.Relative))));
                }
            }
        }
        private static void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            if (_isRecording)
            {
                Bitmap     frame    = eventArgs.Frame;
                Graphics   graphics = Graphics.FromImage(frame);
                CURSORINFO pci;
                pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));

                if (GetCursorInfo(out pci))
                {
                    if (pci.flags == CURSOR_SHOWING)
                    {
                        int x = pci.ptScreenPos.x - screenLeft;
                        int y = pci.ptScreenPos.y - screenTop;
                        DrawIcon(graphics.GetHdc(), x, y, pci.hCursor);
                        graphics.ReleaseHdc();
                    }
                }
                if (useArea)
                {
                    var destRect = new Rectangle(Convert.ToInt32((_width - frame.Width) / 2),
                                                 Convert.ToInt32((_height - frame.Height) / 2), frame.Width, frame.Height);
                    var destImage = new Bitmap(_width, _height);
                    destImage.SetResolution(frame.HorizontalResolution, frame.VerticalResolution);

                    graphics = Graphics.FromImage(destImage);
                    graphics.DrawImage(frame, destRect, 0, 0, frame.Width, frame.Height, GraphicsUnit.Pixel, null);
                    frame = destImage;
                }

                _writer.WriteVideoFrame(frame);
            }
            else
            {
                _streamVideo.SignalToStop();
                Thread.Sleep(500);
                _writer.Close();
                Save();
                MainWindow.TrayApp.ShowBalloonTip(2000, "TankiTools", $"{L18n.Get("TrayApp", "Balloon_VideoEnded")}", ToolTipIcon.None);
            }
        }
Example #15
0
        private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            if (this.mIsRecording)
            {
                this.mFrameCount++;
                this.mWriter.WriteVideoFrame(eventArgs.Frame);

                SetFramesPerSecondLabel();

                SetStopWatchLabel();
            }
            else
            {
                mStopWatch.Reset();
                Thread.Sleep(500);
                mStreamVideo.SignalToStop();
                Thread.Sleep(500);
                mWriter.Close();
            }
        }
Example #16
0
        public static void Stop()
        {
            try
            {
                if (m_videostream != null)
                {
                    m_videostream.SignalToStop();
                    m_videostream.WaitForStop();
                    m_videostream = null;
                }


                if (m_filewriter != null && m_filewriter.IsOpen)
                {
                    m_filewriter.Close();
                    m_filewriter.Dispose();
                    m_filewriter = null;
                }
            }
            catch { }

            m_recording = false;
        }
Example #17
0
 private void StopScreenCapture()
 {
     // signal to stop
     ScreenCapture.SignalToStop();
     ScreenCapture.NewFrame -= NewVideoFrame;
 }
Example #18
0
        private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            if (this._isRecording)
            {
                this._frameCount += Convert.ToUInt32(fps);
                this._writer.WriteVideoFrame(eventArgs.Frame);

                this.lb_stopWatch.Invoke(new Action(() =>
                {
                    this.lb_stopWatch.Text = string.Format("{0:00}:{1:00}:{2:00}", _stopWatch.Elapsed.Hours, _stopWatch.Elapsed.Minutes, (int)_stopWatch.Elapsed.Seconds);
                }));


                this.lb_rebootWatch.Invoke(new Action(() =>
                {
                    if (checkBox3.Checked)
                    {
                        leftTime   = totalTime - (int)_stopWatch.Elapsed.TotalSeconds;
                        TimeSpan t = TimeSpan.FromSeconds(leftTime);
                        //this.lb_rebootWatch.Text = string.Format("{0:00}:{1:00}:{2:00}", h_leftTime, m_leftTime, s_leftTime);
                        this.lb_rebootWatch.Text = string.Format("{0:D2}h:{1:D2}m:{2:D2}s",
                                                                 t.Hours,
                                                                 t.Minutes,
                                                                 t.Seconds);

                        if (leftTime == 0)
                        {
                            // terminate system
                            bt_Save_Click(sender, eventArgs);
                        }
                    }
                }));
            }
            else
            {
                _stopWatch.Reset();   // Terninate Thread
                _rebootWatch.Reset(); // Terninate Thread

                _streamVideo.SignalToStop();

                _writer.Close(); // End Recoding

                //stop recording
                capture.Stop();
                w.Dispose();
                w = null;
                capture.Dispose();
                capture = null;

                if (checkBox1.Checked == true)
                {
                    string files   = "-i " + fullName + ".avi -i " + fullName + ".wav -c:v copy -c:a aac -strict experimental " + fullName + ".mp4";
                    string cmdtext = "/C ffmpeg " + files;
                    var    process = System.Diagnostics.Process.Start("CMD.exe", cmdtext);
                    process.WaitForExit();

                    try
                    {
                        System.IO.File.Delete(fullName + ".avi");
                        System.IO.File.Delete(fullName + ".wav");
                    }
                    catch { MessageBox.Show("fail"); }
                }

                if (checkBox3.Checked == true && leftTime == 0)
                {
                    System.Windows.Forms.Application.Exit();
                    Process.Start("shutdown", "/s /t 0");
                }
            }
        }