public Recorder() { _CaptureRegion = new Rectangle(0, 0, 480, 360); _isRecording = false; _isPausing = false; _RecordingScreen = false; _RecordingCamera = false; _RecordingMicrophone = false; _RecordingAudio = false; _FrameRate = 60; _BitRate = 1200 * 1000; _FileName = "Video.avi"; _FilePath = "C:\\"; _CameraDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); _CurrentCameraDevice = GetCameraDevice(0); _CameraSource = new VideoCaptureDevice(_CurrentCameraDevice.MonikerString); _ScreenSource = new ScreenCaptureStream(_CaptureRegion); _AudioDevices = new AudioDeviceCollection(AudioDeviceCategory.Capture); _CurrenrAudioDevice = GetAudioDevice(0); _Writer = new VideoFileWriter(); _StartTime = DateTime.MinValue; _ScreenTotalFrames = 0; _AudioTotalFrames = 0; }
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; }
/// <summary> /// 勾选框勾选 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void _checkBox_Checked(object sender, RoutedEventArgs e) { //勾选 //如果是桌面,则特殊处理 _image = new ImageX(_model, _index, _textBlock.Text, this); _model._imagexList.Add(_index, _image); _model.ImagePanel.Children.Add(_image); if (_index == 0) { List <SimpleModel> deskCapabilityList = CommonHelper.GetDeskCapability(); _image.SetResolution(deskCapabilityList); //开始显示桌面 Rectangle screenArea = Rectangle.Empty; screenArea = Rectangle.Union(screenArea, Screen.PrimaryScreen.Bounds); var streamVideo = new ScreenCaptureStream(screenArea); _image.SetVideoResource(streamVideo); } else { //index-1 是因为要去掉【桌面】这个序号 _image.SetResolution(VideoHelper.GetCameraResolution(_index - 1)); //开始显示摄像头 FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); if (videoDevices.Count > 0) { var camera = new VideoCaptureDevice(videoDevices[_index - 1].MonikerString); camera.VideoResolution = camera.VideoCapabilities[_index - 1]; camera.NewFrame += _image.Camera_NewFrame; _image.setFrameRate(camera.VideoCapabilities[_index - 1].AverageFrameRate); _image.SetVideoResource(camera); } } }
/// <summary> /// 开始 /// </summary> /// <param name="frameEventHandler">每帧回调(默认不需要填)</param> public virtual void Start(NewFrameEventHandler frameEventHandler = null) { //继续播放 if (this.RecorderStatus == RecorderStatus.Pause) { this.VideoStreamer.Start(); this.wavRecorder.Start(); return; } this.RecorderStatus = RecorderStatus.Start; //设置所有显示器 foreach (Screen screen in Screen.AllScreens) { this.ScreenArea = Rectangle.Union(this.ScreenArea, screen.Bounds); } //打开录制器 this.VideoWriter.Open(this.AviFilePath, this.ScreenWidth, this.ScreenHight, this.FrameRate, this.VideoCodec, this.BitRate); this.VideoStreamer = new ScreenCaptureStream(this.ScreenArea); this.VideoStreamer.NewFrame += VideoStreamer_NewFrame; if (frameEventHandler != null) { this.VideoStreamer.NewFrame += frameEventHandler; } this.VideoStreamer.Start(); //是否需要录制声音 if (wavRecorder != null) { wavRecorder.Start(); } }
private void StartRecord() //Object stateInfo { // create screen capture video source this._streamVideo = new ScreenCaptureStream(this._screenArea); //MessageBox.Show(form2.Location.X.ToString() + " " + form2.Location.Y.ToString()); //MessageBox.Show(this._screenArea.Width.ToString() + " " + this._screenArea.Height.ToString()); // set NewFrame event handler this._streamVideo.NewFrame += new NewFrameEventHandler(this.video_NewFrame); // start the video source this._streamVideo.Start(); // _stopWatch this._stopWatch.Start(); if (checkBox3.Checked) { // MessageBox.Show("automatic termination is initiated"); // _stopWatch this._rebootWatch.Start(); int selectedIndex = comboBox1.SelectedIndex; int selectedValue = (int)comboBox1.SelectedValue; totalTime = selectedValue * 60; leftTime = totalTime; } }
/// <summary> /// 预览桌面 /// </summary> private void PreviewDesktop() { if (PreviewPlayer.IsRunning) { PreviewPlayer.SignalToStop(); PreviewPlayer.WaitForStop(); } Rectangle screenArea = Rectangle.Empty; screenArea = Rectangle.Union(screenArea, System.Windows.Forms.Screen.PrimaryScreen.Bounds); var streamVideo = new ScreenCaptureStream(screenArea); //当前屏幕的宽高比 var index1 = Math.Round((screenArea.Width * 1.0 / screenArea.Height * 1.0), 2); var width = Convert.ToInt32(Math.Round(CameraStackpanel.Width)); var height = Convert.ToInt32(Math.Round(CameraStackpanel.Height)); //预览播放器的宽高比 var index2 = Math.Round((width * 1.0 / height * 1.0), 2); if (index1 > index2) { PreviewPlayer.Width = width; PreviewPlayer.Height = CommonHelper.GetHeight(screenArea.Width, screenArea.Height, width); } else { PreviewPlayer.Width = CommonHelper.GetWidth(screenArea.Width, screenArea.Height, height); PreviewPlayer.Height = height; } PreviewPlayer.VideoSource = streamVideo; PreviewPlayer.Start(); }
public override bool startRecording() { // Save File option mWriter.Open(mFullName, this.mWidth, this.mHeight, this.mFramesPerSecond, this.mVideoCodec, this.mBitRate); mIsRecording = true; try { // create screen capture video source this.mStreamVideo = new ScreenCaptureStream(this.mScreenArea); // set NewFrame event handler this.mStreamVideo.NewFrame += new NewFrameEventHandler(this.video_NewFrame); // start the video source this.mStreamVideo.Start(); // _stopWatch this.mStopWatch.Start(); return(true); } catch (Exception e) { MessageBox.Show("An error occurred: '{0}'", e.ToString()); return(false); } }
private void captureStart_Click(object sender, EventArgs e) { if (_capturing) { closeScreenSource(); return; } processes += DrawLine; Rectangle screenArea = Rectangle.Empty; ScreenCapStart sc = new ScreenCapStart(false); if (sc.ShowDialog() == DialogResult.OK) { screenArea = sc.toreturn; // create screen capture video source ScreenStream = new ScreenCaptureStream(screenArea, 60); // set NewFrame event handler ScreenStream.NewFrame += new NewFrameEventHandler(Screen_NewFrame); // start the video source ScreenStream.Start(); pBox_preview.SizeMode = PictureBoxSizeMode.StretchImage; captureStart.Text = "Stop Capturing"; _capturing = true; } }
public Recorder(Rectangle area, bool recordmicro, bool recordaudio, int framerate, int bitrate, string filepath, string filename) { _CaptureRegion = new Rectangle(area.X, area.Y, area.Width, area.Height); _RecordingScreen = true; _RecordingMicrophone = recordmicro; _RecordingAudio = recordaudio; _FrameRate = framerate; _BitRate = bitrate; _FileName = filename; _FilePath = filepath; _CameraDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); _CurrentCameraDevice = GetCameraDevice(0); _CameraSource = new VideoCaptureDevice(_CurrentCameraDevice.MonikerString); _ScreenSource = new ScreenCaptureStream(_CaptureRegion); _AudioDevices = new AudioDeviceCollection(AudioDeviceCategory.Capture); _CurrenrAudioDevice = GetAudioDevice(0); _Writer = new VideoFileWriter(); _StartTime = DateTime.MinValue; _ScreenTotalFrames = 0; _AudioTotalFrames = 0; }
////////////////////////////////////////////////////////////////////////// private void Home_Click(object sender, EventArgs e) { Estrategia.Enabled = true; Horario.Enabled = true; Estrategia.BackColor = Color.Lime; Rectangle screenArea = Rectangle.Empty; screenArea = new Rectangle(1758, 500, 150, 150); //NUEVA VENTANA FuentedeVideo2 = new ScreenCaptureStream(screenArea); videoSourcePlayer2.VideoSource = FuentedeVideo2; videoSourcePlayer2.Start(); // //////////////////////////////////////////////////////////////////////////////////////////////////// Rectangle screenArea2 = Rectangle.Empty; //Linea Superior screenArea2 = new Rectangle(850, 430, 125, 65); // si funciona la deteccion y el PUT anterior de 785 y menos 10 FuentedeVideo1 = new ScreenCaptureStream(screenArea2); videoSourcePlayer1.VideoSource = FuentedeVideo1; videoSourcePlayer1.Start(); Rectangle screenArea4 = Rectangle.Empty; // linea Roja, screenArea4 = new Rectangle(1100, 430, 125, 65); //si Funciona el PUSH antes 982 menos 10 FuentedeVideo4 = new ScreenCaptureStream(screenArea4); videoSourcePlayer4.VideoSource = FuentedeVideo4; videoSourcePlayer4.Start(); // //////////////////////////////////////////////////////////////////////////////////////////////////// Rectangle screenArea3 = Rectangle.Empty; screenArea3 = new Rectangle(1200, 899, 150, 10); //COORDENADAS TENDENCIA SEGUNDA COLUMNA SEGUNDA RENGLON FuentedeVideo3 = new ScreenCaptureStream(screenArea3); videoSourcePlayer3.VideoSource = FuentedeVideo3; videoSourcePlayer3.Start(); Rectangle screenArea5 = Rectangle.Empty; //COORDENADAS TENDENCIA SEGUNDA COLUMNA PRIMER RENGLON screenArea5 = new Rectangle(1200, 780, 150, 10); FuentedeVideo5 = new ScreenCaptureStream(screenArea5); videoSourcePlayer5.VideoSource = FuentedeVideo5; videoSourcePlayer5.Start(); }
private void Form1_Load(object sender, EventArgs e) { cap = new ScreenCaptureStream(new Rectangle(2000, 200, 320, 480), 10); cap.NewFrame += cap_NewFrame; Get_All_Devices(); colorFilter.Red = new IntRange(10, 255); colorFilter.Green = new IntRange(10, 255); colorFilter.Blue = new IntRange(10, 255); }
private void LoadSceenCapture() { System.Drawing.Rectangle screenArea = System.Drawing.Rectangle.Empty; screenArea.Width = 20; screenArea.Height = 20; CaptureSource = new ScreenCaptureStream(screenArea, 5); CaptureSource.NewFrame += new AForge.Video.NewFrameEventHandler(screenSource_NewFrame); CaptureSource.Start(); }
/// <summary> /// Starts playing the preview screen, grabbing /// frames, but not recording to a video file. /// </summary> /// public void StartPlaying() { if (IsPlaying) { return; } // Checks if we were already waiting for a window // to be selected, in case the user had chosen to // capture from a fixed window. if (IsWaitingForTargetWindow) { // Yes, we were. We will not be waiting anymore // since the user should have selected one now. IsWaitingForTargetWindow = false; } else { // No, this is the first time the user starts the // frame grabber. Let's check what the user wants if (CaptureMode == CaptureRegionOption.Window) { // The user wants to capture from a window. So we // need to ask which window we have to keep a look. // We will return here and wait the user to respond; // when he finishes selecting he should signal back // by calling SelectWindowUnderCursor(). IsWaitingForTargetWindow = true; OnTargetWindowRequested(); return; } } // All is well. Keep configuring and start CaptureRegion = Screen.PrimaryScreen.Bounds; double framerate = Settings.Default.FrameRate; int interval = (int)Math.Round(1000 / framerate); int height = CaptureRegion.Height; int width = CaptureRegion.Width; clickCapture.Enabled = true; keyCapture.Enabled = true; screenStream = new ScreenCaptureStream(CaptureRegion, interval); screenStream.VideoSourceError += ScreenStream_VideoSourceError; videoPlayer.VideoSource = screenStream; videoPlayer.Start(); IsPlaying = true; }
public Form1() { screenCapture = new ScreenCaptureStream(new Rectangle(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height), 60); screenCapture.NewFrame += ScreenCapture_NewFrame; screenCapture.Start(); InitializeComponent(); SizeChanged += Form1_SizeChanged; timer1.Start(); }
private void startStripMenuItem_Click(object sender, EventArgs e) { //Rectangle screenArea = Rectangle.FromLTRB(0, 0, 2560, 1440); // 1st monitor Rectangle screenArea = Rectangle.FromLTRB(2561, 0, 5120, 1440); // 2nd monitor ScreenCaptureStream stream = new ScreenCaptureStream(screenArea, 100); stream.NewFrame += new NewFrameEventHandler(video_NewFrame); openVideoToolStripMenuItem.Enabled = false; // start the video source stream.Start(); }
private void StartScreenCapture() { var screenArea = new Rectangle(0, 0, (int)SystemParameters.VirtualScreenWidth, (int)SystemParameters.VirtualScreenHeight); // create screen capture video source ScreenCapture = new ScreenCaptureStream(screenArea); // set NewFrame event handler ScreenCapture.NewFrame += new NewFrameEventHandler(NewVideoFrame); // start the video source ScreenCapture.Start(); }
private void pBox_preview_MouseDown(object sender, MouseEventArgs e) { if (VideoDevice != null || ScreenStream != null) { Bitmap img = (Bitmap)pBox_preview.Image; float stretch_X = img.Width / (float)pBox_preview.Width; float stretch_Y = img.Height / (float)pBox_preview.Height; pt = new Point((int)(e.X * stretch_X), (int)(e.Y * stretch_Y)); processes += DrawLine; } else { if (rButton_Screen.Checked) { // get the desktop Rectangle screenArea = Rectangle.Empty; ScreenCapStart sc = new ScreenCapStart(); if (sc.ShowDialog() == DialogResult.OK) { screenArea = Rectangle.Union(screenArea, sc.toreturn.Bounds); // create screen capture video source ScreenStream = new ScreenCaptureStream(screenArea); ScreenStream.FrameInterval = 30; // set NewFrame event handler ScreenStream.NewFrame += new NewFrameEventHandler(Screen_NewFrame); // start the video source ScreenStream.Start(); pBox_preview.SizeMode = PictureBoxSizeMode.StretchImage; btn_Start.Enabled = true; } } else { WebcamStart ws = new WebcamStart(); if (ws.ShowDialog() == DialogResult.OK) { string moniker = ws.toreturn; if (moniker != null) { VideoDevice = new VideoCaptureDevice(moniker); VideoDevice.NewFrame += new NewFrameEventHandler(videoSource_NewFrame); VideoDevice.Start(); pBox_preview.SizeMode = PictureBoxSizeMode.StretchImage; btn_Start.Enabled = true; } } } panel4.Enabled = false; } }
private void StartRecord() //Object stateInfo { // create screen capture video source this._streamVideo = new ScreenCaptureStream(this._screenArea); // set NewFrame event handler this._streamVideo.NewFrame += new NewFrameEventHandler(this.video_NewFrame); // start the video source this._streamVideo.Start(); // _stopWatch this._stopWatch.Start(); }
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; } }
private void StartRecord() //Object stateInfo { // create screen capture video source _streamVideo = new ScreenCaptureStream(_screenArea); // set NewFrame event handler _streamVideo.NewFrame += Video_NewFrame; // start the video source _streamVideo.Start(); // _stopWatch _stopWatch.Start(); }
public Recorder(int xlocation, int ylocation, int width, int height, AudioDeviceInfo audioDevice) { audioEncoder = new WaveEncoder(@"D:\Projects\test_audio.wav"); audio = new AudioCaptureDevice(audioDevice); captureStream = new ScreenCaptureStream(new System.Drawing.Rectangle(xlocation, ylocation, width, height)); video = new VideoFileWriter(); audio.DesiredFrameSize = 4096; audio.SampleRate = 44100; audio.NewFrame += Audio_NewFrame; captureStream.FrameInterval = 1; captureStream.NewFrame += CaptureStream_NewFrame; }
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; } } }
/// <summary> /// Opens video streamer and starts recordnig. /// </summary> private void StartRecording() { //SaveFileDialog Savefile = new SaveFileDialog() { Filter = "AVI视频文件|*.avi" }; //if (Savefile.ShowDialog() == System.Windows.Forms.DialogResult.OK) //{ // fileName = Savefile.FileName; //} //this.fileName = saveFile(sd.FileName); //InitializeRecordingParameters(); this.videoStreamer = new ScreenCaptureStream(this.screenArea); this.videoStreamer.NewFrame += new NewFrameEventHandler(video_NewFrame); this.videoStreamer.Start(); this.stopWatch.Start(); }
/* * private void Start(bool selectArea) * { * try * { * this.StartRec(selectArea); * } * catch (Exception exc) * { * MessageBox.Show(exc.Message); * } * }*/ private void StartRec(CaptureTypes type) { if (_isRecording == false) { this.SetScreenArea(type); this._isRecording = true; now = DateTime.Now; name = $"{now.ToString().Replace(" ", "_").Replace(".", "_").Replace(":", "_") }.avi"; path = Path.Combine(SettingsManager.videos_path, name); _writer.Open(path, _width, _height, fps, codec, bitrate); this._streamVideo = new ScreenCaptureStream(this._screenArea); this._streamVideo.NewFrame += new NewFrameEventHandler(this.video_NewFrame); this._streamVideo.Start(); } }
public static void CaptureScreen(int?index = null) { lock (_lock) { VideoSource?.SignalToStop(); ScreenIndex = index ?? ScreenIndex + 1; CameraIndex = -1; if (ScreenIndex >= Screen.AllScreens.Length) { ScreenIndex = 0; } VideoSource = new ScreenCaptureStream(Screen.AllScreens[ScreenIndex].Bounds); VideoSource.NewFrame += NewFrameHandler; VideoSource.Start(); VideoSourceChanged?.Invoke(); } }
public static void StartRec(CaptureTypes type) { if (_isRecording == false) { SetScreenArea(type); _isRecording = true; now = DateTime.Now; name = $"{now.ToString().Replace(" ", "_").Replace(".", "_").Replace(":", "_") }.avi"; path = Path.Combine(SettingsManager.videos_path, name); _writer.Open(path, _width, _height, fps, codec, bitrate); _streamVideo = new ScreenCaptureStream(_screenArea); _streamVideo.NewFrame += new NewFrameEventHandler(video_NewFrame); _streamVideo.Start(); MainWindow.TrayApp.ShowBalloonTip(2000, "TankiTools", $"{L18n.Get("TrayApp", "Balloon_VideoStarted")}", ToolTipIcon.None); } }
public Screen_Grab_2() { Process[] processes = Process.GetProcessesByName("obs64"); windowHandle = processes[0].MainWindowHandle; RECT rc; GetWindowRect(windowHandle, out rc); ScreenCaptureStream source = new ScreenCaptureStream(rc, 1000); // approx 500 KB per screenshot source.Start(); source.NewFrame += Source_NewFrame; }
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 void StartRecordScreen(string path) { this.streamScreen = new ScreenCaptureStream(new Rectangle(startPosX, 0, this.width, this.height)); string fullName = string.Format(@"{0}\{1}_{2}.avi", path, Environment.UserName.ToUpper(), DateTime.Now.ToString("d_MMM_yyyy_HH_mm_ssff")); writer.Open(fullName, this.width, this.height, (int)fps, (VideoCodec)videoCodec, (int)(BitRate)bitRate); this.streamScreen.NewFrame += new NewFrameEventHandler(this.NewFrame); isRecording = true; this.streamScreen.Start(); OnThreadLabelTimeEventStart(); }
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; }