Fix plugin downloader for RIFE VS, add image sequence support

This commit is contained in:
n00mkrad
2022-06-01 15:46:34 +02:00
parent 0c0f725c87
commit bb0210abc7
6 changed files with 53 additions and 45 deletions

View File

@@ -261,7 +261,7 @@ namespace Flowframes.IO
if (key == Key.minOutVidLength) return WriteDefault(key, "5");
if (key == Key.h264Crf) return WriteDefault(key, "20");
if (key == Key.h265Crf) return WriteDefault(key, "24");
if (key == Key.av1Crf) return WriteDefault(key, "27");
if (key == Key.av1Crf) return WriteDefault(key, "28");
if (key == Key.vp9Crf) return WriteDefault(key, "28");
if (key == Key.proResProfile) return WriteDefault(key, "2");
if (key == Key.aviCodec) return WriteDefault(key, "ffv1");

View File

@@ -117,11 +117,11 @@ namespace Flowframes.IO
return IsFileValid(path);
}
public static void CopyDir(string sourceDirectoryName, string targetDirectoryName, bool move = false)
public static void CopyDir(string sourceDirectory, string targetDirectory, bool move = false)
{
Directory.CreateDirectory(targetDirectoryName);
DirectoryInfo source = new DirectoryInfo(sourceDirectoryName);
DirectoryInfo target = new DirectoryInfo(targetDirectoryName);
Directory.CreateDirectory(targetDirectory);
DirectoryInfo source = new DirectoryInfo(sourceDirectory);
DirectoryInfo target = new DirectoryInfo(targetDirectory);
CopyWork(source, target, move);
}

View File

