diff --git a/HelpersLib/Extensions/StringExtensions.cs b/HelpersLib/Extensions/StringExtensions.cs index 52986ce5b..c496bb9a2 100644 --- a/HelpersLib/Extensions/StringExtensions.cs +++ b/HelpersLib/Extensions/StringExtensions.cs @@ -212,5 +212,10 @@ public static bool IsNumber(this string text) return true; } + + public static string[] Lines(this string text) + { + return text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); + } } } \ No newline at end of file diff --git a/ScreenCaptureLib/Screencast/FFmpegHelper.cs b/ScreenCaptureLib/Screencast/FFmpegHelper.cs index 77af42ef5..c2b96c272 100644 --- a/ScreenCaptureLib/Screencast/FFmpegHelper.cs +++ b/ScreenCaptureLib/Screencast/FFmpegHelper.cs @@ -144,9 +144,50 @@ public static bool ExtractFFmpeg(string zipPath, string extractPath) return false; } - public void ListDevices() + public DirectShowDevices GetDirectShowDevices() { - WriteInput("-list_devices true -f dshow -i dummy"); + DirectShowDevices devices = new DirectShowDevices(); + + if (File.Exists(Options.FFmpeg.CLIPath)) + { + string arg = "-list_devices true -f dshow -i dummy"; + Open(Options.FFmpeg.CLIPath, arg); + string output = Errors.ToString(); + string[] lines = output.Lines(); + bool isVideo = true; + Regex regex = new Regex("\\[dshow @ \\w+\\] \"(.+)\"", RegexOptions.Compiled | RegexOptions.CultureInvariant); + foreach (string line in lines) + { + if (line.EndsWith("] DirectShow video devices", StringComparison.InvariantCulture)) + { + isVideo = true; + continue; + } + else if (line.EndsWith("] DirectShow audio devices", StringComparison.InvariantCulture)) + { + isVideo = false; + continue; + } + + Match match = regex.Match(line); + + if (match.Success) + { + string value = match.Groups[1].Value; + + if (isVideo) + { + devices.VideoDevices.Add(value); + } + else + { + devices.AudioDevices.Add(value); + } + } + } + } + + return devices; } public override void Close() @@ -154,4 +195,10 @@ public override void Close() WriteInput("q"); } } + + public class DirectShowDevices + { + public List VideoDevices = new List(); + public List AudioDevices = new List(); + } } \ No newline at end of file diff --git a/ScreenCaptureLib/Screencast/FFmpegOptionsForm.Designer.cs b/ScreenCaptureLib/Screencast/FFmpegOptionsForm.Designer.cs index 1b317d538..33c07a4be 100644 --- a/ScreenCaptureLib/Screencast/FFmpegOptionsForm.Designer.cs +++ b/ScreenCaptureLib/Screencast/FFmpegOptionsForm.Designer.cs @@ -70,6 +70,7 @@ private void InitializeComponent() this.gbSource = new System.Windows.Forms.GroupBox(); this.gbCodecs = new System.Windows.Forms.GroupBox(); this.gbContainer = new System.Windows.Forms.GroupBox(); + this.btnRefreshSources = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.nudx264CRF)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudQscale)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudVPxCRF)).BeginInit(); @@ -89,7 +90,7 @@ private void InitializeComponent() // lblExt // this.lblExt.AutoSize = true; - this.lblExt.Location = new System.Drawing.Point(8, 36); + this.lblExt.Location = new System.Drawing.Point(8, 26); this.lblExt.Name = "lblExt"; this.lblExt.Size = new System.Drawing.Size(56, 13); this.lblExt.TabIndex = 2; @@ -186,15 +187,15 @@ private void InitializeComponent() // this.cbExtension.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cbExtension.FormattingEnabled = true; - this.cbExtension.Location = new System.Drawing.Point(72, 32); + this.cbExtension.Location = new System.Drawing.Point(72, 22); this.cbExtension.Name = "cbExtension"; - this.cbExtension.Size = new System.Drawing.Size(72, 21); + this.cbExtension.Size = new System.Drawing.Size(88, 21); this.cbExtension.TabIndex = 3; // // lblCodec // this.lblCodec.AutoSize = true; - this.lblCodec.Location = new System.Drawing.Point(8, 28); + this.lblCodec.Location = new System.Drawing.Point(8, 26); this.lblCodec.Name = "lblCodec"; this.lblCodec.Size = new System.Drawing.Size(70, 13); this.lblCodec.TabIndex = 0; @@ -204,9 +205,9 @@ private void InitializeComponent() // this.cboVideoCodec.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cboVideoCodec.FormattingEnabled = true; - this.cboVideoCodec.Location = new System.Drawing.Point(88, 24); + this.cboVideoCodec.Location = new System.Drawing.Point(88, 22); this.cboVideoCodec.Name = "cboVideoCodec"; - this.cboVideoCodec.Size = new System.Drawing.Size(120, 21); + this.cboVideoCodec.Size = new System.Drawing.Size(136, 21); this.cboVideoCodec.TabIndex = 1; // // cbPreset @@ -361,7 +362,7 @@ private void InitializeComponent() this.tpVpx.Controls.Add(this.lblVpxCRF); this.tpVpx.Location = new System.Drawing.Point(4, 22); this.tpVpx.Name = "tpVpx"; - this.tpVpx.Size = new System.Drawing.Size(304, 46); + this.tpVpx.Size = new System.Drawing.Size(312, 46); this.tpVpx.TabIndex = 2; this.tpVpx.Text = "VP8"; this.tpVpx.UseVisualStyleBackColor = true; @@ -381,7 +382,7 @@ private void InitializeComponent() this.tpXvid.Controls.Add(this.lblQscale); this.tpXvid.Location = new System.Drawing.Point(4, 22); this.tpXvid.Name = "tpXvid"; - this.tpXvid.Size = new System.Drawing.Size(304, 46); + this.tpXvid.Size = new System.Drawing.Size(312, 46); this.tpXvid.TabIndex = 3; this.tpXvid.Text = "XviD"; this.tpXvid.UseVisualStyleBackColor = true; @@ -439,15 +440,15 @@ private void InitializeComponent() // this.cboVideoSource.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cboVideoSource.FormattingEnabled = true; - this.cboVideoSource.Location = new System.Drawing.Point(96, 22); + this.cboVideoSource.Location = new System.Drawing.Point(88, 22); this.cboVideoSource.Name = "cboVideoSource"; - this.cboVideoSource.Size = new System.Drawing.Size(120, 21); + this.cboVideoSource.Size = new System.Drawing.Size(136, 21); this.cboVideoSource.TabIndex = 12; // // lblVideoSource // this.lblVideoSource.AutoSize = true; - this.lblVideoSource.Location = new System.Drawing.Point(16, 26); + this.lblVideoSource.Location = new System.Drawing.Point(8, 26); this.lblVideoSource.Name = "lblVideoSource"; this.lblVideoSource.Size = new System.Drawing.Size(72, 13); this.lblVideoSource.TabIndex = 11; @@ -457,17 +458,15 @@ private void InitializeComponent() // this.cboAudioSource.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cboAudioSource.FormattingEnabled = true; - this.cboAudioSource.Items.AddRange(new object[] { - "None"}); - this.cboAudioSource.Location = new System.Drawing.Point(96, 56); + this.cboAudioSource.Location = new System.Drawing.Point(88, 52); this.cboAudioSource.Name = "cboAudioSource"; - this.cboAudioSource.Size = new System.Drawing.Size(120, 21); + this.cboAudioSource.Size = new System.Drawing.Size(136, 21); this.cboAudioSource.TabIndex = 14; // // lblAudioSource // this.lblAudioSource.AutoSize = true; - this.lblAudioSource.Location = new System.Drawing.Point(16, 60); + this.lblAudioSource.Location = new System.Drawing.Point(8, 56); this.lblAudioSource.Name = "lblAudioSource"; this.lblAudioSource.Size = new System.Drawing.Size(72, 13); this.lblAudioSource.TabIndex = 13; @@ -477,15 +476,15 @@ private void InitializeComponent() // this.cboAudioCodec.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cboAudioCodec.FormattingEnabled = true; - this.cboAudioCodec.Location = new System.Drawing.Point(88, 56); + this.cboAudioCodec.Location = new System.Drawing.Point(88, 52); this.cboAudioCodec.Name = "cboAudioCodec"; - this.cboAudioCodec.Size = new System.Drawing.Size(120, 21); + this.cboAudioCodec.Size = new System.Drawing.Size(136, 21); this.cboAudioCodec.TabIndex = 16; // // lblAudioCodec // this.lblAudioCodec.AutoSize = true; - this.lblAudioCodec.Location = new System.Drawing.Point(8, 60); + this.lblAudioCodec.Location = new System.Drawing.Point(8, 56); this.lblAudioCodec.Name = "lblAudioCodec"; this.lblAudioCodec.Size = new System.Drawing.Size(70, 13); this.lblAudioCodec.TabIndex = 15; @@ -510,9 +509,9 @@ private void InitializeComponent() this.gbCodecs.Controls.Add(this.lblAudioCodec); this.gbCodecs.Controls.Add(this.cboVideoCodec); this.gbCodecs.Controls.Add(this.lblCodec); - this.gbCodecs.Location = new System.Drawing.Point(256, 8); + this.gbCodecs.Location = new System.Drawing.Point(248, 8); this.gbCodecs.Name = "gbCodecs"; - this.gbCodecs.Size = new System.Drawing.Size(224, 88); + this.gbCodecs.Size = new System.Drawing.Size(232, 88); this.gbCodecs.TabIndex = 18; this.gbCodecs.TabStop = false; this.gbCodecs.Text = "Codecs"; @@ -521,19 +520,30 @@ private void InitializeComponent() // this.gbContainer.Controls.Add(this.cbExtension); this.gbContainer.Controls.Add(this.lblExt); - this.gbContainer.Location = new System.Drawing.Point(496, 8); + this.gbContainer.Location = new System.Drawing.Point(488, 8); this.gbContainer.Name = "gbContainer"; - this.gbContainer.Size = new System.Drawing.Size(160, 88); + this.gbContainer.Size = new System.Drawing.Size(168, 88); this.gbContainer.TabIndex = 19; this.gbContainer.TabStop = false; this.gbContainer.Text = "Container format"; // + // btnRefreshSources + // + this.btnRefreshSources.Location = new System.Drawing.Point(176, 4); + this.btnRefreshSources.Name = "btnRefreshSources"; + this.btnRefreshSources.Size = new System.Drawing.Size(56, 23); + this.btnRefreshSources.TabIndex = 20; + this.btnRefreshSources.Text = "Refresh"; + this.btnRefreshSources.UseVisualStyleBackColor = true; + this.btnRefreshSources.Click += new System.EventHandler(this.btnRefreshSources_Click); + // // FFmpegOptionsForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.White; this.ClientSize = new System.Drawing.Size(668, 474); + this.Controls.Add(this.btnRefreshSources); this.Controls.Add(this.gbContainer); this.Controls.Add(this.gbCodecs); this.Controls.Add(this.gbSource); @@ -619,5 +629,6 @@ private void InitializeComponent() private System.Windows.Forms.GroupBox gbSource; private System.Windows.Forms.GroupBox gbCodecs; private System.Windows.Forms.GroupBox gbContainer; + private System.Windows.Forms.Button btnRefreshSources; } } \ No newline at end of file diff --git a/ScreenCaptureLib/Screencast/FFmpegOptionsForm.cs b/ScreenCaptureLib/Screencast/FFmpegOptionsForm.cs index 6733a7f46..f15638422 100644 --- a/ScreenCaptureLib/Screencast/FFmpegOptionsForm.cs +++ b/ScreenCaptureLib/Screencast/FFmpegOptionsForm.cs @@ -71,6 +71,8 @@ public FFmpegOptionsForm(ScreencastOptions options) private void SettingsLoad() { // General + RefreshSources(); + cboVideoCodec.Items.AddRange(Helpers.GetEnumDescriptions()); cboVideoCodec.SelectedIndex = (int)Options.FFmpeg.VideoCodec; cboVideoCodec.SelectedIndexChanged += (sender, e) => { UpdateUI(); UpdateExtensions(); }; @@ -107,6 +109,30 @@ private void SettingsLoad() nudQscale.ValueChanged += (sender, e) => UpdateUI(); } + private void RefreshSources() + { + DirectShowDevices devices = null; + Helpers.AsyncJob(() => + { + using (FFmpegHelper ffmpeg = new FFmpegHelper(Options)) + { + devices = ffmpeg.GetDirectShowDevices(); + } + }, + () => + { + cboVideoSource.Items.Clear(); + cboVideoSource.Items.Add("GDI grab"); + cboAudioSource.Items.Clear(); + cboAudioSource.Items.Add("None"); + if (devices != null) + { + cboVideoSource.Items.AddRange(devices.VideoDevices.ToArray()); + cboAudioSource.Items.AddRange(devices.AudioDevices.ToArray()); + } + }); + } + public void SettingsSave() { // General @@ -154,8 +180,11 @@ public void UpdateExtensions() private void buttonFFmpegBrowse_Click(object sender, EventArgs e) { - Helpers.BrowseFile("Browse for ffmpeg.exe", tbFFmpegPath, Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)); - UpdateUI(); + if (Helpers.BrowseFile("Browse for ffmpeg.exe", tbFFmpegPath, Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles))) + { + RefreshSources(); + UpdateUI(); + } } private void buttonFFmpegHelp_Click(object sender, EventArgs e) @@ -175,7 +204,12 @@ private void DownloaderForm_InstallRequested(string filePath) if (result) { - this.InvokeSafe(() => tbFFmpegPath.Text = extractPath); + this.InvokeSafe(() => + { + tbFFmpegPath.Text = extractPath; + RefreshSources(); + UpdateUI(); + }); MessageBox.Show("FFmpeg successfully downloaded.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } else @@ -211,5 +245,10 @@ private void btnCopyPreview_Click(object sender, EventArgs e) { ClipboardHelpers.CopyText("ffmpeg " + Options.GetFFmpegArgs()); } + + private void btnRefreshSources_Click(object sender, EventArgs e) + { + RefreshSources(); + } } } \ No newline at end of file