/// <summary> /// 开始录制点击事件 /// </summary> private void btBegin_Click(object sender, RoutedEventArgs e) { if (!SettingHelp.Settings.桌面 && !SettingHelp.Settings.摄像头 && !SettingHelp.Settings.声音) { Functions.Message("未选择任何录制源,请先选择录制内容"); return; } try { if (IsRecording)//如果已经是录制中则说明是暂停后恢复录制 { VideoStreamer.Start(); parseSpan = parseSpan.Add(DateTime.Now - parseTime); IsParsing = false; } else//否则为首次开启录制,调用开始录制方法 { BeginRecord(); } btBegin.Visibility = Visibility.Collapsed; btParse.Visibility = Visibility.Visible; btClose.Visibility = Visibility.Collapsed; btStop.Visibility = Visibility.Visible; } catch (Exception ex) { StopRecord(ShowErr: false); Functions.Message(ex.Message); } }
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; } }
private void btBegin_Click(object sender, RoutedEventArgs e) { if (!SettingHelp.Settings.桌面 && !SettingHelp.Settings.摄像头 && !SettingHelp.Settings.声音) { Message("未选择任何录制源,请先选择录制内容"); return; } try { if (isRecording) { videoStreamer.Start(); isParsing = false; } else { BeginRecord(); } btBegin.Visibility = Visibility.Collapsed; btParse.Visibility = Visibility.Visible; btClose.Visibility = Visibility.Collapsed; btStop.Visibility = Visibility.Visible; } catch (Exception ex) { StopRecord(false); Message(ex.Message); } }
public void Start() { _Writer.Width = _CaptureRegion.Width; _Writer.Height = _CaptureRegion.Height; _Writer.FrameRate = _FrameRate; _Writer.BitRate = _BitRate; _Writer.VideoCodec = VideoCodec.Default; _Writer.Open(_FilePath + _FileName); if (_RecordingScreen) { _ScreenSource.FrameInterval = 20; _ScreenSource.NewFrame += Screen_NewFrame; _ScreenSource.Start(); } if (_RecordingMicrophone) { _AudioSource = new AudioCaptureDevice(_CurrenrAudioDevice); _AudioSource.NewFrame += new EventHandler <Accord.Audio.NewFrameEventArgs>(Microphone_NewFrame); _AudioSource.Start(); } if (_RecordingAudio) { Trace.WriteLine("start recoder Speaker"); _SpeakerSource = new AudioCaptureDevice(_CurrenrSpeakerDevice); _SpeakerSource.NewFrame += new EventHandler <Accord.Audio.NewFrameEventArgs>(Speaker_NewFrame); _SpeakerSource.Start(); } }
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(); }
public void StartRecord() { if (!isRecording) { StartTick = null; isRecording = true; video.Open(@"D:\Projects\new_test.avi", 1920, 1080, new Accord.Math.Rational(60.0), VideoCodec.Default); captureStream.Start(); audio.Start(); } }
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 RecordButton_Click(object sender, EventArgs e) { string folderpath = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos); string filename = FileNameBox.Text + ".WMV"; string path = Path.Combine(folderpath, filename); MessageLabel.Text = "Recording"; writer.Open(path, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, 10, VideoCodec.WMV1, 12000000); stream.NewFrame += new NewFrameEventHandler(video_NewFrame); stream.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 _streamVideo = new ScreenCaptureStream(_screenArea); // set NewFrame event handler _streamVideo.NewFrame += Video_NewFrame; // start the video source _streamVideo.Start(); // _stopWatch _stopWatch.Start(); }
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"; } }
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 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 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; }
public RMDServer(string addressServer, int hash) { screenCapture = new ScreenCaptureStream(new Rectangle(Screen.PrimaryScreen.Bounds.Location, Screen.PrimaryScreen.Bounds.Size), 30); screenCapture.NewFrame += ScreenCapture_NewFrame; screenCapture.Start(); tcpClient = new TcpClient(addressServer, port); networkStream = tcpClient.GetStream(); formatter.Serialize(networkStream, 1); //говорим, что мы сервер formatter.Serialize(networkStream, hash); int result = (int)formatter.Deserialize(networkStream); if (result != 1) { tcpClient.Dispose(); return; } timer.Interval = 10; timer.Tick += Timer_Elapsed; timer.Start(); }
internal static bool Record(int fps, int codec) { if (!Assistant.Engine.CDepPresent) { return(false); } IntPtr uowindow = Client.Instance.GetWindowHandle(); if (uowindow == IntPtr.Zero) { return(false); } System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.FromHandle(uowindow); Rectangle screenBound = screen.Bounds; if (!DLLImport.Win.GetWindowRect(uowindow, out DLLImport.Win.RECT handleRect)) { return(false); } //Getting the intersection between the two rectangles Rectangle handleBound = new Rectangle(handleRect.Left + 6, handleRect.Top, handleRect.Right - handleRect.Left - 6, handleRect.Bottom - handleRect.Top); m_ResX = (handleBound.Right - handleBound.Left) - 5; m_ResY = (handleBound.Bottom - handleBound.Top) - 5; if (m_ResX % 2 != 0) { m_ResX--; } if (m_ResY % 2 != 0) { m_ResY--; } string filename; string name = "Unknown"; string path = RazorEnhanced.Settings.General.ReadString("VideoPath"); if (!Directory.Exists(path)) { path = Assistant.Engine.RootPath; RazorEnhanced.Settings.General.WriteString("VideoPath", path); Assistant.Engine.MainWindow.VideoPathTextBox.Text = path; } if (World.Player != null) { name = World.Player.Name; } if (name == null || name.Trim() == "" || name.IndexOfAny(Path.GetInvalidPathChars()) != -1) { name = "Unknown"; } name = String.Format("{0}_{1}", name, DateTime.Now.ToString("M-d_HH.mm")); int count = 0; do { filename = Path.Combine(path, String.Format("{0}{1}.avi", name, count != 0 ? count.ToString() : "")); count--; // cause a - to be put in front of the number }while (File.Exists(filename)); try { m_recording = true; m_filewriter = new VideoFileWriter(); m_filewriter.Open(filename, m_ResX, m_ResY, fps, (VideoCodec)codec, 30000000); // create screen capture video source m_videostream = new ScreenCaptureStream(handleBound, fps); // set NewFrame event handler m_videostream.NewFrame += new NewFrameEventHandler(video_NewFrame); // start the video source m_videostream.Start(); return(true); } catch { MessageBox.Show("Video Codec not installed on your system."); return(false); } }
private void button4_Click(object sender, EventArgs e) { //timer1.Enabled = true; cap.Start(); }
public static bool Record(int fps, int codec) { GetWindowRect(ClientCommunication.FindUOWindow(), out RECT lpRect); Rectangle screenArea = new Rectangle(lpRect.Left, lpRect.Top, (lpRect.Right - lpRect.Left), (lpRect.Bottom - lpRect.Top)); foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens) { screenArea = Rectangle.Union(screenArea, screen.Bounds); } m_ResX = (lpRect.Right - lpRect.Left) - 5; m_ResY = (lpRect.Bottom - lpRect.Top) - 5; if (m_ResX % 2 != 0) { m_ResX--; } if (m_ResY % 2 != 0) { m_ResY--; } string filename; string name = "Unknown"; string path = RazorEnhanced.Settings.General.ReadString("VideoPath"); if (!Directory.Exists(path)) { path = Path.GetDirectoryName(Application.ExecutablePath); RazorEnhanced.Settings.General.WriteString("VideoPath", path); Assistant.Engine.MainWindow.VideoPathTextBox.Text = path; } if (World.Player != null) { name = World.Player.Name; } if (name == null || name.Trim() == "" || name.IndexOfAny(Path.GetInvalidPathChars()) != -1) { name = "Unknown"; } name = String.Format("{0}_{1}", name, DateTime.Now.ToString("M-d_HH.mm")); int count = 0; do { filename = Path.Combine(path, String.Format("{0}{1}.avi", name, count != 0 ? count.ToString() : "")); count--; // cause a - to be put in front of the number }while (File.Exists(filename)); try { m_recording = true; m_filewriter = new VideoFileWriter(); m_filewriter.Open(filename, m_ResX, m_ResY, fps, (VideoCodec)codec, 30000000); // create screen capture video source m_videostream = new ScreenCaptureStream(screenArea, fps); // set NewFrame event handler m_videostream.NewFrame += new NewFrameEventHandler(video_NewFrame); // start the video source m_videostream.Start(); return(true); } catch { MessageBox.Show("Video Codec not installed on your system."); return(false); } }
private void BeginRecord() { curVideoName = MakeFilePath(".avi", "Raw"); curAudioName = curVideoName.Replace(".avi", ".wav");//使音频文件和视频文件同名 var curScreen = System.Windows.Forms.Screen.FromHandle(winHandle); videoSpan = new TimeSpan(); lbTime.Content = videoSpan.ToString("hh\\:mm\\:ss"); FrameCount = 0; int RecordWidth = 0, RecordHeight = 0, RecordTop = 0, RecordLeft = 0; if (SettingHelp.Settings.跨屏录制) { foreach (var s in System.Windows.Forms.Screen.AllScreens) { RecordWidth += Math.Abs(s.Bounds.Width); if (Math.Abs(s.Bounds.Height) > RecordHeight) { RecordHeight = Math.Abs(s.Bounds.Height); } RecordLeft = Math.Min(s.Bounds.X, RecordLeft); RecordTop = Math.Min(s.Bounds.Y, RecordTop); } } else { RecordWidth = curScreen.Bounds.Width; RecordHeight = curScreen.Bounds.Height; } if (SettingHelp.Settings.桌面) { lock (this) { videoWriter.Open(curVideoName, RecordWidth, RecordHeight, SettingHelp.Settings.视频帧率, VideoCodec.MSMPEG4v3, curScreen.Bounds.Width * curScreen.Bounds.Height * SettingHelp.Settings.视频质量); } System.Drawing.Rectangle rec = new System.Drawing.Rectangle(SettingHelp.Settings.跨屏录制 ? RecordLeft : curScreen.Bounds.X, SettingHelp.Settings.跨屏录制 ? RecordTop : curScreen.Bounds.Y, RecordWidth, RecordHeight); videoStreamer = new ScreenCaptureStream(rec, 1000 / SettingHelp.Settings.视频帧率);//帧间隔需要和帧率关联,不然录的10秒视频文件不是10s videoStreamer.NewFrame += VideoNewFrame; videoStreamer.Start(); } if (SettingHelp.Settings.摄像头) { var carmeraShow = new CameraShow(curVideoName); //如果录制桌面又开启摄像头则摄像头只在右下角显示用,不单独保存文件 Visibility = SettingHelp.Settings.桌面 ? Visibility.Visible : Visibility.Collapsed; //当只录摄像头时隐藏主命令栏 carmeraShow.Owner = this; } if (SettingHelp.Settings.声音) { audioStreamer = new WaveInEvent(); audioStreamer.DataAvailable += AudioDataAvailable; audioWriter = new WaveFileWriter(curAudioName, audioStreamer.WaveFormat); audioStreamer.StartRecording(); } isRecording = true; isParsing = false; if (SettingHelp.Settings.录制隐藏) { HiddenTools(true); } btSet.Visibility = Visibility.Collapsed; //waitBar.Visibility = Visibility.Collapsed; lbTime.Visibility = Visibility.Visible; ChangePlace(); //TitleDragMove(false); }
/// <summary> /// 开始录制 /// </summary> private void BeginRecord() { //重编码体积更小,但清晰度受影响,不录制声音时直接输出MP4不再ffmpeg处理 CurrentVideoPath = MakeFilePath(".mp4", SettingHelp.Settings.声音 ? "Raw" : ""); CurrentAudioPath = CurrentVideoPath.Replace(".mp4", ".wav");//使音频文件和视频文件同名 var curScreen = System.Windows.Forms.Screen.FromHandle(winHandle); parseSpan = new TimeSpan(); lbTime.Content = "00:00:00"; FrameCount = 0; int RecordWidth = 0, RecordHeight = 0, RecordTop = 0, RecordLeft = 0; if (SettingHelp.Settings.跨屏录制) { foreach (var s in System.Windows.Forms.Screen.AllScreens) { RecordWidth += Math.Abs(s.Bounds.Width); if (Math.Abs(s.Bounds.Height) > RecordHeight) { RecordHeight = Math.Abs(s.Bounds.Height); } RecordLeft = Math.Min(s.Bounds.X, RecordLeft); RecordTop = Math.Min(s.Bounds.Y, RecordTop); } } else { RecordWidth = curScreen.Bounds.Width; RecordHeight = curScreen.Bounds.Height; } if (SettingHelp.Settings.桌面) { lock (this) { VideoWriter.Open(CurrentVideoPath, RecordWidth, RecordHeight, SettingHelp.Settings.视频帧率, VideoCodec.MPEG4, curScreen.Bounds.Width * curScreen.Bounds.Height * SettingHelp.Settings.视频质量); } Rectangle rec = SettingHelp.Settings.跨屏录制 ? new Rectangle(RecordLeft, RecordTop, RecordWidth, RecordHeight) : new Rectangle(curScreen.Bounds.X, curScreen.Bounds.Y, RecordWidth, RecordHeight); VideoStreamer = new ScreenCaptureStream(rec, 1000 / SettingHelp.Settings.视频帧率);//帧间隔需要和帧率关联,不然录的10秒视频文件不是10s VideoStreamer.NewFrame += VideoNewFrameHandle; beginTime = DateTime.Now; VideoStreamer.Start(); } if (SettingHelp.Settings.摄像头) { CarmeraShowWin = new CameraShowWindow(CurrentVideoPath, CurrentScreen); //如果录制桌面又开启摄像头则摄像头只在右下角显示用,不单独保存文件 Visibility = SettingHelp.Settings.桌面 ? Visibility.Visible : Visibility.Collapsed; //当只录摄像头时隐藏主命令栏 CarmeraShowWin.Owner = this; } if (SettingHelp.Settings.声音) { AudioStreamer = new WaveInEvent(); AudioStreamer.DataAvailable += AudioDataAvailableHandle; AudioWriter = new WaveFileWriter(CurrentAudioPath, AudioStreamer.WaveFormat); AudioStreamer.StartRecording(); } IsRecording = true; IsParsing = false; if (SettingHelp.Settings.录制隐藏) { HiddenTools(true); } btSet.Visibility = Visibility.Collapsed; lbTime.Visibility = Visibility.Visible; GoToScreenTopMiddle(); //TitleDragMove(false); }