Ejemplo n.º 1
0
        IVideoWriterItem HandleVideoEncoder(StartCmdOptions StartOptions, out IVideoWriterProvider VideoWriterKind)
        {
            var selected = _videoWriterProviders
                           .Select(M => new
            {
                kind   = M,
                writer = M.ParseCli(StartOptions.Encoder)
            })
                           .FirstOrDefault(M => M.writer != null);

            if (selected != null)
            {
                VideoWriterKind = selected.kind;

                return(selected.writer);
            }

            var ffmpegExists           = FFmpegService.FFmpegExists;
            var sharpAviWriterProvider = ServiceProvider.Get <SharpAviWriterProvider>();

            // Rolling
            if (ffmpegExists && Regex.IsMatch(StartOptions.Encoder, @"^roll:\d+$"))
            {
                var duration = int.Parse(StartOptions.Encoder.Substring(5));

                VideoWriterKind = ServiceProvider.Get <FFmpegWriterProvider>();

                return(new FFmpegRollingWriterItem(duration));
            }

            VideoWriterKind = sharpAviWriterProvider;
            return(sharpAviWriterProvider.First());
        }
Ejemplo n.º 2
0
        static void HandleVideoEncoder(MainViewModel ViewModel, StartCmdOptions StartOptions)
        {
            if (StartOptions.Encoder == null)
                return;

            var video = ViewModel.VideoViewModel;

            // FFMpeg
            if (FFMpegService.FFMpegExists && Regex.IsMatch(StartOptions.Encoder, @"^ffmpeg:\d+$"))
            {
                var index = int.Parse(StartOptions.Encoder.Substring(7));

                video.SelectedVideoWriterKind = ServiceProvider.Get<FFMpegWriterProvider>();

                if (index < video.AvailableVideoSources.Count)
                    video.SelectedVideoWriter = video.AvailableVideoWriters[index];
            }

            // SharpAvi
            else if (ServiceProvider.FileExists("SharpAvi.dll") && Regex.IsMatch(StartOptions.Encoder, @"^sharpavi:\d+$"))
            {
                var index = int.Parse(StartOptions.Encoder.Substring(9));

                video.SelectedVideoWriterKind = ServiceProvider.Get<SharpAviWriterProvider>();

                if (index < video.AvailableVideoSources.Count)
                    video.SelectedVideoWriter = video.AvailableVideoWriters[index];
            }

            // Gif
            else if (StartOptions.Encoder == "gif")
            {
                video.SelectedVideoWriterKind = ServiceProvider.Get<GifWriterProvider>();
            }
        }
Ejemplo n.º 3
0
        IVideoWriterItem HandleVideoEncoder(StartCmdOptions StartOptions, out IVideoWriterProvider VideoWriterKind)
        {
            var ffmpegExists           = FFmpegService.FFmpegExists;
            var sharpAviWriterProvider = ServiceProvider.Get <SharpAviWriterProvider>();

            // FFmpeg
            if (ffmpegExists && Regex.IsMatch(StartOptions.Encoder, @"^ffmpeg:\d+$"))
            {
                var index = int.Parse(StartOptions.Encoder.Substring(7));

                var ffmpegWriterProvider = ServiceProvider.Get <FFmpegWriterProvider>();
                var writers = ffmpegWriterProvider.ToArray();

                if (index < writers.Length)
                {
                    VideoWriterKind = ffmpegWriterProvider;

                    return(writers[index]);
                }
            }

            // SharpAvi
            else if (ServiceProvider.FileExists("SharpAvi.dll") && Regex.IsMatch(StartOptions.Encoder, @"^sharpavi:\d+$"))
            {
                var index = int.Parse(StartOptions.Encoder.Substring(9));

                var writers = sharpAviWriterProvider.ToArray();

                if (index < writers.Length)
                {
                    VideoWriterKind = sharpAviWriterProvider;

                    return(writers[index]);
                }
            }

            // Stream
            else if (ffmpegExists && Regex.IsMatch(StartOptions.Encoder, @"^stream:\S+$"))
            {
                var url = StartOptions.Encoder.Substring(7);
                _settings.FFmpeg.CustomStreamingUrl = url;

                VideoWriterKind = ServiceProvider.Get <StreamingWriterProvider>();

                return(StreamingWriterProvider.GetCustomStreamingCodec());
            }

            // Rolling
            else if (ffmpegExists && Regex.IsMatch(StartOptions.Encoder, @"^roll:\d+$"))
            {
                var duration = int.Parse(StartOptions.Encoder.Substring(5));

                VideoWriterKind = ServiceProvider.Get <FFmpegWriterProvider>();

                return(new FFmpegRollingWriterItem(duration));
            }

            VideoWriterKind = sharpAviWriterProvider;
            return(sharpAviWriterProvider.First());
        }