@@ -47,7 +47,7 @@ namespace Flowframes
Program.mainForm.SetStatus("Starting...");
sw.Restart();
if (!AutoEncodeResume.resumeNextRun && !current.ai.Piped)
if (!AutoEncodeResume.resumeNextRun && !(current.ai.Piped && !current.inputIsFrames))
{
await GetFrames();
if (canceled) return;
@@ -179,15 +179,14 @@ namespace Flowframes
{
if (canceled) return;
if (!ai.Piped)
{
await Task.Run(async () => { await Dedupe.CreateDupesFile(current.framesFolder, currentInputFrameCount, current.framesExt); });
await Task.Run(async () => { await FrameRename.Rename(); });
if (!ai.Piped)
await Task.Run(async () => { await FrameOrder.CreateFrameOrderFile(current.framesFolder, Config.GetBool(Config.Key.enableLoop), current.interpFactor); });
}
Program.mainForm.SetStatus("Downloading models...");
//await ModelDownloader.DownloadModelFiles(ai, current.model.dir);
await ModelDownloader.DownloadModelFiles(ai, current.model.dir);
if (canceled) return;
currentlyUsingAutoEnc = Utils.CanUseAutoEnc(stepByStep, current);

View File

@@ -82,9 +82,13 @@ namespace Flowframes.Os
if (Interpolate.canceled) return;
Program.mainForm.SetProgress(100);
AiProcessSuspend.SetRunning(false);
int interpFramesFiles = IoUtils.GetAmountOfFiles(Interpolate.current.interpFolder, false, "*" + Interpolate.current.interpExt);
int interpFramesCount = interpFramesFiles + InterpolationProgress.deletedFramesCount;
if (!Interpolate.current.ai.Piped)
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())
@@ -324,7 +328,6 @@ namespace Flowframes.Os
Logger.Log($"Running RIFE (NCNN-VS){(uhd ? " (UHD Mode)" : "")}...", false);
await RunRifeNcnnVsProcess(framesPath, factor, outPath, mdl, uhd);
//await DeleteNcnnDupes(outPath, factor);
}
catch (Exception e)
{
@@ -350,10 +353,14 @@ namespace Flowframes.Os
float scn = Config.GetBool(Config.Key.scnDetect) ? Config.GetFloat(Config.Key.scnDetectValue) : 0f;
Size res = InterpolateUtils.GetOutputResolution(Interpolate.current.InputResolution, true, true);
string pkgDir = Path.Combine(Paths.GetPkgPath(), Implementations.rifeNcnnVs.PkgDir);
string vsModelDir = Path.Combine(pkgDir, "vapoursynth64", "plugins", "models", mdl);
IoUtils.CopyDir(Path.Combine(pkgDir, mdl), vsModelDir);
VapourSynthUtils.VsSettings vsSettings = new VapourSynthUtils.VsSettings()
{ InterpSettings = Interpolate.current, ModelDir = mdl, Factor = factor, Res = res, Uhd = uhd, SceneDetectSensitivity = scn, Loop = Config.GetBool(Config.Key.enableLoop), MatchDuration = Config.GetBool(Config.Key.fixOutputDuration) };
rifeNcnnVs.StartInfo.Arguments = $"{OsUtils.GetCmdArg()} cd /D {Path.Combine(Paths.GetPkgPath(), Implementations.rifeNcnnVs.PkgDir).Wrap()} & vspipe {VapourSynthUtils.CreateScript(vsSettings).Wrap()} -c y4m - | {ffmpegArgs}";
rifeNcnnVs.StartInfo.Arguments = $"{OsUtils.GetCmdArg()} cd /D {pkgDir.Wrap()} & vspipe {VapourSynthUtils.CreateScript(vsSettings).Wrap()} -c y4m - | {ffmpegArgs}";
Logger.Log("cmd.exe " + rifeNcnnVs.StartInfo.Arguments, true);
@@ -372,6 +379,10 @@ namespace Flowframes.Os
}
while (!rifeNcnnVs.HasExited) await Task.Delay(1);
await Task.Delay(100);
IoUtils.TryDeleteIfExists(vsModelDir);
}
public static async Task RunDainNcnn(string framesPath, string outPath, float factor, string mdl, int tilesize)
@@ -497,23 +508,6 @@ namespace Flowframes.Os
Stopwatch sw = new Stopwatch();
sw.Restart();
//if (line.Contains("iVBOR"))
//{
// try
// {
// string[] split = line.Split(':');
// //MemoryStream stream = new MemoryStream(Convert.FromBase64String(split[1]));
// //Image img = Image.FromStream(stream);
// Logger.Log($"Received image {split[0]} in {sw.ElapsedMilliseconds} ms", true);
// }
// catch (Exception e)
// {
// Logger.Log($"Failed to decode b64 string - {e}:");
// Logger.Log(line);
// }
// return;
//}
lastLogName = logFilename;
Logger.Log(line, true, false, logFilename);

View File

