Пример #1
0
        private async Task RenderPreview(bool lower = true)
        {
            try
            {
                StatusBand.Hide();

                var drawingVisual = new DrawingVisual();

                if (lower)
                {
                    using (var dc = drawingVisual.RenderOpen())
                    {
                        if (UserSettings.All.VideoImporter == 0)
                        {
                            dc.DrawVideo(_lowerPlayer, new Rect(0, 0, _lowerPlayer.NaturalVideoWidth, _lowerPlayer.NaturalVideoHeight));
                        }
                        else
                        {
                            //Capture image from FFmpeg.
                            var image = await GetScreencap();

                            //Render image in target.
                            if (image != null)
                            {
                                dc.DrawImage(image, new Rect(0, 0, VideoWidth, VideoHeight));
                            }
                        }
                    }

                    lock (_lock)
                        _lowerRenderTargetBitmap.Render(drawingVisual);
                    return;
                }

                using (var dc = drawingVisual.RenderOpen())
                {
                    if (UserSettings.All.VideoImporter == 0)
                    {
                        dc.DrawVideo(_upperPlayer, new Rect(0, 0, _upperPlayer.NaturalVideoWidth, _upperPlayer.NaturalVideoHeight));
                    }
                    else
                    {
                        //Capture image from FFmpeg.
                        var image = await GetScreencap(false);

                        //Render image in target.
                        if (image != null)
                        {
                            dc.DrawImage(image, new Rect(0, 0, VideoWidth, VideoHeight));
                        }
                    }
                }

                lock (_lock)
                    _upperRenderTargetBitmap.Render(drawingVisual);
            }
            catch (TimeoutException t)
            {
                LogWriter.Log(t, "Impossible to get the preview of the video.");
                StatusBand.Warning(LocalizationHelper.Get("S.ImportVideo.Timeout"));
            }
            catch (Exception e)
            {
                LogWriter.Log(e, "Impossible to get the preview of the video.");
                StatusBand.Error(LocalizationHelper.Get("S.ImportVideo.Error"));
            }
        }
Пример #2
0
        private async Task GetMultipleScreencaps()
        {
            var start  = TimeSpan.FromMilliseconds(SelectionSlider.LowerValue);
            var end    = TimeSpan.FromMilliseconds(SelectionSlider.UpperValue);
            var fps    = FpsIntegerUpDown.Value;
            var count  = CountFrames();
            var folder = Path.Combine(RootFolder, "Import");
            var path   = Path.Combine(folder, $"%0{count.ToString().Length + 1}d.png");

            try
            {
                //Create temporary folder.
                if (Directory.Exists(folder))
                {
                    Directory.Delete(folder, true);
                }

                Directory.CreateDirectory(folder);

                CaptureProgressBar.Value   = 0;
                CaptureProgressBar.Maximum = count;

                var info = new ProcessStartInfo(UserSettings.All.FfmpegLocation)
                {
                    Arguments              = $" -i \"{VideoPath}\" -vsync 2 -progress pipe:1 -vf scale={VideoWidth}:{VideoHeight} -ss {start:hh\\:mm\\:ss\\.fff} -to {end:hh\\:mm\\:ss\\.fff} -hide_banner -c:v png -r {fps} -vframes {count} \"{path}\"",
                    CreateNoWindow         = true,
                    ErrorDialog            = false,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true
                };

                _process = new Process();
                _process.OutputDataReceived += (sender, e) =>
                {
                    Debug.WriteLine(e.Data);

                    if (string.IsNullOrEmpty(e.Data))
                    {
                        return;
                    }

                    var parsed = e.Data.Split('=');

                    switch (parsed[0])
                    {
                    case "frame":
                        Dispatcher?.InvokeAsync(() => { CaptureProgressBar.Value = Convert.ToDouble(parsed[1]); });
                        break;

                    case "progress":
                        if (parsed[1] == "end")
                        {
                            GetFiles(folder);
                        }

                        break;
                    }
                };

                _process.ErrorDataReceived += (sender, e) =>
                {
                    if (!string.IsNullOrEmpty(e.Data))
                    {
                        throw new Exception("Error while capturing frames with FFmpeg.")
                              {
                                  HelpLink = $"Command:\n\r{info.Arguments}\n\rResult:\n\r{e.Data}"
                              }
                    }
                    ;
                };

                _process.StartInfo = info;
                _process.Start();
                _process.BeginOutputReadLine();

                await Task.Factory.StartNew(() => _process.WaitForExit());
            }
            catch (Exception e)
            {
                LogWriter.Log(e, "Error importing frames with FFmpeg");
                ClearImportFolder(folder);

                Splitter.Visibility           = Visibility.Visible;
                DetailsGrid.Visibility        = Visibility.Visible;
                SelectionSlider.IsEnabled     = true;
                OkButton.IsEnabled            = true;
                StatusLabel.Visibility        = Visibility.Collapsed;
                CaptureProgressBar.Visibility = Visibility.Collapsed;

                StatusBand.Error(LocalizationHelper.Get("S.ImportVideo.Error") + Environment.NewLine + e.Message + Environment.NewLine + e.HelpLink);
            }
        }
