public ScreenRecorder(ScreenRecordOutput outputType, ScreencastOptions options, Screenshot screenshot, Rectangle captureRectangle) { if (string.IsNullOrEmpty(options.OutputPath)) { throw new Exception("Screen recorder cache path is empty."); } FPS = options.FPS; DurationSeconds = options.Duration; CaptureRectangle = captureRectangle; CachePath = options.OutputPath; OutputType = outputType; Options = options; switch (OutputType) { default: case ScreenRecordOutput.FFmpeg: Helpers.CreateDirectoryFromFilePath(Options.OutputPath); ffmpeg = new FFmpegCLIManager(Options.FFmpeg.FFmpegPath); ffmpeg.EncodeStarted += OnRecordingStarted; break; case ScreenRecordOutput.GIF: imgCache = new HardDiskCache(Options); break; } this.screenshot = screenshot; }
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; } }