Exemplo n.º 1
0
        public bool StartRecording(string FileName = null)
        {
            if (VideoViewModel.SelectedVideoWriterKind is FFMpegWriterProvider ||
                VideoViewModel.SelectedVideoWriterKind is StreamingWriterProvider ||
                (VideoViewModel.SelectedVideoSourceKind is NoVideoSourceProvider && VideoViewModel.SelectedVideoSource is FFMpegAudioItem))
            {
                if (!FFMpegService.FFMpegExists)
                {
                    ServiceProvider.MessageProvider.ShowFFMpegUnavailable();

                    return(false);
                }
            }

            if (VideoViewModel.SelectedVideoWriterKind is GifWriterProvider)
            {
                if (Settings.Audio.Enabled)
                {
                    if (!ServiceProvider.MessageProvider.ShowYesNo("Audio won't be included in the recording.\nDo you want to record?", "Gif does not support Audio"))
                    {
                        return(false);
                    }
                }
            }

            IImageProvider imgProvider;

            try
            {
                imgProvider = GetImageProvider();
            }
            catch (NotSupportedException e) when(VideoViewModel.SelectedVideoSourceKind is DeskDuplSourceProvider)
            {
                var yes = ServiceProvider.MessageProvider.ShowYesNo($"{e.Message}\n\nDo you want to turn off Desktop Duplication.", Loc.ErrorOccured);

                if (yes)
                {
                    VideoViewModel.SelectedVideoSourceKind = VideoViewModel.AvailableVideoSourceKinds[0];
                }

                return(false);
            }
            catch (Exception e)
            {
                ServiceProvider.MessageProvider.ShowError(e.ToString(), e.Message);

                return(false);
            }

            // Window Picker or Screen Picker Cancelled
            if ((VideoViewModel.SelectedVideoSource is WindowPickerItem ||
                 VideoViewModel.SelectedVideoSource is ScreenPickerItem) && imgProvider == null)
            {
                return(false);
            }

            if (VideoViewModel.SelectedVideoWriterKind is GifWriterProvider &&
                Settings.Gif.VariableFrameRate &&
                imgProvider is DeskDuplImageProvider deskDuplImageProvider)
            {
                deskDuplImageProvider.Timeout = 5000;
            }

            Settings.EnsureOutPath();

            _isVideo = !(VideoViewModel.SelectedVideoSourceKind is NoVideoSourceProvider);

            var extension = VideoViewModel.SelectedVideoWriter.Extension;

            if (VideoViewModel.SelectedVideoSource is NoVideoItem x)
            {
                extension = x.Extension;
            }

            _currentFileName = FileName ?? Path.Combine(Settings.OutPath, $"{DateTime.Now:yyyy-MM-dd-HH-mm-ss}{extension}");

            IAudioProvider audioProvider = null;

            try
            {
                if (Settings.Audio.Enabled)
                {
                    audioProvider = AudioSource.GetAudioProvider();
                }
            }
            catch (Exception e)
            {
                ServiceProvider.MessageProvider.ShowError(e.ToString(), e.Message);

                imgProvider?.Dispose();

                return(false);
            }

            IVideoFileWriter videoEncoder;

            try
            {
                videoEncoder = GetVideoFileWriter(imgProvider, audioProvider);
            }
            catch (Exception e)
            {
                ServiceProvider.MessageProvider.ShowError(e.ToString(), e.Message);

                imgProvider?.Dispose();
                audioProvider?.Dispose();

                return(false);
            }

            if (videoEncoder is GifWriter gif && Settings.Gif.VariableFrameRate)
            {
                _recorder = new VFRGifRecorder(gif, imgProvider);
            }
Exemplo n.º 2
0
        public bool StartRecording(string FileName = null)
        {
            if (VideoViewModel.SelectedVideoWriterKind is FFmpegWriterProvider ||
                VideoViewModel.SelectedVideoWriterKind is StreamingWriterProvider ||
                (VideoViewModel.SelectedVideoSourceKind is NoVideoSourceProvider && VideoViewModel.SelectedVideoSource is FFmpegAudioItem))
            {
                if (!FFmpegService.FFmpegExists)
                {
                    ServiceProvider.MessageProvider.ShowFFmpegUnavailable();

                    return(false);
                }
            }

            if (VideoViewModel.SelectedVideoWriterKind is GifWriterProvider)
            {
                if (Settings.Audio.Enabled)
                {
                    if (!ServiceProvider.MessageProvider.ShowYesNo("Audio won't be included in the recording.\nDo you want to record?", "Gif does not support Audio"))
                    {
                        return(false);
                    }
                }
            }

            IImageProvider imgProvider;

            try
            {
                imgProvider = GetImageProvider();
            }
            catch (NotSupportedException e) when(VideoViewModel.SelectedVideoSourceKind is DeskDuplSourceProvider)
            {
                var yes = ServiceProvider.MessageProvider.ShowYesNo($"{e.Message}\n\nDo you want to turn off Desktop Duplication.", Loc.ErrorOccurred);

                if (yes)
                {
                    VideoViewModel.SelectedVideoSourceKind = VideoViewModel.AvailableVideoSourceKinds[0];
                }

                return(false);
            }
            catch (Exception e)
            {
                ServiceProvider.MessageProvider.ShowException(e, e.Message);

                return(false);
            }

            // Window Picker or Screen Picker Cancelled
            if ((VideoViewModel.SelectedVideoSource is WindowPickerItem ||
                 VideoViewModel.SelectedVideoSource is ScreenPickerItem) && imgProvider == null)
            {
                return(false);
            }

            if (VideoViewModel.SelectedVideoWriterKind is GifWriterProvider &&
                Settings.Gif.VariableFrameRate &&
                imgProvider is DeskDuplImageProvider deskDuplImageProvider)
            {
                deskDuplImageProvider.Timeout = 5000;
            }

            Settings.EnsureOutPath();

            _isVideo = !(VideoViewModel.SelectedVideoSourceKind is NoVideoSourceProvider);

            var extension = VideoViewModel.SelectedVideoWriter.Extension;

            if (VideoViewModel.SelectedVideoSource is NoVideoItem x)
            {
                extension = x.Extension;
            }

            _currentFileName = FileName ?? Path.Combine(Settings.OutPath, $"{DateTime.Now:yyyy-MM-dd-HH-mm-ss}{extension}");

            IAudioProvider audioProvider = null;

            try
            {
                if (Settings.Audio.Enabled)
                {
                    audioProvider = AudioSource.GetAudioProvider(Settings.Video.FrameRate);
                }
            }
            catch (Exception e)
            {
                ServiceProvider.MessageProvider.ShowException(e, e.Message);

                imgProvider?.Dispose();

                return(false);
            }

            IVideoFileWriter videoEncoder;

            try
            {
                videoEncoder = GetVideoFileWriter(imgProvider, audioProvider);
            }
            catch (Exception e)
            {
                ServiceProvider.MessageProvider.ShowException(e, e.Message);

                imgProvider?.Dispose();
                audioProvider?.Dispose();

                return(false);
            }

            switch (videoEncoder)
            {
            case GifWriter gif when Settings.Gif.VariableFrameRate:
                _recorder = new VFRGifRecorder(gif, imgProvider);
                break;

            case WithPreviewWriter previewWriter when previewWriter.OriginalWriter is GifWriter gif && Settings.Gif.VariableFrameRate:
                _recorder = new VFRGifRecorder(gif, imgProvider);
                break;

            default:
                if (_isVideo)
                {
                    _recorder = new Recorder(videoEncoder, imgProvider, Settings.Video.FrameRate, audioProvider);
                }
                else if (VideoViewModel.SelectedVideoSource is NoVideoItem audioWriter)
                {
                    _recorder = new Recorder(audioWriter.GetAudioFileWriter(_currentFileName, audioProvider?.WaveFormat, Settings.Audio.Quality), audioProvider);
                }
                break;
            }

            if (VideoViewModel.SelectedVideoSourceKind is RegionSourceProvider)
            {
                _regionProvider.Lock();
            }

            _systemTray.HideNotification();

            if (Settings.UI.MinimizeOnStart)
            {
                _mainWindow.IsMinimized = true;
            }

            RecorderState = RecorderState.Recording;

            _timer?.Stop();
            TimeSpan = TimeSpan.Zero;

            Status.LocalizationKey = Settings.StartDelay > 0 ? nameof(LanguageManager.Waiting) : nameof(LanguageManager.Recording);

            _recorder.ErrorOccurred += E =>
            {
                if (_syncContext != null)
                {
                    _syncContext.Post(S => OnErrorOccurred(E), null);
                }
                else
                {
                    OnErrorOccurred(E);
                }
            };

            if (Settings.StartDelay > 0)
            {
                Task.Factory.StartNew(async() =>
                {
                    await Task.Delay(Settings.StartDelay);

                    Status.LocalizationKey = nameof(LanguageManager.Recording);

                    _recorder.Start();
                });
            }
            else
            {
                _recorder.Start();
            }

            _timing?.Start();
            _timer?.Start();

            return(true);
        }
Exemplo n.º 3
0
        public bool StartRecording(string FileName = null)
        {
            if (VideoViewModel.SelectedVideoWriterKind is FFMpegWriterProvider ||
                VideoViewModel.SelectedVideoWriterKind is StreamingWriterProvider ||
                (VideoViewModel.SelectedVideoSourceKind is NoVideoSourceProvider && VideoViewModel.SelectedVideoSource is FFMpegAudioItem))
            {
                if (!FFMpegService.FFMpegExists)
                {
                    ServiceProvider.MessageProvider.ShowFFMpegUnavailable();

                    return(false);
                }

                FFMpegLog.Reset();
            }

            if (VideoViewModel.SelectedVideoWriterKind is GifWriterProvider &&
                Settings.GifVariable &&
                VideoViewModel.SelectedVideoSourceKind is DeskDuplSourceProvider)
            {
                ServiceProvider.MessageProvider.ShowError("Using Variable Frame Rate GIF with Desktop Duplication is not supported.");

                return(false);
            }

            if (VideoViewModel.SelectedVideoWriterKind is GifWriterProvider)
            {
                if (AudioSource.AudioAvailable)
                {
                    if (!ServiceProvider.MessageProvider.ShowYesNo("Audio won't be included in the recording.\nDo you want to record?", "Gif does not support Audio"))
                    {
                        return(false);
                    }
                }
            }

            if (Duration != 0 && (StartDelay > Duration * 1000))
            {
                ServiceProvider.MessageProvider.ShowError(Loc.DelayGtDuration);

                return(false);
            }

            IImageProvider imgProvider;

            try
            {
                imgProvider = GetImageProvider();
            }
            catch (NotSupportedException e) when(VideoViewModel.SelectedVideoSourceKind is DeskDuplSourceProvider)
            {
                var yes = ServiceProvider.MessageProvider.ShowYesNo($"{e.Message}\n\nDo you want to turn off Desktop Duplication.", Loc.ErrorOccured);

                if (yes)
                {
                    VideoViewModel.SelectedVideoSourceKind = ServiceProvider.Get <ScreenSourceProvider>();
                }

                return(false);
            }
            catch (Exception e)
            {
                ServiceProvider.MessageProvider.ShowError(e.ToString());

                return(false);
            }

            _regionProvider.Lock();

            _systemTray.HideNotification();

            if (Settings.UI.MinimizeOnStart)
            {
                _mainWindow.IsMinimized = true;
            }

            Settings.EnsureOutPath();

            RecorderState = RecorderState.Recording;

            _isVideo = !(VideoViewModel.SelectedVideoSourceKind is NoVideoSourceProvider);

            var extension = VideoViewModel.SelectedVideoWriter.Extension;

            if (VideoViewModel.SelectedVideoSource is NoVideoItem x)
            {
                extension = x.Extension;
            }

            _currentFileName = FileName ?? Path.Combine(Settings.OutPath, $"{DateTime.Now:yyyy-MM-dd-HH-mm-ss}{extension}");

            Status.LocalizationKey = StartDelay > 0 ? nameof(LanguageManager.Waiting) : nameof(LanguageManager.Recording);

            _timer?.Stop();
            TimeSpan = TimeSpan.Zero;

            var audioProvider = AudioSource.GetAudioProvider();

            var videoEncoder = GetVideoFileWriter(imgProvider, audioProvider);

            if (videoEncoder is GifWriter gif && Settings.GifVariable)
            {
                _recorder = new VFRGifRecorder(gif, imgProvider);
            }