Example #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);
                }

                FFMpegLog.Reset();
            }

            if (VideoViewModel.SelectedVideoWriterKind is GifWriterProvider &&
                Settings.Gif.VariableFrameRate &&
                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 = VideoViewModel.AvailableVideoSourceKinds[0];
                }

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

                return(false);
            }

            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;

            try
            {
                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);
            }
Example #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);
                }

                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);
            }