Ejemplo n.º 4
0
        void Loop(StartCmdOptions StartOptions)
        {
            if (StartOptions.Length > 0)
            {
                var elapsed = 0;

                Write(TimeSpan.Zero);

                while (elapsed++ < StartOptions.Length)
                {
                    Thread.Sleep(1000);
                    Write(new string('\b', 8) + TimeSpan.FromSeconds(elapsed));
                }

                Write(new string('\b', 8));
            }
            else
            {
                const string recordingText = "Press p to pause or resume, q to quit";

                WriteLine(recordingText);

                char ReadChar()
                {
                    if (IsInputRedirected)
                    {
                        var line = ReadLine();

                        if (line != null && line.Length == 1)
                        {
                            return(line[0]);
                        }

                        return(char.MinValue);
                    }

                    return(char.ToLower(ReadKey(true).KeyChar));
                }

                char c;

                do
                {
                    c = ReadChar();

                    if (c != 'p')
                    {
                        continue;
                    }

                    _recordingModel.OnPauseExecute();

                    if (_recordingModel.RecorderState != RecorderState.Paused)
                    {
                        WriteLine("Resumed");
                    }
                } while (c != 'q');
            }
        }
Ejemplo n.º 5
0
        static void Start(MainViewModel ViewModel, StartCmdOptions StartOptions)
        {
            ViewModel.Settings.IncludeCursor = StartOptions.Cursor;

            ViewModel.Settings.Clicks.Display = StartOptions.Clicks;

            ViewModel.Settings.Keystrokes.Display = StartOptions.Keys;

            if (File.Exists(StartOptions.FileName))
            {
                WriteLine("Output File Already Exists");

                return;
            }

            HandleVideoSource(ViewModel, StartOptions);

            HandleVideoEncoder(ViewModel, StartOptions);

            HandleAudioSource(ViewModel, StartOptions);

            HandleWebcam(StartOptions);

            ViewModel.Settings.Video.FrameRate = StartOptions.FrameRate;

            ViewModel.Settings.Audio.Quality = StartOptions.AudioQuality;
            ViewModel.Settings.Video.Quality = StartOptions.VideoQuality;

            if (!ViewModel.RecordCommand.CanExecute(null))
            {
                WriteLine("Nothing to Record");

                return;
            }

            if (StartOptions.Delay > 0)
            {
                Thread.Sleep(StartOptions.Delay);
            }

            if (!ViewModel.StartRecording(StartOptions.FileName))
            {
                return;
            }

            Task.Factory.StartNew(() =>
            {
                Loop(ViewModel, StartOptions);

                ViewModel.StopRecording().Wait();

                Application.Exit();
            });

            // MouseKeyHook requires a Window Handle to register
            Application.Run(new ApplicationContext());
        }
Ejemplo n.º 6
0
        void HandleWebcam(StartCmdOptions StartOptions)
        {
            if (StartOptions.Webcam != -1 && StartOptions.Webcam < _webcamModel.AvailableCams.Count - 1)
            {
                _webcamModel.SelectedCam = _webcamModel.AvailableCams[StartOptions.Webcam + 1];

                // HACK: Sleep to prevent AccessViolationException
                Thread.Sleep(500);
            }
        }
Ejemplo n.º 7
0
        static void HandleWebcam(StartCmdOptions StartOptions)
        {
            var webcam = ServiceProvider.Get <IWebCamProvider>();

            if (StartOptions.Webcam != -1 && StartOptions.Webcam < webcam.AvailableCams.Count - 1)
            {
                webcam.SelectedCam = webcam.AvailableCams[StartOptions.Webcam + 1];

                // Sleep to prevent AccessViolationException
                Thread.Sleep(500);
            }
        }
