From 2c872629fbeb08c3d605131edebefd94805cecbb Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Wed, 27 Jan 2021 14:29:49 +0100 Subject: [PATCH] Added alpha support to RIFE-NCNN --- Code/OS/AiProcess.cs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/Code/OS/AiProcess.cs b/Code/OS/AiProcess.cs index 6f19a6a..6e74987 100644 --- a/Code/OS/AiProcess.cs +++ b/Code/OS/AiProcess.cs @@ -148,14 +148,29 @@ namespace Flowframes public static async Task RunRifeNcnn (string framesPath, string outPath, int factor, string mdl) { - int times = (int)Math.Log(factor, 2); processTimeMulti.Restart(); Logger.Log($"Running RIFE{(await InterpolateUtils.UseUHD() ? " (UHD Mode)" : "")}...", false); - if(times > 1) + await RunRifeNcnnMulti(framesPath, outPath, factor, mdl); + + if (!Interpolate.canceled && Interpolate.current.alpha) + { + InterpolateUtils.progressPaused = true; + Logger.Log("Interpolating alpha channel..."); + await RunRifeNcnnMulti(framesPath + Paths.alphaSuffix, outPath + Paths.alphaSuffix, factor, mdl); + } + + await AiFinished("RIFE"); + } + + static async Task RunRifeNcnnMulti(string framesPath, string outPath, int factor, string mdl) + { + int times = (int)Math.Log(factor, 2); + + if (times > 1) AutoEncode.paused = true; // Disable autoenc until the last iteration - for(int iteration = 1; iteration <= times; iteration++) + for (int iteration = 1; iteration <= times; iteration++) { if (Interpolate.canceled) return; @@ -167,7 +182,6 @@ namespace Flowframes Logger.Log($"Re-Running RIFE for {Math.Pow(2, iteration)}x interpolation...", false); string lastInterpPath = outPath + $"-run{iteration - 1}"; Directory.Move(outPath, lastInterpPath); // Rename last interp folder - Directory.CreateDirectory(outPath); await RunRifeNcnnProcess(lastInterpPath, outPath, mdl); IOUtils.TryDeleteIfExists(lastInterpPath); } @@ -176,12 +190,11 @@ namespace Flowframes await RunRifeNcnnProcess(framesPath, outPath, mdl); } } - - await AiFinished("RIFE"); } static async Task RunRifeNcnnProcess(string inPath, string outPath, string mdl) { + Directory.CreateDirectory(outPath); Process rifeNcnn = OSUtils.NewProcess(!OSUtils.ShowHiddenCmd()); AiStarted(rifeNcnn, 1500, inPath); SetProgressCheck(outPath, 2);