private void RefreshSourcesAsync() { btnRefreshSources.Enabled = false; DirectShowDevices devices = null; TaskEx.Run(() => { using (FFmpegHelper ffmpeg = new FFmpegHelper(Options)) { devices = ffmpeg.GetDirectShowDevices(); } }, () => { cboVideoSource.Items.Clear(); cboVideoSource.Items.Add(FFmpegHelper.SourceNone); cboVideoSource.Items.Add(FFmpegHelper.SourceGDIGrab); cboAudioSource.Items.Clear(); cboAudioSource.Items.Add(FFmpegHelper.SourceNone); if (devices != null) { cboVideoSource.Items.AddRange(devices.VideoDevices.ToArray()); cboAudioSource.Items.AddRange(devices.AudioDevices.ToArray()); } cboVideoSource.Text = Options.FFmpeg.VideoSource; cboAudioSource.Text = Options.FFmpeg.AudioSource; btnRefreshSources.Enabled = true; }); }
private async Task RefreshSourcesAsync(bool selectDevices = false) { btnRefreshSources.Enabled = false; DirectShowDevices devices = null; await Task.Run(() => { if (File.Exists(Options.FFmpeg.FFmpegPath)) { using (FFmpegCLIManager ffmpeg = new FFmpegCLIManager(Options.FFmpeg.FFmpegPath)) { devices = ffmpeg.GetDirectShowDevices(); } } }); if (!IsDisposed) { cboVideoSource.Items.Clear(); cboVideoSource.Items.Add(FFmpegCLIManager.SourceNone); cboVideoSource.Items.Add(FFmpegCLIManager.SourceGDIGrab); cboAudioSource.Items.Clear(); cboAudioSource.Items.Add(FFmpegCLIManager.SourceNone); if (devices != null) { cboVideoSource.Items.AddRange(devices.VideoDevices.ToArray()); cboAudioSource.Items.AddRange(devices.AudioDevices.ToArray()); } if (selectDevices && cboVideoSource.Items.Contains(FFmpegCLIManager.SourceVideoDevice)) { Options.FFmpeg.VideoSource = FFmpegCLIManager.SourceVideoDevice; } else if (!cboVideoCodec.Items.Contains(Options.FFmpeg.VideoSource)) { Options.FFmpeg.VideoSource = FFmpegCLIManager.SourceGDIGrab; } cboVideoSource.Text = Options.FFmpeg.VideoSource; if (selectDevices && cboAudioSource.Items.Contains(FFmpegCLIManager.SourceAudioDevice)) { Options.FFmpeg.AudioSource = FFmpegCLIManager.SourceAudioDevice; } else if (!cboAudioSource.Items.Contains(Options.FFmpeg.AudioSource)) { Options.FFmpeg.AudioSource = FFmpegCLIManager.SourceNone; } cboAudioSource.Text = Options.FFmpeg.AudioSource; btnRefreshSources.Enabled = true; } }
public DirectShowDevices GetDirectShowDevices() { DirectShowDevices devices = new DirectShowDevices(); if (File.Exists(Options.FFmpeg.FFmpegPath)) { string arg = "-list_devices true -f dshow -i dummy"; Open(Options.FFmpeg.FFmpegPath, arg); string output = Output.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; } 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 DirectShowDevices GetDirectShowDevices() { DirectShowDevices devices = new DirectShowDevices(); if (File.Exists(Options.FFmpeg.FFmpegPath)) { string arg = "-list_devices true -f dshow -i dummy"; Open(Options.FFmpeg.FFmpegPath, arg); string output = Output.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; } 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; }