diff --git a/README.md b/README.md index 77a3ba1..1d703ac 100644 --- a/README.md +++ b/README.md @@ -63,15 +63,6 @@ Where can you install the app? - Record any monitor connected to your PC
- Availability in ten languages (English, Español, Français, Deutsch, Українська, 日本語, Português do Brasil, 中文(简体), العربية and Italiano) -

Demo

-

- Watch a demo of the app recording gameplay on YouTube: -
- - Simple-Screen-Recorder app test | C# Project (.NET 8 and WinForms) - -

-

Install

Windows 8, 10, 11 (64 bits) | v1.2.9 | Download directly from GitHub

diff --git a/Simple-Screen-Recorder.csproj b/Simple-Screen-Recorder.csproj index 2d44375..17242c4 100644 --- a/Simple-Screen-Recorder.csproj +++ b/Simple-Screen-Recorder.csproj @@ -9,11 +9,11 @@ enable Simple_Screen_Recorder.Program True - 1.2.9 + 1.3.0 Lextrack Lextrack - 1.2.9 - 1.2.9 + 1.3.0 + 1.3.0 screen recorder.png Resources\screen recorder.ico x64 diff --git a/UI/AboutForm.Designer.cs b/UI/AboutForm.Designer.cs index 7481e95..469a65f 100644 --- a/UI/AboutForm.Designer.cs +++ b/UI/AboutForm.Designer.cs @@ -66,7 +66,7 @@ private void InitializeComponent() label3.Name = "label3"; label3.Size = new Size(151, 38); label3.TabIndex = 7; - label3.Text = "Simple Screen Recorder\r\nv1.2.9"; + label3.Text = "Simple Screen Recorder\r\nv1.3.0"; // // label2 // diff --git a/UI/AudioRecorderMainWindow.Designer.cs b/UI/AudioRecorderMainWindow.Designer.cs index 7b9dc54..04703d6 100644 --- a/UI/AudioRecorderMainWindow.Designer.cs +++ b/UI/AudioRecorderMainWindow.Designer.cs @@ -76,7 +76,7 @@ private void InitializeComponent() btnOutputRecordings.Margin = new Padding(4, 3, 4, 3); btnOutputRecordings.Name = "btnOutputRecordings"; btnOutputRecordings.Size = new Size(296, 40); - btnOutputRecordings.TabIndex = 7; + btnOutputRecordings.TabIndex = 6; btnOutputRecordings.Text = " Open Recordings Folder"; btnOutputRecordings.UseVisualStyleBackColor = true; btnOutputRecordings.Click += btnOutputRecordings_Click; @@ -144,7 +144,7 @@ private void InitializeComponent() comboBoxAudioSourceAudio.Location = new Point(13, 57); comboBoxAudioSourceAudio.Name = "comboBoxAudioSourceAudio"; comboBoxAudioSourceAudio.Size = new Size(221, 23); - comboBoxAudioSourceAudio.TabIndex = 42; + comboBoxAudioSourceAudio.TabIndex = 3; // // label6 // @@ -206,7 +206,7 @@ private void InitializeComponent() ComboBoxMicrophone.Location = new Point(15, 189); ComboBoxMicrophone.Name = "ComboBoxMicrophone"; ComboBoxMicrophone.Size = new Size(219, 24); - ComboBoxMicrophone.TabIndex = 6; + ComboBoxMicrophone.TabIndex = 5; // // ComboBoxSpeaker // @@ -216,7 +216,7 @@ private void InitializeComponent() ComboBoxSpeaker.Location = new Point(15, 137); ComboBoxSpeaker.Name = "ComboBoxSpeaker"; ComboBoxSpeaker.Size = new Size(219, 24); - ComboBoxSpeaker.TabIndex = 5; + ComboBoxSpeaker.TabIndex = 4; // // CountRecAudio // diff --git a/UI/AudioRecorderMainWindow.cs b/UI/AudioRecorderMainWindow.cs index fa76d5c..b8799e9 100644 --- a/UI/AudioRecorderMainWindow.cs +++ b/UI/AudioRecorderMainWindow.cs @@ -14,7 +14,6 @@ public partial class AudioRecorderMainWindow : Form private string AudioName = ""; public int ProcessId { get; private set; } - public static string ResourcePath = Path.Combine(Directory.GetCurrentDirectory(), @"FFmpegResources\ffmpeg"); public AudioRecorderMainWindow() { @@ -24,11 +23,11 @@ public AudioRecorderMainWindow() private void AudioRecorderMainWindow_Load(object sender, EventArgs e) { GetTextsMain(); - OpenAudioComponents(); + InitializeAudioComponents(); LoadUserSettingsCombobox(); } - private void OpenAudioComponents() + private void InitializeAudioComponents() { AudioRecorderMic.OpenComp(); ComboBoxMicrophone.DataSource = AudioRecorderMic.cboDIspositivos.DataSource; @@ -45,86 +44,51 @@ private void btnStartRecording_Click(object sender, EventArgs e) RecordAudio(); DisableElementsUI(); - RecordFfmpegInitial(); } - - private void RecordFfmpegInitial() - { - ProcessStartInfo ProcessId = new("cmd.exe", $"/c {RecorderScreenMainWindow.ResourcePath} -f gdigrab AudioRecordings/" + AudioName + ""); - ProcessId.WindowStyle = ProcessWindowStyle.Hidden; - ProcessId.CreateNoWindow = true; - ProcessId.RedirectStandardOutput = true; - Process.Start(ProcessId); - } - - private void DisableElementsUI() + private void RecordAudio() { - btnStartRecording.Enabled = false; - ComboBoxMicrophone.Enabled = false; - ComboBoxSpeaker.Enabled = false; - BtnBackScreen.Enabled = false; - comboBoxAudioSourceAudio.Enabled = false; - } + string selectedOption = comboBoxAudioSourceAudio.SelectedItem.ToString(); - private void BtnStop_Click(object sender, EventArgs e) - { - try + if (selectedOption == StringsEN.TwoTrackAudio) { - LbTimer.ForeColor = Color.White; - LbTimer.Text = "00:00:00"; - CountRecAudio.Enabled = false; - StopAudioRec(); - + RecordTwoTracks(); } - catch (Exception) + else if (selectedOption == StringsEN.DesktopAudio) { - return; + RecordDesktopAudio(); + } + else if (selectedOption == StringsEN.MicrophoneAudio) + { + RecordMicrophone(); } } - private void StopAudioRec() + private void RecordTwoTracks() { - btnStartRecording.Enabled = true; - ComboBoxMicrophone.Enabled = true; - ComboBoxSpeaker.Enabled = true; - BtnBackScreen.Enabled = true; - comboBoxAudioSourceAudio.Enabled = true; + if (WaveIn.DeviceCount == 0) + { + MessageBox.Show(StringsEN.message3, "Error"); + return; + } - CheckAudioStop(); - CheckFfmpegProcces(); + RecMic(); + RecSpeaker(); } - private void RecordAudio() + private void RecordDesktopAudio() { - string selectedOption = comboBoxAudioSourceAudio.SelectedItem.ToString(); + RecSpeaker(); + } - if (selectedOption == StringsEN.TwoTrackAudio) - { - if (WaveIn.DeviceCount > 0) - { - RecMic(); - } - else - { - MessageBox.Show(StringsEN.message3, "Error"); - } - RecSpeaker(); - } - else if (selectedOption == StringsEN.DesktopAudio) - { - RecSpeaker(); - } - else if (selectedOption == StringsEN.MicrophoneAudio) + private void RecordMicrophone() + { + if (WaveIn.DeviceCount == 0) { - if (WaveIn.DeviceCount > 0) - { - RecMic(); - } - else - { - MessageBox.Show(StringsEN.message3, "Error"); - } + MessageBox.Show(StringsEN.message3, "Error"); + return; } + + RecMic(); } private void CheckAudioStop() @@ -161,20 +125,52 @@ private void CheckAudioStop() soundPlayer.Stop(); } - private void CheckFfmpegProcces() + private void StopAudioRecordingProcess() + { + btnStartRecording.Enabled = true; + ComboBoxMicrophone.Enabled = true; + ComboBoxSpeaker.Enabled = true; + BtnBackScreen.Enabled = true; + comboBoxAudioSourceAudio.Enabled = true; + + CheckAudioStop(); + } + + + private void BtnStop_Click(object sender, EventArgs e) { - foreach (Process proceso in Process.GetProcesses()) + try { - if (proceso.ProcessName == "ffmpeg") - { - proceso.Kill(); - } + LbTimer.ForeColor = Color.White; + LbTimer.Text = "00:00:00"; + CountRecAudio.Enabled = false; + StopAudioRecordingProcess(); + EnableElementsUI(); + + } + catch (Exception) + { + return; } + } - Process proc = Process.GetProcessById(ProcessId); - proc.Kill(); + private void DisableElementsUI() + { + btnStartRecording.Enabled = false; + ComboBoxMicrophone.Enabled = false; + ComboBoxSpeaker.Enabled = false; + BtnBackScreen.Enabled = false; + comboBoxAudioSourceAudio.Enabled = false; } + private void EnableElementsUI() + { + btnStartRecording.Enabled = true; + ComboBoxMicrophone.Enabled = true; + ComboBoxSpeaker.Enabled = true; + BtnBackScreen.Enabled = true; + comboBoxAudioSourceAudio.Enabled = true; + } private static void RecMic() { AudioRecorderMic.Cleanup(); diff --git a/UI/MergeAllMediaForm.Designer.cs b/UI/MergeAllMediaForm.Designer.cs index 1301852..381c82c 100644 --- a/UI/MergeAllMediaForm.Designer.cs +++ b/UI/MergeAllMediaForm.Designer.cs @@ -50,7 +50,7 @@ private void InitializeComponent() BtnVideo2.Location = new Point(14, 10); BtnVideo2.Name = "BtnVideo2"; BtnVideo2.Size = new Size(236, 41); - BtnVideo2.TabIndex = 0; + BtnVideo2.TabIndex = 1; BtnVideo2.Text = "Select a video file"; BtnVideo2.TextAlign = ContentAlignment.MiddleRight; BtnVideo2.UseVisualStyleBackColor = true; @@ -65,7 +65,7 @@ private void InitializeComponent() BtnDeskAudio2.Location = new Point(14, 89); BtnDeskAudio2.Name = "BtnDeskAudio2"; BtnDeskAudio2.Size = new Size(236, 41); - BtnDeskAudio2.TabIndex = 1; + BtnDeskAudio2.TabIndex = 3; BtnDeskAudio2.Text = "Select a system sound file"; BtnDeskAudio2.TextAlign = ContentAlignment.MiddleRight; BtnDeskAudio2.UseVisualStyleBackColor = true; @@ -77,6 +77,7 @@ private void InitializeComponent() txtVideoPath.Font = new Font("Segoe UI", 8F); txtVideoPath.Location = new Point(256, 21); txtVideoPath.Name = "txtVideoPath"; + txtVideoPath.ReadOnly = true; txtVideoPath.RightToLeft = RightToLeft.Yes; txtVideoPath.Size = new Size(216, 22); txtVideoPath.TabIndex = 2; @@ -87,6 +88,7 @@ private void InitializeComponent() txtAudioDesk.Font = new Font("Segoe UI", 8F); txtAudioDesk.Location = new Point(256, 100); txtAudioDesk.Name = "txtAudioDesk"; + txtAudioDesk.ReadOnly = true; txtAudioDesk.RightToLeft = RightToLeft.Yes; txtAudioDesk.Size = new Size(216, 22); txtAudioDesk.TabIndex = 3; @@ -97,6 +99,7 @@ private void InitializeComponent() txtAudioMic.Font = new Font("Segoe UI", 8F); txtAudioMic.Location = new Point(256, 60); txtAudioMic.Name = "txtAudioMic"; + txtAudioMic.ReadOnly = true; txtAudioMic.RightToLeft = RightToLeft.Yes; txtAudioMic.Size = new Size(216, 22); txtAudioMic.TabIndex = 5; @@ -110,7 +113,7 @@ private void InitializeComponent() BtnMicAudio.Location = new Point(14, 49); BtnMicAudio.Name = "BtnMicAudio"; BtnMicAudio.Size = new Size(236, 41); - BtnMicAudio.TabIndex = 4; + BtnMicAudio.TabIndex = 2; BtnMicAudio.Text = "Select a mic audio file"; BtnMicAudio.TextAlign = ContentAlignment.MiddleRight; BtnMicAudio.UseVisualStyleBackColor = true; @@ -125,7 +128,7 @@ private void InitializeComponent() BtnMergeAll2.Location = new Point(95, 150); BtnMergeAll2.Name = "BtnMergeAll2"; BtnMergeAll2.Size = new Size(155, 39); - BtnMergeAll2.TabIndex = 6; + BtnMergeAll2.TabIndex = 4; BtnMergeAll2.Text = "Start mixing"; BtnMergeAll2.TextAlign = ContentAlignment.MiddleRight; BtnMergeAll2.UseVisualStyleBackColor = true; @@ -140,7 +143,7 @@ private void InitializeComponent() btnOutputF2.Location = new Point(256, 150); btnOutputF2.Name = "btnOutputF2"; btnOutputF2.Size = new Size(155, 39); - btnOutputF2.TabIndex = 15; + btnOutputF2.TabIndex = 5; btnOutputF2.Text = "Output folder"; btnOutputF2.TextAlign = ContentAlignment.MiddleRight; btnOutputF2.UseVisualStyleBackColor = true; diff --git a/UI/MergeAllMediaForm.cs b/UI/MergeAllMediaForm.cs index 826d4a6..da82465 100644 --- a/UI/MergeAllMediaForm.cs +++ b/UI/MergeAllMediaForm.cs @@ -56,7 +56,7 @@ private void BtnVideo_Click(object sender, EventArgs e) var archivo = new OpenFileDialog(); archivo.InitialDirectory = recordingsFolder; - archivo.Filter = "Video files|*.avi;*.mkv;*.wmv|All files|*.*"; + archivo.Filter = "Video files|*.mkv;*.avi;*.wmv|All files|*.*"; archivo.Multiselect = false; if (archivo.ShowDialog() == DialogResult.OK) @@ -77,7 +77,7 @@ private void BtnDeskAudio_Click(object sender, EventArgs e) var archivo = new OpenFileDialog(); archivo.InitialDirectory = recordingsFolder; archivo.Filter = "Audio files|*.wav;*.aac|All files|*.*"; - archivo.Multiselect = false; + archivo.Multiselect = false; if (archivo.ShowDialog() == DialogResult.OK) { @@ -97,7 +97,7 @@ private void BtnMicAudio_Click(object sender, EventArgs e) var archivo = new OpenFileDialog(); archivo.InitialDirectory = recordingsFolder; archivo.Filter = "Audio files|*.wav;*.aac|All files|*.*"; - archivo.Multiselect = false; + archivo.Multiselect = false; if (archivo.ShowDialog() == DialogResult.OK) { diff --git a/UI/MergeVideoAudioForm.Designer.cs b/UI/MergeVideoAudioForm.Designer.cs index 629514a..1423a45 100644 --- a/UI/MergeVideoAudioForm.Designer.cs +++ b/UI/MergeVideoAudioForm.Designer.cs @@ -50,7 +50,7 @@ private void InitializeComponent() BtnMergeAll.Location = new Point(95, 150); BtnMergeAll.Name = "BtnMergeAll"; BtnMergeAll.Size = new Size(155, 39); - BtnMergeAll.TabIndex = 13; + BtnMergeAll.TabIndex = 3; BtnMergeAll.Text = "Start mixing"; BtnMergeAll.TextAlign = ContentAlignment.MiddleRight; BtnMergeAll.UseVisualStyleBackColor = true; @@ -62,6 +62,7 @@ private void InitializeComponent() txtAudioDesk.Font = new Font("Segoe UI", 8F); txtAudioDesk.Location = new Point(256, 60); txtAudioDesk.Name = "txtAudioDesk"; + txtAudioDesk.ReadOnly = true; txtAudioDesk.RightToLeft = RightToLeft.Yes; txtAudioDesk.Size = new Size(216, 22); txtAudioDesk.TabIndex = 10; @@ -72,6 +73,7 @@ private void InitializeComponent() txtVideoPath.Font = new Font("Segoe UI", 8F); txtVideoPath.Location = new Point(256, 21); txtVideoPath.Name = "txtVideoPath"; + txtVideoPath.ReadOnly = true; txtVideoPath.RightToLeft = RightToLeft.Yes; txtVideoPath.Size = new Size(216, 22); txtVideoPath.TabIndex = 9; @@ -88,7 +90,7 @@ private void InitializeComponent() BtnDeskAudio.Location = new Point(14, 49); BtnDeskAudio.Name = "BtnDeskAudio"; BtnDeskAudio.Size = new Size(236, 41); - BtnDeskAudio.TabIndex = 8; + BtnDeskAudio.TabIndex = 2; BtnDeskAudio.Text = "Select an audio file"; BtnDeskAudio.TextAlign = ContentAlignment.MiddleRight; BtnDeskAudio.UseVisualStyleBackColor = true; @@ -106,7 +108,7 @@ private void InitializeComponent() BtnVideo.Location = new Point(14, 10); BtnVideo.Name = "BtnVideo"; BtnVideo.Size = new Size(236, 41); - BtnVideo.TabIndex = 7; + BtnVideo.TabIndex = 1; BtnVideo.Text = "Select a video file"; BtnVideo.TextAlign = ContentAlignment.MiddleRight; BtnVideo.UseVisualStyleBackColor = true; @@ -123,7 +125,7 @@ private void InitializeComponent() btnOutputF.Location = new Point(256, 150); btnOutputF.Name = "btnOutputF"; btnOutputF.Size = new Size(155, 39); - btnOutputF.TabIndex = 14; + btnOutputF.TabIndex = 4; btnOutputF.Text = "Output folder"; btnOutputF.TextAlign = ContentAlignment.MiddleRight; btnOutputF.UseVisualStyleBackColor = true; diff --git a/UI/RecorderScreenMainWindow.Designer.cs b/UI/RecorderScreenMainWindow.Designer.cs index b6b0e32..13ecf42 100644 --- a/UI/RecorderScreenMainWindow.Designer.cs +++ b/UI/RecorderScreenMainWindow.Designer.cs @@ -210,7 +210,7 @@ private void InitializeComponent() BtnExit.Margin = new Padding(4, 3, 4, 3); BtnExit.Name = "BtnExit"; BtnExit.Size = new Size(143, 39); - BtnExit.TabIndex = 11; + BtnExit.TabIndex = 12; BtnExit.Text = " Exit"; BtnExit.UseVisualStyleBackColor = true; BtnExit.Click += BtnExit_Click; @@ -255,7 +255,7 @@ private void InitializeComponent() comboBoxCodec.Location = new Point(230, 99); comboBoxCodec.Name = "comboBoxCodec"; comboBoxCodec.Size = new Size(136, 23); - comboBoxCodec.TabIndex = 4; + comboBoxCodec.TabIndex = 6; // // crownGroupBox1 // @@ -287,7 +287,7 @@ private void InitializeComponent() comboBoxBitrate.Location = new Point(372, 99); comboBoxBitrate.Name = "comboBoxBitrate"; comboBoxBitrate.Size = new Size(61, 23); - comboBoxBitrate.TabIndex = 5; + comboBoxBitrate.TabIndex = 7; // // RefreshMonitors // @@ -344,7 +344,7 @@ private void InitializeComponent() ComboBoxFormat.Location = new Point(230, 45); ComboBoxFormat.Name = "ComboBoxFormat"; ComboBoxFormat.Size = new Size(203, 23); - ComboBoxFormat.TabIndex = 5; + ComboBoxFormat.TabIndex = 4; // // CheckBoxAllMonitors // @@ -354,7 +354,7 @@ private void InitializeComponent() CheckBoxAllMonitors.Location = new Point(10, 128); CheckBoxAllMonitors.Name = "CheckBoxAllMonitors"; CheckBoxAllMonitors.Size = new Size(146, 21); - CheckBoxAllMonitors.TabIndex = 6; + CheckBoxAllMonitors.TabIndex = 12; CheckBoxAllMonitors.Text = "Capture all monitors"; CheckBoxAllMonitors.CheckedChanged += CheckBoxAllMonitors_CheckedChanged; // @@ -366,7 +366,7 @@ private void InitializeComponent() comboBoxFps.Location = new Point(8, 99); comboBoxFps.Name = "comboBoxFps"; comboBoxFps.Size = new Size(203, 23); - comboBoxFps.TabIndex = 6; + comboBoxFps.TabIndex = 5; // // labelFps // @@ -407,7 +407,7 @@ private void InitializeComponent() comboBoxAudioSource.Location = new Point(10, 58); comboBoxAudioSource.Name = "comboBoxAudioSource"; comboBoxAudioSource.Size = new Size(277, 23); - comboBoxAudioSource.TabIndex = 6; + comboBoxAudioSource.TabIndex = 8; // // ComboBoxMicrophone // @@ -417,7 +417,7 @@ private void InitializeComponent() ComboBoxMicrophone.Location = new Point(9, 186); ComboBoxMicrophone.Name = "ComboBoxMicrophone"; ComboBoxMicrophone.Size = new Size(278, 23); - ComboBoxMicrophone.TabIndex = 8; + ComboBoxMicrophone.TabIndex = 10; // // ComboBoxSpeaker // @@ -427,7 +427,7 @@ private void InitializeComponent() ComboBoxSpeaker.Location = new Point(10, 137); ComboBoxSpeaker.Name = "ComboBoxSpeaker"; ComboBoxSpeaker.Size = new Size(277, 23); - ComboBoxSpeaker.TabIndex = 7; + ComboBoxSpeaker.TabIndex = 9; // // crownGroupBox3 // diff --git a/UI/RecorderScreenMainWindow.cs b/UI/RecorderScreenMainWindow.cs index d20332a..dac3335 100644 --- a/UI/RecorderScreenMainWindow.cs +++ b/UI/RecorderScreenMainWindow.cs @@ -28,7 +28,7 @@ private void InitializeForm() { GetTextsMain(); CheckMonitors(); - OpenAudioComponents(); + InitializeAudioComponents(); InitializeComboBoxes(); CreateOutputFolder(); SetKeyPreview(); @@ -50,6 +50,15 @@ private void CreateOutputFolder() } } + private void InitializeAudioComponents() + { + ScreenAudioMic.OpenComp(); + ComboBoxMicrophone.DataSource = ScreenAudioMic.cboDIspositivos.DataSource; + + ScreenAudioDesktop.OpenComp(); + ComboBoxSpeaker.DataSource = ScreenAudioDesktop.cboDIspositivos.DataSource; + } + private void InitializeComboBoxes() { comboBoxCodec.Items.AddRange(new[] { "H264 (Default)", "MPEG-4", "H264 NVENC (Nvidia)", "H264 AMF (AMD)" }); @@ -58,35 +67,12 @@ private void InitializeComboBoxes() comboBoxFps.Items.AddRange(new[] { "30", "60" }); comboBoxFps.SelectedIndex = 0; - comboBoxBitrate.Items.AddRange(new[] { "2000k", "4000k", "6000k", "8000k", "10000k", "15000k", "20000k" }); + comboBoxBitrate.Items.AddRange(new[] { "2000k", "4000k", "6000k", "8000k", "10000k", "15000k", "20000k", "30000k" }); comboBoxBitrate.SelectedIndex = 0; - ComboBoxFormat.Items.AddRange(new[] { ".avi", ".mkv", ".wmv" }); + ComboBoxFormat.Items.AddRange(new[] { ".mkv", ".avi", ".wmv" }); ComboBoxFormat.SelectedIndex = 0; - - } - - private void OpenAudioComponents() - { - ScreenAudioMic.OpenComp(); - ComboBoxMicrophone.DataSource = ScreenAudioMic.cboDIspositivos.DataSource; - - ScreenAudioDesktop.OpenComp(); - ComboBoxSpeaker.DataSource = ScreenAudioDesktop.cboDIspositivos.DataSource; - } - - private void btnStartRecording_Click(object sender, EventArgs e) - { - var format = ComboBoxFormat.SelectedItem.ToString(); - VideoName = $"Video.{DateTime.Now.ToString(DateFormat)}.{format.TrimStart('.')}"; - LbTimer.ForeColor = Color.IndianRed; - TimeRec = DateTime.Now; - CountRecVideo.Enabled = true; - - RecordAudio(); - VideoCodecs(); - DisableElementsUI(); } private void CheckMonitors() @@ -118,124 +104,77 @@ private void CheckBoxAllMonitors_CheckedChanged(object sender, EventArgs e) } } - private void VideoCodecs() + private void btnStartRecording_Click(object sender, EventArgs e) + { + var format = ComboBoxFormat.SelectedItem.ToString(); + VideoName = $"Video.{DateTime.Now.ToString(DateFormat)}.{format.TrimStart('.')}"; + LbTimer.ForeColor = Color.IndianRed; + TimeRec = DateTime.Now; + CountRecVideo.Enabled = true; + + RecordAudio(); + VideoCodecs(); + DisableElementsUI(); + } + + private void StartRecordingProcess(string codec, int fps, string bitrate, string screenArgs) { - if (CheckBoxAllMonitors.Checked == true) + try { - switch (comboBoxCodec.SelectedItem) + string ffmpegArgs = $"{ResourcePath} -f gdigrab -framerate {fps} {screenArgs} -c:v {codec} -b:v {bitrate} Recordings/{VideoName}"; + + ProcessStartInfo processInfo = new("cmd.exe", $"/c {ffmpegArgs}") { - case "H264 (Default)": - { - int fps = int.Parse((string)comboBoxFps.SelectedItem); - string Bitrate = (string)comboBoxBitrate.SelectedItem; - ProcessStartInfo ProcessId = new("cmd.exe", $"/c {ResourcePath} -f gdigrab -framerate " + fps + " -i desktop -c:v h264_mf -qp 0 -b:v " + Bitrate + " Recordings/" + VideoName + ""); - ProcessId.WindowStyle = ProcessWindowStyle.Hidden; - ProcessId.CreateNoWindow = true; - ProcessId.RedirectStandardOutput = true; - Process.Start(ProcessId); - break; - } - - case "MPEG-4": - { - int fps = int.Parse((string)comboBoxFps.SelectedItem); - string Bitrate = (string)comboBoxBitrate.SelectedItem; - ProcessStartInfo ProcessId = new("cmd.exe", $"/c {ResourcePath} -f gdigrab -framerate " + fps + " -i desktop -c:v mpeg4 -b:v " + Bitrate + " -preset medium Recordings/" + VideoName + ""); - ProcessId.WindowStyle = ProcessWindowStyle.Hidden; - ProcessId.CreateNoWindow = true; - ProcessId.RedirectStandardOutput = true; - Process.Start(ProcessId); - break; - } - - case "H264 NVENC (Nvidia)": - { - int fps = int.Parse((string)comboBoxFps.SelectedItem); - string Bitrate = (string)comboBoxBitrate.SelectedItem; - ProcessStartInfo ProcessId = new("cmd.exe", $"/c {ResourcePath} -f gdigrab -framerate " + fps + " -i desktop -c:v h264_nvenc -qp 0 -b:v " + Bitrate + " Recordings/" + VideoName + ""); - ProcessId.WindowStyle = ProcessWindowStyle.Hidden; - ProcessId.CreateNoWindow = true; - ProcessId.RedirectStandardOutput = true; - Process.Start(ProcessId); - break; - } - - case "H264 AMF (AMD)": - { - int fps = int.Parse((string)comboBoxFps.SelectedItem); - string Bitrate = (string)comboBoxBitrate.SelectedItem; - ProcessStartInfo ProcessId = new("cmd.exe", $"/c {ResourcePath} -f gdigrab -framerate " + fps + " -i desktop -c:v h264_amf -qp 0 -b:v " + Bitrate + " Recordings/" + VideoName + ""); - ProcessId.WindowStyle = ProcessWindowStyle.Hidden; - ProcessId.CreateNoWindow = true; - ProcessId.RedirectStandardOutput = true; - Process.Start(ProcessId); - break; - } - } + WindowStyle = ProcessWindowStyle.Hidden, + CreateNoWindow = true, + RedirectStandardOutput = true + }; + Process.Start(processInfo); + } + catch (Exception ex) + { + MessageBox.Show($"Failed to start recording: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void VideoCodecs() + { + int fps = int.Parse((string)comboBoxFps.SelectedItem); + string bitrate = (string)comboBoxBitrate.SelectedItem; + string codecArgs; + string codec; + if (CheckBoxAllMonitors.Checked) + { + codecArgs = "-i desktop"; } else { - switch (comboBoxCodec.SelectedItem) - { - case "H264 (Default)": - { - Screen selectedScreen = Screen.AllScreens[comboBoxMonitors.SelectedIndex]; - string Bitrate = (string)comboBoxBitrate.SelectedItem; - Rectangle bounds = selectedScreen.Bounds; - string getScreen = string.Format("-f gdigrab -framerate {0} -offset_x {1} -offset_y {2} -video_size {3}x{4} -i desktop -c:v h264_mf -qp 0 -b:v " + Bitrate + " -preset medium Recordings/{5}", comboBoxFps.SelectedItem, bounds.Left, bounds.Top, bounds.Width, bounds.Height, VideoName); - ProcessStartInfo ProcessId = new("cmd.exe", $"/c {ResourcePath} " + getScreen); - ProcessId.WindowStyle = ProcessWindowStyle.Hidden; - ProcessId.CreateNoWindow = true; - ProcessId.RedirectStandardOutput = true; - Process.Start(ProcessId); - break; - } - - case "MPEG-4": - { - Screen selectedScreen = Screen.AllScreens[comboBoxMonitors.SelectedIndex]; - string Bitrate = (string)comboBoxBitrate.SelectedItem; - Rectangle bounds = selectedScreen.Bounds; - string getScreen = string.Format("-f gdigrab -framerate {0} -offset_x {1} -offset_y {2} -video_size {3}x{4} -i desktop -c:v mpeg4 -b:v " + Bitrate + " -preset medium Recordings/{5}", comboBoxFps.SelectedItem, bounds.Left, bounds.Top, bounds.Width, bounds.Height, VideoName); - ProcessStartInfo ProcessId = new("cmd.exe", $"/c {ResourcePath} " + getScreen); - ProcessId.WindowStyle = ProcessWindowStyle.Hidden; - ProcessId.CreateNoWindow = true; - ProcessId.RedirectStandardOutput = true; - Process.Start(ProcessId); - break; - } - - case "H264 NVENC (Nvidia)": - { - Screen selectedScreen = Screen.AllScreens[comboBoxMonitors.SelectedIndex]; - string Bitrate = (string)comboBoxBitrate.SelectedItem; - Rectangle bounds = selectedScreen.Bounds; - string getScreen = string.Format("-f gdigrab -framerate {0} -offset_x {1} -offset_y {2} -video_size {3}x{4} -i desktop -c:v h264_nvenc -qp 0 -b:v " + Bitrate + " Recordings/{5}", comboBoxFps.SelectedItem, bounds.Left, bounds.Top, bounds.Width, bounds.Height, VideoName); - ProcessStartInfo ProcessId = new("cmd.exe", $"/c {ResourcePath} " + getScreen); - ProcessId.WindowStyle = ProcessWindowStyle.Hidden; - ProcessId.CreateNoWindow = true; - ProcessId.RedirectStandardOutput = true; - Process.Start(ProcessId); - break; - } - - case "H264 AMF (AMD)": - { - Screen selectedScreen = Screen.AllScreens[comboBoxMonitors.SelectedIndex]; - string Bitrate = (string)comboBoxBitrate.SelectedItem; - Rectangle bounds = selectedScreen.Bounds; - string getScreen = string.Format("-f gdigrab -framerate {0} -offset_x {1} -offset_y {2} -video_size {3}x{4} -show_region 1 -i desktop -c:v h264_amf -qp 0 -b:v " + Bitrate + " Recordings/{5}", comboBoxFps.SelectedItem, bounds.Left, bounds.Top, bounds.Width, bounds.Height, VideoName); - ProcessStartInfo ProcessId = new("cmd.exe", $"/c {ResourcePath} " + getScreen); - ProcessId.WindowStyle = ProcessWindowStyle.Hidden; - ProcessId.CreateNoWindow = true; - ProcessId.RedirectStandardOutput = true; - Process.Start(ProcessId); - break; - } - } + Screen selectedScreen = Screen.AllScreens[comboBoxMonitors.SelectedIndex]; + Rectangle bounds = selectedScreen.Bounds; + codecArgs = $"-offset_x {bounds.Left} -offset_y {bounds.Top} -video_size {bounds.Width}x{bounds.Height} -i desktop"; + } + + switch (comboBoxCodec.SelectedItem.ToString()) + { + case "H264 (Default)": + codec = "h264_mf -qp 0"; + break; + case "MPEG-4": + codec = "mpeg4 -preset medium"; + break; + case "H264 NVENC (Nvidia)": + codec = "h264_nvenc -qp 0"; + break; + case "H264 AMF (AMD)": + codec = "h264_amf -qp 0"; + break; + default: + codec = "h264_mf -qp 0"; + break; } + StartRecordingProcess(codec, fps, bitrate, codecArgs); } private void RecordAudio() @@ -244,33 +183,45 @@ private void RecordAudio() if (selectedOption == StringsEN.TwoTrack) { - if (WaveIn.DeviceCount > 0) - { - RecMic(); - } - else - { - MessageBox.Show(StringsEN.message3, "Error"); - } - RecSpeaker(); + RecordTwoTracks(); } else if (selectedOption == StringsEN.Desktop) { - RecSpeaker(); + RecordDesktopAudio(); } else if (selectedOption == StringsEN.Microphone) { - if (WaveIn.DeviceCount > 0) - { - RecMic(); - } - else - { - MessageBox.Show(StringsEN.message3, "Error"); - } + RecordMicrophone(); } } + private void RecordTwoTracks() + { + if (WaveIn.DeviceCount == 0) + { + MessageBox.Show(StringsEN.message3, "Error"); + return; + } + + RecMic(); + RecSpeaker(); + } + + private void RecordDesktopAudio() + { + RecSpeaker(); + } + + private void RecordMicrophone() + { + if (WaveIn.DeviceCount == 0) + { + MessageBox.Show(StringsEN.message3, "Error"); + return; + } + + RecMic(); + } private void CheckAudioStop() { @@ -306,19 +257,49 @@ private void CheckAudioStop() soundPlayer.Stop(); } - private void CheckFfmpegProcces() { - foreach (Process proceso in Process.GetProcesses()) + var ffmpegProcesses = Process.GetProcessesByName("ffmpeg"); + + foreach (var process in ffmpegProcesses) { - if (proceso.ProcessName == "ffmpeg") + try + { + if (process.MainModule.FileName.Contains(ResourcePath)) + { + process.Kill(); + process.WaitForExit(); + } + } + catch (Exception ex) { - proceso.Kill(); + MessageBox.Show($"Failed to stop ffmpeg process: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + } + + private void StopRecordingProcess() + { + EnableElementsUI(); + CheckAudioStop(); + CheckFfmpegProcces(); + } + + private void BtnStop_Click(object sender, EventArgs e) + { + try + { + LbTimer.ForeColor = Color.White; + LbTimer.Text = "00:00:00"; + CountRecVideo.Enabled = false; + StopRecordingProcess(); + + } + catch (Exception) + { + return; + } - Process proc = Process.GetProcessById(ProcessId); - proc.Kill(); } private static void RecMic() @@ -343,68 +324,7 @@ private static void RecSpeaker() ScreenAudioDesktop.waveIn.StartRecording(); } - #region Testing things with VideoCodecs - /*private void StartRecordingProcess(string codec, int fps, string bitrate, string screenArgs) - { - try - { - string ffmpegArgs = $"{ResourcePath} -f gdigrab -framerate {fps} {screenArgs} -c:v {codec} -b:v {bitrate} Recordings/{VideoName}"; - - ProcessStartInfo processInfo = new("cmd.exe", $"/c {ffmpegArgs}") - { - WindowStyle = ProcessWindowStyle.Hidden, - CreateNoWindow = true, - RedirectStandardOutput = true - }; - Process.Start(processInfo); - } - catch (Exception ex) - { - MessageBox.Show($"Failed to start recording: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void VideoCodecs() - { - int fps = int.Parse((string)comboBoxFps.SelectedItem); - string bitrate = (string)comboBoxBitrate.SelectedItem; - string codecArgs; - string codec; - - if (CheckBoxAllMonitors.Checked) - { - codecArgs = "-i desktop"; - } - else - { - Screen selectedScreen = Screen.AllScreens[comboBoxMonitors.SelectedIndex]; - Rectangle bounds = selectedScreen.Bounds; - codecArgs = $"-offset_x {bounds.Left} -offset_y {bounds.Top} -video_size {bounds.Width}x{bounds.Height} -i desktop"; - } - - switch (comboBoxCodec.SelectedItem.ToString()) - { - case "H264 (Default)": - codec = "h264_mf -qp 0"; - break; - case "MPEG-4": - codec = "mpeg4 -preset medium"; - break; - case "H264 NVENC (Nvidia)": - codec = "h264_nvenc -qp 0"; - break; - case "H264 AMF (AMD)": - codec = "h264_amf -qp 0"; - break; - default: - codec = "h264_mf -qp 0"; - break; - } - - StartRecordingProcess(codec, fps, bitrate, codecArgs); - }*/ - #endregion - + #region Some shit about UI private void DisableElementsUI() { comboBoxMonitors.Enabled = false; @@ -421,7 +341,7 @@ private void DisableElementsUI() comboBoxAudioSource.Enabled = false; } - private void StopRec() + private void EnableElementsUI() { btnStartRecording.Enabled = true; comboBoxCodec.Enabled = true; @@ -435,27 +355,8 @@ private void StopRec() menuStrip1.Enabled = true; comboBoxBitrate.Enabled = true; comboBoxAudioSource.Enabled = true; - - CheckAudioStop(); - CheckFfmpegProcces(); - } - - private void BtnStop_Click(object sender, EventArgs e) - { - try - { - LbTimer.ForeColor = Color.White; - LbTimer.Text = "00:00:00"; - CountRecVideo.Enabled = false; - StopRec(); - - } - catch (Exception) - { - return; - } - } + #endregion private void BtnExit_Click(object sender, EventArgs e) { @@ -588,14 +489,14 @@ private void SaveUserSettingsComboboxRec() Settings.Default.AudioSourceIndex = comboBoxAudioSource.SelectedIndex; } + #endregion + private void RecorderScreenForm_FormClosed(object sender, FormClosedEventArgs e) { SaveUserSettingsComboboxRec(); Settings.Default.Save(); } - #endregion - private void CountRecVideo_Tick(object sender, EventArgs e) { var Difference = DateTime.Now.Subtract(TimeRec);