From 829b37ca6ac72e58dce191c562890522f2c74001 Mon Sep 17 00:00:00 2001 From: N00MKRAD <61149547+n00mkrad@users.noreply.github.com> Date: Thu, 21 Dec 2023 05:51:28 +0100 Subject: [PATCH] Progress bar is now correct when using FPS limiting --- Code/Magick/Dedupe.cs | 18 ++++++++++-------- Code/Main/Interpolate.cs | 3 +++ Code/Main/InterpolateUtils.cs | 9 ++++++++- Code/Ui/InterpolationProgress.cs | 2 +- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Code/Magick/Dedupe.cs b/Code/Magick/Dedupe.cs index 7be01c8..d4bf7c4 100644 --- a/Code/Magick/Dedupe.cs +++ b/Code/Magick/Dedupe.cs @@ -7,10 +7,6 @@ using System.Threading.Tasks; using System.Threading; using Flowframes.IO; using ImageMagick; -using Flowframes.Os; -using Flowframes.Data; -using System.Drawing; -using Paths = Flowframes.IO.Paths; using Newtonsoft.Json; namespace Flowframes.Magick @@ -117,7 +113,7 @@ namespace Flowframes.Magick } } - System.Threading.Interlocked.Increment(ref statsFramesDeleted); + Interlocked.Increment(ref statsFramesDeleted); if (j+1 == framePaths.Length) return; @@ -126,7 +122,7 @@ namespace Flowframes.Magick } - System.Threading.Interlocked.Increment(ref statsFramesKept); + Interlocked.Increment(ref statsFramesKept); // this frame is different, stop testing agaisnt 'i' // all the frames between i and j are dupes, we can skip them @@ -206,8 +202,14 @@ namespace Flowframes.Magick Logger.Log($"[Deduplication]{testStr} Done. Kept {framesLeft} ({keptPercent}) frames, deleted {framesDeleted} frames.", false, true); if (statsFramesKept <= 0) - Interpolate.Cancel("No frames were left after de-duplication!\n\nTry decreasing the de-duplication threshold."); - } + { + Interpolate.Cancel("No frames were left after de-duplication!\n\nTry decreasing the de-duplication threshold."); + } + else + { + // Interpolate.InterpProgressMultiplier = (framePaths.Length / (float)framesLeft); + } + } static float GetDifference(MagickImage img1, MagickImage img2) { double err = img1.Compare(img2, ErrorMetric.Fuzz); diff --git a/Code/Main/Interpolate.cs b/Code/Main/Interpolate.cs index 6dee670..878baa8 100644 --- a/Code/Main/Interpolate.cs +++ b/Code/Main/Interpolate.cs @@ -26,6 +26,7 @@ namespace Flowframes public static InterpSettings currentSettings; public static MediaFile currentMediaFile; public static bool canceled = false; + public static float InterpProgressMultiplier = 1f; static Stopwatch sw = new Stopwatch(); public static async Task Start() @@ -149,6 +150,8 @@ namespace Flowframes Logger.Log($"Deduplication: Kept {framesLeft} frames."); else Logger.Log($"Deduplication: Kept {framesLeft} ({keptPercent}) frames, deleted {framesDeleted} frames."); + + // InterpProgressMultiplier = (currentMediaFile.FrameCount / (float)framesLeft); } if (!Config.GetBool("allowConsecutiveSceneChanges", true)) diff --git a/Code/Main/InterpolateUtils.cs b/Code/Main/InterpolateUtils.cs index 07ad0d8..53d1fce 100644 --- a/Code/Main/InterpolateUtils.cs +++ b/Code/Main/InterpolateUtils.cs @@ -117,7 +117,7 @@ namespace Flowframes.Main } string fpsLimitValue = Config.Get(Config.Key.maxFps); - float fpsLimit = (fpsLimitValue.Contains("/") ? new Fraction(Config.Get(Config.Key.maxFps)).GetFloat() : fpsLimitValue.GetFloat()); + float fpsLimit = (fpsLimitValue.Contains("/") ? new Fraction(fpsLimitValue).GetFloat() : fpsLimitValue.GetFloat()); int maxFps = s.outSettings.Encoder.GetInfo().MaxFramerate; if (passes && s.outFps.GetFloat() < 1f || (s.outFps.GetFloat() > maxFps && !(fpsLimit > 0 && fpsLimit <= maxFps))) @@ -127,6 +127,13 @@ namespace Flowframes.Main passes = false; } + float fpsLimitFloat = fpsLimitValue.GetFloat(); + + if (fpsLimitFloat > 0) + Interpolate.InterpProgressMultiplier = s.outFps.GetFloat() / fpsLimitFloat; + else + Interpolate.InterpProgressMultiplier = 1f; + if (!passes) I.Cancel("Invalid settings detected.", true); diff --git a/Code/Ui/InterpolationProgress.cs b/Code/Ui/InterpolationProgress.cs index b6cd6a0..42c5ae1 100644 --- a/Code/Ui/InterpolationProgress.cs +++ b/Code/Ui/InterpolationProgress.cs @@ -135,7 +135,7 @@ namespace Flowframes.Ui interpolatedInputFramesCount = ((frames / I.currentSettings.interpFactor).RoundToInt() - 1); //ResumeUtils.Save(); frames = frames.Clamp(0, target); - int percent = (int)Math.Round(((float)frames / target) * 100f); + int percent = (int)Math.Round(((float)frames / target) * 100f * Interpolate.InterpProgressMultiplier); Program.mainForm.SetProgress(percent); float generousTime = ((AiProcess.processTime.ElapsedMilliseconds - AiProcess.lastStartupTimeMs) / 1000f);