Ejemplo n.º 8
0
        private void HandleWebCam(StartCmdOptions startOptions)
        {
            if (startOptions.WebCam == -1 || startOptions.WebCam >= _webCamProvider.AvailableCams.Count - 1)
            {
                return;
            }

            _webCamProvider.SelectedCam = _webCamProvider.AvailableCams[startOptions.WebCam + 1];

            // Sleep to prevent AccessViolationException
            Thread.Sleep(500);
        }
Ejemplo n.º 9
0
        static void HandleAudioSource(MainViewModel ViewModel, StartCmdOptions StartOptions)
        {
            var source = ViewModel.AudioSource;

            if (StartOptions.Microphone != -1 && StartOptions.Microphone < source.AvailableRecordingSources.Count - 1)
            {
                source.SelectedRecordingSource = source.AvailableRecordingSources[StartOptions.Microphone + 1];
            }

            if (StartOptions.Speaker != -1 && StartOptions.Speaker < source.AvailableLoopbackSources.Count - 1)
            {
                source.SelectedLoopbackSource = source.AvailableLoopbackSources[StartOptions.Speaker + 1];
            }
        }
Ejemplo n.º 10
0
        void HandleVideoEncoder(StartCmdOptions StartOptions)
        {
            if (StartOptions.Encoder == null)
            {
                return;
            }

            // FFmpeg
            if (FFmpegService.FFmpegExists && Regex.IsMatch(StartOptions.Encoder, @"^ffmpeg:\d+$"))
            {
                var index = int.Parse(StartOptions.Encoder.Substring(7));

                _videoWritersViewModel.SelectedVideoWriterKind = ServiceProvider.Get <FFmpegWriterProvider>();

                if (index < _videoWritersViewModel.AvailableVideoWriters.Count)
                {
                    _videoWritersViewModel.SelectedVideoWriter = _videoWritersViewModel.AvailableVideoWriters[index];
                }
            }

            // SharpAvi
            else if (ServiceProvider.FileExists("SharpAvi.dll") && Regex.IsMatch(StartOptions.Encoder, @"^sharpavi:\d+$"))
            {
                var index = int.Parse(StartOptions.Encoder.Substring(9));

                _videoWritersViewModel.SelectedVideoWriterKind = ServiceProvider.Get <SharpAviWriterProvider>();

                if (index < _videoWritersViewModel.AvailableVideoWriters.Count)
                {
                    _videoWritersViewModel.SelectedVideoWriter = _videoWritersViewModel.AvailableVideoWriters[index];
                }
            }

            // Gif
            else if (StartOptions.Encoder == "gif")
            {
                _videoWritersViewModel.SelectedVideoWriterKind = ServiceProvider.Get <GifWriterProvider>();
            }

            // Stream
            else if (FFmpegService.FFmpegExists && Regex.IsMatch(StartOptions.Encoder, @"^stream:\S+$"))
            {
                var url = StartOptions.Encoder.Substring(7);
                _settings.FFmpeg.CustomStreamingUrl = url;

                _videoWritersViewModel.SelectedVideoWriterKind = ServiceProvider.Get <StreamingWriterProvider>();

                _videoWritersViewModel.SelectedVideoWriter = StreamingItem.CustomUrl;
            }
        }
Ejemplo n.º 11
0
        static void HandleAudioSource(MainViewModel ViewModel, StartCmdOptions StartOptions)
        {
            var source = ViewModel.AudioSource;

            if (StartOptions.Microphone != -1 && StartOptions.Microphone < source.AvailableRecordingSources.Count)
            {
                source.AvailableRecordingSources[StartOptions.Microphone].Active = true;
            }

            if (StartOptions.Speaker != -1 && StartOptions.Speaker < source.AvailableLoopbackSources.Count)
            {
                source.AvailableLoopbackSources[StartOptions.Speaker].Active = true;
            }
        }
Ejemplo n.º 12
0
        void HandleAudioSource(StartCmdOptions StartOptions)
        {
            var audioSource = ServiceProvider.Get <AudioSource>();

            if (StartOptions.Microphone != -1 && StartOptions.Microphone < audioSource.AvailableRecordingSources.Count)
            {
                _settings.Audio.Enabled = true;
                audioSource.AvailableRecordingSources[StartOptions.Microphone].Active = true;
            }

            if (StartOptions.Speaker != -1 && StartOptions.Speaker < audioSource.AvailableLoopbackSources.Count)
            {
                _settings.Audio.Enabled = true;
                audioSource.AvailableLoopbackSources[StartOptions.Speaker].Active = true;
            }
        }