Пример #3
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            #region Validation

            if (Global.UpdateAvailable == null)
            {
                WhatsNewParagraph.Inlines.Add("Something wrong happened. No update was found.");
                return;
            }

            #endregion

            try
            {
                //Detect if this is portable or installed. Download the proper file.
                IsChocolatey = AppDomain.CurrentDomain.BaseDirectory.EndsWith(@"Chocolatey\lib\screentogif\content\");
                IsInstaller  = Directory.EnumerateFiles(AppDomain.CurrentDomain.BaseDirectory).Any(x => x.ToLowerInvariant().EndsWith("screentogif.visualelementsmanifest.xml"));

                VersionRun.Text = $"{LocalizationHelper.Get("S.Updater.Version")} {Global.UpdateAvailable.Version}";
                SizeRun.Text    = Global.UpdateAvailable.InstallerSize > 0 ? Humanizer.BytesToString(IsInstaller ? Global.UpdateAvailable.InstallerSize : Global.UpdateAvailable.PortableSize) : "";
                TypeRun.Text    = IsInstaller ? LocalizationHelper.Get("S.Updater.Installer") : LocalizationHelper.Get("S.Updater.Portable");

                //If set to download automatically, check if the installer was downloaded.
                if (UserSettings.All.InstallUpdates)
                {
                    //If the update was already downloaded.
                    if (File.Exists(Global.UpdateAvailable.InstallerPath))
                    {
                        DownloadButton.SetResourceReference(ImageButton.TextProperty, "S.Updater.Install");

                        //When the update was prompted manually, the user can set the installer to run the app afterwards.
                        if (WasPromptedManually)
                        {
                            RunAfterwardsCheckBox.Visibility = Visibility.Visible;
                            RunAfterwardsCheckBox.IsChecked  = true;
                        }
                    }
                }

                //Details.
                if (Global.UpdateAvailable.IsFromGithub)
                {
                    //From Github, the description is available.
                    var splited = Global.UpdateAvailable.Description.Split(new[] { '#' }, StringSplitOptions.RemoveEmptyEntries);

                    WhatsNewParagraph.Inlines.Add(splited[0].Replace(" What's new?\r\n\r\n", ""));
                    FixesParagraph.Inlines.Add(splited.Length > 1 ? splited[1].Replace(" Bug fixes:\r\n\r\n", "").Replace(" Fixed:\r\n\r\n", "") : "Aparently nothing.");
                }
                else
                {
                    //If the release detail was obtained by querying Fosshub, no release note is available.
                    MainFlowDocument.Blocks.Remove(WhatsNewParagraphTitle);
                    MainFlowDocument.Blocks.Remove(FixesParagraphTitle);
                    MainFlowDocument.Blocks.Remove(FixesParagraph);

                    var run = new Run();
                    run.SetResourceReference(Run.TextProperty, "S.Updater.Info.NewVersionAvailable");
                    WhatsNewParagraph.Inlines.Add(run);
                }
            }
            catch (Exception ex)
            {
                LogWriter.Log(ex, "Impossible to load the download details");
                StatusBand.Error(LocalizationHelper.Get("S.Updater.Warning.Show"));
            }
        }