1
mirror of https://github.com/n00mkrad/flowframes synced 2024-10-31 17:06:40 +01:00

Updated RIFE-NCNN, added UHD mode for NCNN, fixed autoenc flaw

This commit is contained in:
N00MKRAD 2021-01-05 17:23:37 +01:00
parent 98f8448a75
commit 49d74f31ce
5 changed files with 57 additions and 12 deletions

View File

@ -15,7 +15,7 @@ namespace Flowframes.Main
static string interpFramesFolder;
static string videoChunksFolder;
public static int chunkSize = 125; // Encode every n frames
public static int safetyBufferFrames = 50; // Ignore latest n frames to avoid using images that haven't been fully encoded yet
public static int safetyBufferFrames = 90; // Ignore latest n frames to avoid using images that haven't been fully encoded yet
public static string[] interpFramesLines;
public static List<int> encodedFrameLines = new List<int>();
public static List<int> unencodedFrameLines = new List<int>();
@ -24,9 +24,15 @@ namespace Flowframes.Main
public static bool paused;
public static void UpdateSafetyBufferSize ()
{
safetyBufferFrames = Interpolate.current.ai.aiName.ToUpper().Contains("NCNN") ? 60 : 30; // Use bigger safety buffer for NCNN
}
public static async Task MainLoop(string interpFramesPath)
{
UpdateSafetyBufferSize();
interpFramesFolder = interpFramesPath;
videoChunksFolder = Path.Combine(interpFramesPath.GetParentDir(), Paths.chunksDir);
@ -34,7 +40,6 @@ namespace Flowframes.Main
unencodedFrameLines.Clear();
chunkSize = GetChunkSize(IOUtils.GetAmountOfFiles(Interpolate.current.framesFolder, false, "*.png") * Interpolate.current.interpFactor);
safetyBufferFrames = Interpolate.current.ai.aiName.ToUpper().Contains("NCNN") ? 60 : 30; // Use bigger safety buffer for NCNN
Logger.Log($"Starting AutoEncode MainLoop - Chunk Size: {chunkSize} Frames - Safety Buffer: {safetyBufferFrames} Frames", true);
int videoIndex = 1;

View File

@ -137,11 +137,7 @@ namespace Flowframes
public static async Task RunAi(string outpath, int targetFrames, int tilesize, AI ai, bool stepByStep = false)
{
bool vidMode = current.outMode.ToString().ToLower().Contains("vid");
if ((stepByStep && Config.GetBool("sbsAllowAutoEnc")) || (!stepByStep && Config.GetInt("autoEncMode") > 0))
currentlyUsingAutoEnc = vidMode && IOUtils.GetAmountOfFiles(current.framesFolder, false) * current.interpFactor >= (AutoEncode.chunkSize + AutoEncode.safetyBufferFrames) * 0.9f;
else
currentlyUsingAutoEnc = false;
currentlyUsingAutoEnc = Utils.UseAutoEnc(stepByStep, current);
IOUtils.CreateDir(outpath);

View File

@ -330,6 +330,43 @@ namespace Flowframes.Main
return (n - a > b - n) ? b : a; // Return of closest of two
}
public static bool UseAutoEnc (bool stepByStep, InterpSettings current)
{
AutoEncode.UpdateSafetyBufferSize();
if (!current.outMode.ToString().ToLower().Contains("vid"))
{
Logger.Log($"Not Using AutoEnc: Out Mode is not video ({current.outMode.ToString()})", true);
return false;
}
if(stepByStep && !Config.GetBool("sbsAllowAutoEnc"))
{
Logger.Log($"Not Using AutoEnc: Using step-by-step mode, but 'sbsAllowAutoEnc' is false.", true);
return false;
}
if (!stepByStep && Config.GetInt("autoEncMode") == 0)
{
Logger.Log($"Not Using AutoEnc: 'autoEncMode' is 0.", true);
return false;
}
int inFrames = IOUtils.GetAmountOfFiles(current.framesFolder, false);
if (inFrames * current.interpFactor < (AutoEncode.chunkSize + AutoEncode.safetyBufferFrames) * 1.2f)
{
Logger.Log($"Not Using AutoEnc: Input frames ({inFrames}) * factor ({current.interpFactor}) is smaller (chunkSize ({AutoEncode.chunkSize}) + safetyBufferFrames ({AutoEncode.safetyBufferFrames}) * 1.2f", true);
return false;
}
return true;
}
public static bool UseUHD ()
{
return GetOutputResolution(i.current.inPath, false).Height >= Config.GetInt("uhdThresh");
}
public static void FixConsecutiveSceneFrames (string sceneFramesPath, string sourceFramesPath)
{
if (!Directory.Exists(sceneFramesPath) || IOUtils.GetAmountOfFiles(sceneFramesPath, false) < 1)

View File

@ -151,8 +151,7 @@ namespace Flowframes
{
string rifeDir = Path.Combine(Paths.GetPkgPath(), Path.GetFileNameWithoutExtension(Packages.rifeCuda.fileName));
string script = "inference_video.py";
bool uhd = InterpolateUtils.GetOutputResolution(Interpolate.current.inPath, false).Height >= Config.GetInt("uhdThresh");
string uhdStr = uhd ? "--UHD" : "";
string uhdStr = InterpolateUtils.UseUHD() ? "--UHD" : "";
string args = $" --img {framesPath.Wrap()} --exp {(int)Math.Log(interpFactor, 2)} {uhdStr} --imgformat {InterpolateUtils.GetOutExt()} --output {Paths.interpDir}";
if (!File.Exists(Path.Combine(rifeDir, script)))
@ -165,7 +164,7 @@ namespace Flowframes
AiStarted(rifePy, 3500, Interpolate.current.interpFactor);
rifePy.StartInfo.Arguments = $"{OSUtils.GetCmdArg()} cd /D {PkgUtils.GetPkgFolder(Packages.rifeCuda).Wrap()} & " +
$"set CUDA_VISIBLE_DEVICES={Config.Get("torchGpus")} & {Python.GetPyCmd()} {script} {args}";
Logger.Log($"Running RIFE {(uhd ? "(UHD Mode)" : "")} ({script})...".TrimWhitespaces(), false);
Logger.Log($"Running RIFE {(InterpolateUtils.UseUHD() ? "(UHD Mode)" : "")} ({script})...".TrimWhitespaces(), false);
Logger.Log("cmd.exe " + rifePy.StartInfo.Arguments, true);
if (!OSUtils.ShowHiddenCmd())
{
@ -185,7 +184,7 @@ namespace Flowframes
public static async Task RunRifeNcnnMulti(string framesPath, string outPath, int tilesize, int times)
{
processTimeMulti.Restart();
Logger.Log("Running RIFE...", false);
Logger.Log($"Running RIFE{(InterpolateUtils.UseUHD() ? " (UHD Mode)" : "")} ...", false);
bool useAutoEnc = Interpolate.currentlyUsingAutoEnc;
if(times > 2)
@ -233,20 +232,28 @@ namespace Flowframes
{
Process rifeNcnn = OSUtils.NewProcess(!OSUtils.ShowHiddenCmd());
AiStarted(rifeNcnn, 1500, 2, inPath);
string uhdStr = InterpolateUtils.UseUHD() ? "-u" : "";
rifeNcnn.StartInfo.Arguments = $"{OSUtils.GetCmdArg()} cd /D {PkgUtils.GetPkgFolder(Packages.rifeNcnn).Wrap()} & rife-ncnn-vulkan.exe " +
$" -v -i {inPath.Wrap()} -o {outPath.Wrap()} -m rife1.7 -g {Config.Get("ncnnGpus")} -f {InterpolateUtils.GetOutExt()} -j {GetNcnnThreads()}";
$" -v -i {inPath.Wrap()} -o {outPath.Wrap()} -m rife1.7 {uhdStr} -g {Config.Get("ncnnGpus")} -f {InterpolateUtils.GetOutExt()} -j {GetNcnnThreads()}";
Logger.Log("cmd.exe " + rifeNcnn.StartInfo.Arguments, true);
if (!OSUtils.ShowHiddenCmd())
{
rifeNcnn.OutputDataReceived += (sender, outLine) => { LogOutput("[O] " + outLine.Data, "rife-ncnn-log"); };
rifeNcnn.ErrorDataReceived += (sender, outLine) => { LogOutput("[E] " + outLine.Data, "rife-ncnn-log"); };
}
rifeNcnn.Start();
if (!OSUtils.ShowHiddenCmd())
{
rifeNcnn.BeginOutputReadLine();
rifeNcnn.BeginErrorReadLine();
}
while (!rifeNcnn.HasExited) await Task.Delay(1);
}

Binary file not shown.