@@ -30,21 +30,22 @@ namespace Flowframes.Os
public static string CreateScript(VsSettings s)
{
string inputPath = s.InterpSettings.inPath;
bool resize = !s.InterpSettings.ScaledResolution.IsEmpty && s.InterpSettings.ScaledResolution != s.InterpSettings.InputResolution;
bool sc = s.SceneDetectSensitivity >= 0.01f;
int endDupeCount = s.Factor.RoundToInt() - 1;
List<string> l = new List<string>();
List<string> l = new List<string> { "import sys", "import vapoursynth as vs", "core = vs.core" }; // Imports
l.Add($"import sys");
l.Add($"import vapoursynth as vs");
l.Add($"core = vs.core");
if (Config.GetBool(Config.Key.vsUseLsmash, true))
l.Add($"clip = core.lsmas.LWLibavSource(r'{inputPath}', cachefile=r'{Path.Combine(s.InterpSettings.tempFolder, "lsmash.cache.lwi")}')");
if (s.InterpSettings.inputIsFrames)
{
string first = Path.GetFileNameWithoutExtension(IoUtils.GetFileInfosSorted(s.InterpSettings.framesFolder, false).FirstOrDefault().FullName);
l.Add($"clip = core.imwri.Read(r'{Path.Combine(s.InterpSettings.framesFolder, $"%0{first.Length}d.png")}', firstnum={first.GetInt()})"); // Load image sequence with imwri
l.Add($"clip = core.std.AssumeFPS(clip, fpsnum={s.InterpSettings.inFps.Numerator}, fpsden={s.InterpSettings.inFps.Denominator})"); // Set frame rate for img seq
}
else
l.Add($"clip = core.ffms2.Source(source=r'{inputPath}', cachefile=r'{Path.Combine(s.InterpSettings.tempFolder, "ffms2.cache.ffindex")}')");
{
l.Add($"clip = core.lsmas.LWLibavSource(r'{inputPath}', cachefile=r'{Path.Combine(s.InterpSettings.tempFolder, "lsmash.cache.lwi")}')"); // Load video with lsmash
}
l.Add($"targetFrameCountMatchDuration = round((clip.num_frames*{s.Factor.ToStringDot()}), 1)"); // Target frame count to match original duration (and for loops)
l.Add($"targetFrameCountTrue = targetFrameCountMatchDuration-{endDupeCount}"); // Target frame count without dupes at the end (only in-between frames added)
@@ -55,13 +56,12 @@ namespace Flowframes.Os
l.Add($"clip = clip + firstFrame"); // Add to end (for seamless loop interpolation)
}
l.Add($"clip = core.resize.Bicubic(clip=clip, format=vs.RGBS{(resize ? $", width={s.InterpSettings.ScaledResolution.Width}, height={s.InterpSettings.ScaledResolution.Height}" : "")})");
//l.Add($"clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, matrix_in_s=\"709\", range_s=\"limited\"{(resize ? $", width={s.InterpSettings.ScaledResolution.Width}, height={s.InterpSettings.ScaledResolution.Height}" : "")})");
l.AddRange(GetScaleLines(s));
if (sc)
l.Add($"clip = core.misc.SCDetect(clip=clip,threshold={s.SceneDetectSensitivity.ToStringDot()})"); // Scene detection
l.Add($"clip = core.rife.RIFE(clip, {GetModelNum(s.ModelDir)}, {s.Factor.ToStringDot()}, {s.GpuId}, {s.GpuThreads}, {s.Tta}, {s.Uhd}, {sc})"); // Interpolate
l.Add($"clip = core.rife.RIFE(clip, {9}, {s.Factor.ToStringDot()}, {s.GpuId}, {s.GpuThreads}, {s.Tta}, {s.Uhd}, {sc})"); // Interpolate
l.Add($"clip = vs.core.resize.Bicubic(clip, format=vs.YUV444P16, matrix_s=\"709\")"); // Convert RGB to YUV
if (s.Loop)
@@ -84,6 +84,22 @@ namespace Flowframes.Os
return vpyPath;
}
static List<string> GetScaleLines(VsSettings s)
{
bool resize = !s.InterpSettings.ScaledResolution.IsEmpty && s.InterpSettings.ScaledResolution != s.InterpSettings.InputResolution;
List<string> l = new List<string>();
l.Add($"");
l.Add($"if clip.format.color_family == vs.YUV:");
l.Add($"\tclip = core.resize.Bicubic(clip=clip, format=vs.RGBS, matrix_in_s=\"709\", range_s=\"limited\"{(resize ? $", width={s.InterpSettings.ScaledResolution.Width}, height={s.InterpSettings.ScaledResolution.Height}" : "")})");
l.Add($"");
l.Add($"if clip.format.color_family == vs.RGB:");
l.Add($"\tclip = core.resize.Bicubic(clip=clip, format=vs.RGBS{(resize ? $", width={s.InterpSettings.ScaledResolution.Width}, height={s.InterpSettings.ScaledResolution.Height}" : "")})");
l.Add($"");
return l;
}
private static int GetModelNum(string modelDir)
{
switch (modelDir)

View File

@@ -102,7 +102,6 @@ namespace Flowframes.Ui
if (!progressPaused && AiProcess.processTime.IsRunning)
{
string lastLogLine = Logger.GetSessionLogLastLines(logFile, 1).Where(x => x.Contains("frame=")).LastOrDefault();
int num = lastLogLine == null ? 0 : lastLogLine.Split("frame=")[1].Split("fps=")[0].GetInt();
if(num > 0)