Ejemplo n.º 13
0
        IVideoWriterItem HandleVideoEncoder(StartCmdOptions StartOptions, out IVideoWriterProvider VideoWriterKind)
        {
            var selected = _videoWriterProviders
                           .Select(M => new
            {
                kind   = M,
                writer = M.ParseCli(StartOptions.Encoder)
            })
                           .FirstOrDefault(M => M.writer != null);

            if (selected != null)
            {
                VideoWriterKind = selected.kind;

                return(selected.writer);
            }

            var sharpAviWriterProvider = ServiceProvider.Get <SharpAviWriterProvider>();

            // Steps in video
            if (StartOptions.Encoder == "steps:video")
            {
                _settings.Video.RecorderMode = RecorderMode.Steps;

                VideoWriterKind = null;
                return(new StepsVideoWriterItem(sharpAviWriterProvider.First()));
            }

            // Steps in set of images
            if (StartOptions.Encoder == "steps:images")
            {
                _settings.Video.RecorderMode = RecorderMode.Steps;

                VideoWriterKind = null;
                return(new ImageFolderWriterItem());
            }

            VideoWriterKind = sharpAviWriterProvider;
            return(sharpAviWriterProvider.First());
        }
Ejemplo n.º 14
0
        IVideoWriterItem HandleVideoEncoder(StartCmdOptions StartOptions, out IVideoWriterProvider VideoWriterKind)
        {
            var selected = _videoWriterProviders
                           .Select(M => new
            {
                kind   = M,
                writer = M.ParseCli(StartOptions.Encoder)
            })
                           .FirstOrDefault(M => M.writer != null);

            if (selected != null)
            {
                VideoWriterKind = selected.kind;

                return(selected.writer);
            }

            var sharpAviWriterProvider = ServiceProvider.Get <SharpAviWriterProvider>();

            VideoWriterKind = sharpAviWriterProvider;
            return(sharpAviWriterProvider.First());
        }
Ejemplo n.º 15
0
        void HandleAudioSource(StartCmdOptions StartOptions, out IAudioItem Microphone, out IAudioItem Speaker)
        {
            Microphone = Speaker = null;

            var mics = _audioSource
                       .Microphones
                       .ToArray();

            var speakers = _audioSource
                           .Speakers
                           .ToArray();

            if (StartOptions.Microphone != -1 && StartOptions.Microphone < mics.Length)
            {
                _settings.Audio.RecordMicrophone = true;
                Microphone = mics[StartOptions.Microphone];
            }

            if (StartOptions.Speaker != -1 && StartOptions.Speaker < speakers.Length)
            {
                _settings.Audio.RecordSpeaker = true;
                Speaker = speakers[StartOptions.Speaker];
            }
        }
Ejemplo n.º 16
0
        IEnumerable <IAudioItem> HandleAudioSource(StartCmdOptions StartOptions)
        {
            var sources = _audioSource.GetSources();

            var mics = sources
                       .Where(M => !M.IsLoopback)
                       .ToArray();

            var speakers = sources
                           .Where(M => M.IsLoopback)
                           .ToArray();

            if (StartOptions.Microphone != -1 && StartOptions.Microphone < mics.Length)
            {
                _settings.Audio.Enabled = true;
                yield return(mics[StartOptions.Microphone]);
            }

            if (StartOptions.Speaker != -1 && StartOptions.Speaker < speakers.Length)
            {
                _settings.Audio.Enabled = true;
                yield return(speakers[StartOptions.Speaker]);
            }
        }
