From 4447731cbc9a0fcc92dcc28f9e0c413cc65f32e4 Mon Sep 17 00:00:00 2001 From: N00MKRAD <61149547+n00mkrad@users.noreply.github.com> Date: Mon, 10 Feb 2025 21:03:05 +0100 Subject: [PATCH] Test "1x interpolation" (dedupe, then interp back to orig. frame count) Also fixes issue with having dedupe enabled on videos that have no (<5%) dupes --- CodeLegacy/Data/InterpSettings.cs | 2 ++ CodeLegacy/Magick/Dedupe.cs | 13 +++++++++++-- CodeLegacy/Os/VapourSynthUtils.cs | 7 +++++-- CodeLegacy/Ui/MainUiFunctions.cs | 3 +++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CodeLegacy/Data/InterpSettings.cs b/CodeLegacy/Data/InterpSettings.cs index 24e90a5..982999c 100644 --- a/CodeLegacy/Data/InterpSettings.cs +++ b/CodeLegacy/Data/InterpSettings.cs @@ -31,6 +31,7 @@ namespace Flowframes public string interpFolder; public bool inputIsFrames; public bool dedupe; + public bool noRedupe; private Size _inputResolution = new Size(); public Size InputResolution @@ -93,6 +94,7 @@ namespace Flowframes framesExt = ""; interpExt = ""; _inputResolution = new Size(0, 0); + noRedupe = dedupe && interpFactor == 1; SetPaths(inPath); RefreshExtensions(ai: ai); } diff --git a/CodeLegacy/Magick/Dedupe.cs b/CodeLegacy/Magick/Dedupe.cs index 4d6c2c4..55166eb 100644 --- a/CodeLegacy/Magick/Dedupe.cs +++ b/CodeLegacy/Magick/Dedupe.cs @@ -228,7 +228,7 @@ namespace Flowframes.Magick public static async Task CreateDupesFile(string framesPath, string ext) { - bool debug = Config.GetBool("dupeScanDebug", false); + bool debug = true; Config.GetBool("dupeScanDebug", false); FileInfo[] frameFiles = IoUtils.GetFileInfosSorted(framesPath, false, "*" + ext); @@ -259,7 +259,8 @@ namespace Flowframes.Magick } } - File.WriteAllText(Path.Combine(framesPath.GetParentDir(), "dupes.json"), frames.ToJson(true)); + // string tempDir = + // File.WriteAllText(Path.Combine(framesPath.GetParentDir(), "dupes.json"), frames.ToJson(true)); } public static async Task CreateFramesFileVideo(string videoPath, bool loop) @@ -300,6 +301,14 @@ namespace Flowframes.Magick float keepPercentage = (float)inputFrames.Count / frameCount * 100f; Logger.Log($"Dedupe: Kept {inputFrames.Count}/{frameCount} frames ({keepPercentage.ToString("0.#")}%)"); + if(Interpolate.currentSettings != null && Interpolate.currentSettings.interpFactor == 1) + { + Interpolate.currentSettings.interpFactor = ((float)frameCount / inputFrames.Count); + Logger.Log($"Dedupe: Factor is 1, will not redupe; overriding factor to {frameCount}/{inputFrames.Count} = {Interpolate.currentSettings.interpFactor.ToString("0.######")}", true); + } + + Logger.Log($""); + if (keepPercentage > 95f) { Logger.Log("Dedupe: Less than 5% duplicate frames detected, will not dedupe."); diff --git a/CodeLegacy/Os/VapourSynthUtils.cs b/CodeLegacy/Os/VapourSynthUtils.cs index fd60d83..6d236e0 100644 --- a/CodeLegacy/Os/VapourSynthUtils.cs +++ b/CodeLegacy/Os/VapourSynthUtils.cs @@ -98,7 +98,10 @@ namespace Flowframes.Os l.Add($""); l.Add($"srcFrames = len(clip)"); l.Add(Debugger.IsAttached ? $"clip = core.text.FrameNum(clip, alignment=7, scale={txtScale}) # Input frame counter" : ""); - l.Add(GetDedupeLines(s)); + + if(s.InterpSettings.dedupe) + l.Add(GetDedupeLines(s)); + l.Add($""); if (trim) @@ -140,7 +143,7 @@ namespace Flowframes.Os string interpStr = alwaysPreferFactorOverFps || Interpolate.currentMediaFile.IsVfr ? $"factor_num={factor.Numerator}, factor_den={factor.Denominator}" : $"fps_num={outFps.Numerator}, fps_den={outFps.Denominator}"; l.Add($"clip = core.rife.RIFE(clip, {interpStr}, model_path={mdlPath}, gpu_id={s.GpuId.ToString().Replace("-1", "None")}, gpu_thread={s.GpuThreads}, tta={s.Tta}, uhd={s.Uhd}, sc={sc})"); // Interpolate - if (s.Dedupe && !s.Realtime) + if (s.Dedupe && !s.InterpSettings.noRedupe && !s.Realtime) { l.Add(GetRedupeLines(s)); l.Add($""); diff --git a/CodeLegacy/Ui/MainUiFunctions.cs b/CodeLegacy/Ui/MainUiFunctions.cs index 5b3cf3f..c4b27d8 100644 --- a/CodeLegacy/Ui/MainUiFunctions.cs +++ b/CodeLegacy/Ui/MainUiFunctions.cs @@ -169,6 +169,9 @@ namespace Flowframes.Ui public static float ValidateInterpFactor (float factor) { + if (factor == 1) + return factor; + AiInfo ai = Program.mainForm.GetAi(); if (ai.NameInternal == Implementations.rifeNcnn.NameInternal && !Program.mainForm.GetModel(ai).Dir.Contains("v4"))