From fc2b61dbb288762d7f00c6510463f1dac61591bf Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Wed, 30 Jun 2021 18:49:07 +0200 Subject: [PATCH] AutoEnc: Actually delete old frames instead of overwriting with dummy data --- Code/IO/IOUtils.cs | 5 +++-- Code/Main/AutoEncode.cs | 4 +++- Code/Main/Interpolate.cs | 1 - Code/OS/AiProcess.cs | 11 ++++++----- Code/UI/InterpolationProgress.cs | 4 ++++ 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Code/IO/IOUtils.cs b/Code/IO/IOUtils.cs index 958a58b..4edcc10 100644 --- a/Code/IO/IOUtils.cs +++ b/Code/IO/IOUtils.cs @@ -467,9 +467,10 @@ namespace Flowframes.IO } } - public static bool DeleteIfExists (string path) // Returns true if the file/dir exists + public static bool DeleteIfExists (string path, bool log = false) // Returns true if the file/dir exists { - Logger.Log($"DeleteIfExists({path})", true); + if(log) + Logger.Log($"DeleteIfExists({path})", true); if (!IsPathDirectory(path) && File.Exists(path)) { diff --git a/Code/Main/AutoEncode.cs b/Code/Main/AutoEncode.cs index 0f21ca6..ce6cdf3 100644 --- a/Code/Main/AutoEncode.cs +++ b/Code/Main/AutoEncode.cs @@ -177,7 +177,9 @@ namespace Flowframes.Main if (!FrameIsStillNeeded(interpFramesLines[frame], frame)) // Make sure frames are no longer needed (for dupes) before deleting! { string framePath = Path.Combine(interpFramesPath, interpFramesLines[frame]); - IOUtils.OverwriteFileWithText(framePath); // Overwrite to save space without breaking progress counter + //IOUtils.OverwriteFileWithText(framePath); // Overwrite to save space without breaking progress counter + IOUtils.TryDeleteIfExists(framePath); + InterpolationProgress.deletedFramesCount++; } } diff --git a/Code/Main/Interpolate.cs b/Code/Main/Interpolate.cs index f77695e..e28096b 100644 --- a/Code/Main/Interpolate.cs +++ b/Code/Main/Interpolate.cs @@ -15,7 +15,6 @@ using System.IO; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; -using Win32Interop.Structs; using Padding = Flowframes.Data.Padding; using Utils = Flowframes.Main.InterpolateUtils; diff --git a/Code/OS/AiProcess.cs b/Code/OS/AiProcess.cs index a442e05..dd865f6 100644 --- a/Code/OS/AiProcess.cs +++ b/Code/OS/AiProcess.cs @@ -67,8 +67,9 @@ namespace Flowframes if (Interpolate.canceled) return; Program.mainForm.SetProgress(100); AiProcessSuspend.SetRunning(false); - int interpolatedFrames = IOUtils.GetAmountOfFiles(Interpolate.current.interpFolder, false, "*" + Interpolate.current.interpExt); - InterpolationProgress.UpdateInterpProgress(interpolatedFrames, InterpolationProgress.targetFrames); + int interpFramesFiles = IOUtils.GetAmountOfFiles(Interpolate.current.interpFolder, false, "*" + Interpolate.current.interpExt); + int interpFramesCount = interpFramesFiles + InterpolationProgress.deletedFramesCount; + InterpolationProgress.UpdateInterpProgress(interpFramesCount, InterpolationProgress.targetFrames); string logStr = $"Done running {aiName} - Interpolation took {FormatUtils.Time(processTime.Elapsed)}. Peak Output FPS: {InterpolationProgress.peakFpsOut.ToString("0.00")}"; if (Interpolate.currentlyUsingAutoEnc && AutoEncode.HasWorkToDo()) @@ -80,9 +81,9 @@ namespace Flowframes Logger.Log(logStr); processTime.Stop(); - if(interpolatedFrames < 3) + if(interpFramesCount < 3) { - string amount = interpolatedFrames > 0 ? $"Only {interpolatedFrames}" : "No"; + string amount = interpFramesCount > 0 ? $"Only {interpFramesCount}" : "No"; Interpolate.Cancel($"Interpolation failed - {amount} interpolated frames were created."); return; } @@ -448,7 +449,7 @@ namespace Flowframes { hasShownError = true; bool usingDain = (Interpolate.current.ai.aiName == Networks.dainNcnn.aiName); - string msg = usingDain ? "\n\nTry reducing the tile size in the AI settings." : "Try a lower resolution (Settings -> Max Video Size)."; + string msg = usingDain ? "\n\nTry reducing the tile size in the AI settings." : "\n\nTry a lower resolution (Settings -> Max Video Size)."; InterpolateUtils.ShowMessage($"Vulkan ran out of memory!\n\n{line}{msg}", "Error"); } diff --git a/Code/UI/InterpolationProgress.cs b/Code/UI/InterpolationProgress.cs index 1538fe8..b9057ec 100644 --- a/Code/UI/InterpolationProgress.cs +++ b/Code/UI/InterpolationProgress.cs @@ -16,6 +16,7 @@ namespace Flowframes.UI { class InterpolationProgress { + public static int deletedFramesCount; public static int lastFrame; public static int targetFrames; public static string currentOutdir; @@ -34,6 +35,7 @@ namespace Flowframes.UI Logger.Log($"Starting GetProgressByFrameAmount() loop for outdir '{currentOutdir}', target is {target} frames", true); bool firstProgUpd = true; Program.mainForm.SetProgress(0); + deletedFramesCount = 0; lastFrame = 0; peakFpsOut = 0f; @@ -141,8 +143,10 @@ namespace Flowframes.UI { while (Program.busy && (i + 10) > interpolatedInputFramesCount) await Task.Delay(1000); if (!Program.busy) break; + if (i != 0 && i != inputFrames.Length - 1) IOUtils.OverwriteFileWithText(inputFrames[i]); + if (i % 10 == 0) await Task.Delay(10); } }