Ejemplo n.º 17
0
        static void Start(MainViewModel ViewModel, StartCmdOptions StartOptions)
        {
            if (StartOptions.Cursor)
                ViewModel.Settings.IncludeCursor = true;

            if (StartOptions.Clicks)
                ViewModel.Settings.Clicks.Display = true;

            if (StartOptions.Keys)
                ViewModel.Settings.Keystrokes.Display = true;

            if (File.Exists(StartOptions.FileName))
            {
                WriteLine("Output File Already Exists");

                return;
            }

            HandleVideoSource(ViewModel, StartOptions);

            HandleVideoEncoder(ViewModel, StartOptions);

            HandleAudioSource(ViewModel, StartOptions);

            ViewModel.Settings.Video.FrameRate = StartOptions.FrameRate;

            ViewModel.Settings.Audio.Quality = StartOptions.AudioQuality;
            ViewModel.Settings.Video.Quality = StartOptions.VideoQuality;

            if (!ViewModel.RecordCommand.CanExecute(null))
            {
                WriteLine("Nothing to Record");

                return;
            }

            if (StartOptions.Delay > 0)
                Thread.Sleep(StartOptions.Delay);

            if (!ViewModel.StartRecording(StartOptions.FileName))
                return;

            if (StartOptions.Length > 0)
            {
                var elapsed = 0;

                Write(TimeSpan.Zero);

                while (elapsed++ < StartOptions.Length)
                {
                    Thread.Sleep(1000);
                    Write(new string('\b', 8) + TimeSpan.FromSeconds(elapsed));
                }

                Write(new string('\b', 8));
            }
            else
            {
                const string recordingText = "Press p to pause or resume, q to quit";

                WriteLine(recordingText);

                char ReadChar()
                {
                    if (IsInputRedirected)
                    {
                        var line = ReadLine();

                        if (line != null && line.Length == 1)
                            return line[0];

                        return char.MinValue;
                    }

                    return char.ToLower(ReadKey(true).KeyChar);
                }

                char c;

                do
                {
                    c = ReadChar();

                    if (c != 'p')
                        continue;
                    
                    ViewModel.PauseCommand.ExecuteIfCan();

                    if (ViewModel.RecorderState != RecorderState.Paused)
                    {
                        WriteLine("Resumed");
                    }
                } while (c != 'q');
            }

            Task.Run(async () => await ViewModel.StopRecording()).Wait();
        }
Ejemplo n.º 18
0
        static void Start(MainViewModel ViewModel, StartCmdOptions StartOptions)
        {
            ViewModel.Settings.IncludeCursor = StartOptions.Cursor;

            ViewModel.Settings.Clicks.Display = StartOptions.Clicks;

            ViewModel.Settings.Keystrokes.Display = StartOptions.Keys;

            ViewModel.Settings.Elapsed.Display = StartOptions.ElapseTime;

            if (StartOptions.ScreenWidth != -1 && StartOptions.ScreenHeight != -1)
            {
                ViewModel.Settings.ScreenWidth = StartOptions.ScreenWidth;

                ViewModel.Settings.ScreenHeight = StartOptions.ScreenHeight;
            }

            if (File.Exists(StartOptions.FileName))
            {
                if (!StartOptions.Overwrite)
                {
                    if (!ServiceProvider.MessageProvider
                        .ShowYesNo("Output File Already Exists, Do you want to overwrite?", ""))
                    {
                        return;
                    }
                }

                File.Delete(StartOptions.FileName);
            }

            HandleVideoSource(ViewModel, StartOptions);

            HandleVideoEncoder(ViewModel, StartOptions);

            HandleAudioSource(ViewModel, StartOptions);

            HandleWebcam(StartOptions);

            ViewModel.Settings.Video.FrameRate = StartOptions.FrameRate;

            ViewModel.Settings.Audio.Quality = StartOptions.AudioQuality;
            ViewModel.Settings.Video.Quality = StartOptions.VideoQuality;

            ViewModel.Settings.FFmpeg.Resize       = StartOptions.FfmpegResize;
            ViewModel.Settings.FFmpeg.ResizeWidth  = StartOptions.FfmpegResizeWidth;
            ViewModel.Settings.FFmpeg.ResizeHeight = StartOptions.FfmpegResizeHeight;
            ViewModel.Settings.FFmpeg.RawBackup    = StartOptions.FfmpegRawBackup;

            if (!ViewModel.RecordingViewModel.RecordCommand.CanExecute(null))
            {
                WriteLine("Nothing to Record");

                return;
            }

            if (StartOptions.Delay > 0)
            {
                Thread.Sleep(StartOptions.Delay);
            }

            if (!ViewModel.RecordingViewModel.StartRecording(StartOptions.FileName))
            {
                return;
            }

            Task.Factory.StartNew(() =>
            {
                Loop(ViewModel, StartOptions);

                ViewModel.RecordingViewModel.StopRecording().Wait();

                Application.Exit();
            });

            // MouseKeyHook requires a Window Handle to register
            Application.Run(new ApplicationContext());
        }
Ejemplo n.º 19
0
        static void Start(MainViewModel ViewModel, StartCmdOptions StartOptions)
        {
            var settings = ViewModel.Settings;

            settings.IncludeCursor      = StartOptions.Cursor;
            settings.Clicks.Display     = StartOptions.Clicks;
            settings.Keystrokes.Display = StartOptions.Keys;

            if (File.Exists(StartOptions.FileName))
            {
                if (!StartOptions.Overwrite)
                {
                    if (!ServiceProvider.MessageProvider
                        .ShowYesNo("Output File Already Exists, Do you want to overwrite?", ""))
                    {
                        return;
                    }
                }

                File.Delete(StartOptions.FileName);
            }

            HandleVideoSource(ViewModel.VideoSourcesViewModel, StartOptions);

            HandleVideoEncoder(ViewModel.VideoWritersViewModel, StartOptions);

            HandleAudioSource(ViewModel.AudioSource, settings.Audio, StartOptions);

            HandleWebcam(StartOptions);

            if (StartOptions.FrameRate is int frameRate)
            {
                settings.Video.FrameRate = frameRate;
            }

            if (StartOptions.AudioQuality is int aq)
            {
                settings.Audio.Quality = aq;
            }

            if (StartOptions.VideoQuality is int vq)
            {
                settings.Video.Quality = vq;
            }

            if (!ViewModel.RecordingViewModel.RecordCommand.CanExecute(null))
            {
                WriteLine("Nothing to Record");

                return;
            }

            if (StartOptions.Delay > 0)
            {
                Thread.Sleep(StartOptions.Delay);
            }

            if (!ViewModel.RecordingViewModel.StartRecording(StartOptions.FileName))
            {
                return;
            }

            Task.Factory.StartNew(() =>
            {
                Loop(ViewModel, StartOptions);

                ViewModel.RecordingViewModel.StopRecording().Wait();

                Application.Exit();
            });

            // MouseKeyHook requires a Window Handle to register
            Application.Run(new ApplicationContext());
        }
Ejemplo n.º 20
0
        public void Start(StartCmdOptions StartOptions)
        {
            _settings.IncludeCursor      = StartOptions.Cursor;
            _settings.Clicks.Display     = StartOptions.Clicks;
            _settings.Keystrokes.Display = StartOptions.Keys;

            if (File.Exists(StartOptions.FileName))
            {
                if (!StartOptions.Overwrite)
                {
                    if (!ServiceProvider.MessageProvider
                        .ShowYesNo("Output File Already Exists, Do you want to overwrite?", ""))
                    {
                        return;
                    }
                }

                File.Delete(StartOptions.FileName);
            }

            HandleVideoSource(StartOptions);

            HandleVideoEncoder(StartOptions);

            HandleAudioSource(StartOptions);

            HandleWebcam(StartOptions);

            if (StartOptions.FrameRate is int frameRate)
            {
                _settings.Video.FrameRate = frameRate;
            }

            if (StartOptions.AudioQuality is int aq)
            {
                _settings.Audio.Quality = aq;
            }

            if (StartOptions.VideoQuality is int vq)
            {
                _settings.Video.Quality = vq;
            }

            if (StartOptions.Delay > 0)
            {
                Thread.Sleep(StartOptions.Delay);
            }

            if (!_recordingModel.StartRecording(StartOptions.FileName))
            {
                return;
            }

            Task.Factory.StartNew(() =>
            {
                Loop(StartOptions);

                _recordingModel.StopRecording().Wait();

                Application.Exit();
            });

            // MouseKeyHook requires a Window Handle to register
            Application.Run(new ApplicationContext());
        }
Ejemplo n.º 21
0
        static void HandleAudioSource(AudioSource AudioSource, AudioSettings Settings, StartCmdOptions StartOptions)
        {
            if (StartOptions.Microphone != -1 && StartOptions.Microphone < AudioSource.AvailableRecordingSources.Count)
            {
                Settings.Enabled = true;
                AudioSource.AvailableRecordingSources[StartOptions.Microphone].Active = true;
            }

            if (StartOptions.Speaker != -1 && StartOptions.Speaker < AudioSource.AvailableLoopbackSources.Count)
            {
                Settings.Enabled = true;
                AudioSource.AvailableLoopbackSources[StartOptions.Speaker].Active = true;
            }
        }
Ejemplo n.º 22
0
        public void Start(StartCmdOptions StartOptions)
        {
            _settings.IncludeCursor      = StartOptions.Cursor;
            _settings.Clicks.Display     = StartOptions.Clicks;
            _settings.Keystrokes.Display = StartOptions.Keys;

            if (File.Exists(StartOptions.FileName))
            {
                if (!StartOptions.Overwrite)
                {
                    if (!_messageProvider
                        .ShowYesNo("Output File Already Exists, Do you want to overwrite?", ""))
                    {
                        return;
                    }
                }

                File.Delete(StartOptions.FileName);
            }

            var videoSourceKind = HandleVideoSource(StartOptions);

            if (videoSourceKind == null)
            {
                WriteLine("Video source not set or invalid");

                return;
            }

            HandleAudioSource(StartOptions, out var mic, out var speaker);

            HandleWebcam(StartOptions);

            if (StartOptions.FrameRate is int frameRate)
            {
                _settings.Video.FrameRate = frameRate;
            }

            if (StartOptions.AudioQuality is int aq)
            {
                _settings.Audio.Quality = aq;
            }

            if (StartOptions.VideoQuality is int vq)
            {
                _settings.Video.Quality = vq;
            }

            if (StartOptions.Replay is int replayDuration && replayDuration > 0)
            {
                _settings.Video.RecorderMode   = RecorderMode.Replay;
                _settings.Video.ReplayDuration = replayDuration;
            }

            var videoWriter = HandleVideoEncoder(StartOptions, out _);

            if (StartOptions.Delay > 0)
            {
                Thread.Sleep(StartOptions.Delay);
            }

            if (!_recordingModel.StartRecording(new RecordingModelParams
            {
                VideoSourceKind = videoSourceKind,
                VideoWriter = videoWriter,
                Microphone = mic,
                Speaker = speaker
            }, StartOptions.FileName))
            {
                return;
            }

            Task.Factory.StartNew(() =>
            {
                Loop(StartOptions);

                _recordingModel.StopRecording().Wait();

                Application.Exit();
            });

            // MouseKeyHook requires a Window Handle to register
            Application.Run(new ApplicationContext());
        }
Ejemplo n.º 23
0
        public void Start(StartCmdOptions StartOptions)
        {
            _settings.IncludeCursor      = StartOptions.Cursor;
            _settings.Clicks.Display     = StartOptions.Clicks;
            _settings.Keystrokes.Display = StartOptions.Keys;

            if (File.Exists(StartOptions.FileName))
            {
                if (!StartOptions.Overwrite)
                {
                    if (!_messageProvider
                        .ShowYesNo("Output File Already Exists, Do you want to overwrite?", ""))
                    {
                        return;
                    }
                }

                File.Delete(StartOptions.FileName);
            }

            var videoSourceKind = HandleVideoSource(StartOptions);

            if (videoSourceKind == null)
            {
                WriteLine("Video source not set or invalid");

                return;
            }

            var videoWriter = HandleVideoEncoder(StartOptions, out var videoWriterKind);

            if (StartOptions.Roll is int rollDuration && rollDuration > 0)
            {
                var internalWriter = videoWriter;
                videoWriter = new FFmpegRollingWriterItem(rollDuration, M => internalWriter.GetVideoFileWriter(M));
            }

            var audioSources = HandleAudioSource(StartOptions);

            HandleWebcam(StartOptions);

            if (StartOptions.FrameRate is int frameRate)
            {
                _settings.Video.FrameRate = frameRate;
            }

            if (StartOptions.AudioQuality is int aq)
            {
                _settings.Audio.Quality = aq;
            }

            if (StartOptions.VideoQuality is int vq)
            {
                _settings.Video.Quality = vq;
            }

            if (StartOptions.Delay > 0)
            {
                Thread.Sleep(StartOptions.Delay);
            }

            if (!_recordingModel.StartRecording(new RecordingModelParams
            {
                VideoSourceKind = videoSourceKind,
                VideoWriter = videoWriter,
                AudioItems = audioSources.Select(M => M.ToIsActive(true))
            }, StartOptions.FileName))
            {
                return;
            }

            Task.Factory.StartNew(() =>
            {
                Loop(StartOptions);

                _recordingModel.StopRecording().Wait();

                Application.Exit();
            });

            // MouseKeyHook requires a Window Handle to register
            Application.Run(new ApplicationContext());
        }