formatting eh

This commit is contained in:
n00mkrad
2023-01-08 02:28:15 +01:00
parent 206ddda873
commit 6a0df3d78a

View File

@@ -69,7 +69,7 @@ namespace Flowframes.Os
{ {
l.Add("indexFilePath = f'{inputPath}.cache.lwi'"); l.Add("indexFilePath = f'{inputPath}.cache.lwi'");
l.Add($"if os.path.isdir(r'{s.InterpSettings.tempFolder}'):"); l.Add($"if os.path.isdir(r'{s.InterpSettings.tempFolder}'):");
l.Add($"\tindexFilePath = r'{Path.Combine(s.InterpSettings.tempFolder, "cache.lwi")}'"); l.Add($" indexFilePath = r'{Path.Combine(s.InterpSettings.tempFolder, "cache.lwi")}'");
l.Add($"clip = core.lsmas.LWLibavSource(inputPath, cachefile=indexFilePath)"); // Load video with lsmash l.Add($"clip = core.lsmas.LWLibavSource(inputPath, cachefile=indexFilePath)"); // Load video with lsmash
} }
@@ -84,7 +84,7 @@ namespace Flowframes.Os
l.Add($"clip = clip + firstFrame"); // Add to end (for seamless loop interpolation) l.Add($"clip = clip + firstFrame"); // Add to end (for seamless loop interpolation)
} }
l.AddRange(GetScaleLines(s)); l.Add(GetScaleLines(s));
if (sc) if (sc)
l.Add($"clip = core.misc.SCDetect(clip=clip, threshold={s.SceneDetectSensitivity.ToStringDot()})"); // Scene detection l.Add($"clip = core.misc.SCDetect(clip=clip, threshold={s.SceneDetectSensitivity.ToStringDot()})"); // Scene detection
@@ -92,7 +92,7 @@ namespace Flowframes.Os
l.Add($"clip = core.rife.RIFE(clip, multiplier={s.Factor.ToStringDot()}, model_path={mdlPath}, gpu_id={s.GpuId}, gpu_thread={s.GpuThreads}, tta={s.Tta}, uhd={s.Uhd}, sc={sc})"); // Interpolate l.Add($"clip = core.rife.RIFE(clip, multiplier={s.Factor.ToStringDot()}, model_path={mdlPath}, gpu_id={s.GpuId}, gpu_thread={s.GpuThreads}, tta={s.Tta}, uhd={s.Uhd}, sc={sc})"); // Interpolate
if (s.Dedupe && !s.Realtime) if (s.Dedupe && !s.Realtime)
l.AddRange(GetRedupeLines(s)); l.Add(GetRedupeLines(s));
l.Add($"clip = vs.core.resize.Bicubic(clip, format=vs.YUV444P16, matrix_s=cMatrix)"); // Convert RGB to YUV l.Add($"clip = vs.core.resize.Bicubic(clip, format=vs.YUV444P16, matrix_s=cMatrix)"); // Convert RGB to YUV
@@ -113,13 +113,13 @@ namespace Flowframes.Os
l.AddRange(new List<string> { $"clip = clip.std.Loop(0)", "" }); // Can't loop piped video so we loop it before piping it to ffplay l.AddRange(new List<string> { $"clip = clip.std.Loop(0)", "" }); // Can't loop piped video so we loop it before piping it to ffplay
if(s.Realtime && s.Osd) if(s.Realtime && s.Osd)
l.AddRange(GetOsdLines(s)); l.Add(GetOsdLines());
l.Add($"clip.set_output()"); // Set output l.Add($"clip.set_output()"); // Set output
l.Add(""); l.Add("");
l.Add($"if os.path.isfile(r'{inputPath}.cache.lwi'):"); l.Add($"if os.path.isfile(r'{inputPath}.cache.lwi'):");
l.Add($"\tos.remove(r'{inputPath}.cache.lwi')"); l.Add($" os.remove(r'{inputPath}.cache.lwi')");
string pkgPath = Path.Combine(Paths.GetPkgPath(), Implementations.rifeNcnnVs.PkgDir); string pkgPath = Path.Combine(Paths.GetPkgPath(), Implementations.rifeNcnnVs.PkgDir);
string vpyPath = Path.Combine(pkgPath, "rife.vpy"); string vpyPath = Path.Combine(pkgPath, "rife.vpy");
@@ -129,107 +129,108 @@ namespace Flowframes.Os
return vpyPath; return vpyPath;
} }
static List<string> GetScaleLines(VsSettings s) static string GetScaleLines(VsSettings settings)
{ {
bool resize = !s.InterpSettings.ScaledResolution.IsEmpty && s.InterpSettings.ScaledResolution != s.InterpSettings.InputResolution; InterpSettings interp = settings.InterpSettings;
List<string> l = new List<string>(); bool resize = !interp.ScaledResolution.IsEmpty && interp.ScaledResolution != interp.InputResolution;
string s = "";
l.Add($""); s += $"\n";
l.Add($"cMatrix = '709'"); s += $"cMatrix = '709'\n";
l.Add($""); s += $"\n";
if (!s.InterpSettings.inputIsFrames) if (!interp.inputIsFrames)
{ {
l.Add("try:"); s += "try:\n";
l.Add("\tm = clip.get_frame(0).props._Matrix"); s += " m = clip.get_frame(0).props._Matrix\n";
l.Add("\tif m == 0: cMatrix = 'rgb'"); s += " if m == 0: cMatrix = 'rgb'\n";
l.Add("\telif m == 4: cMatrix = 'fcc'"); s += " elif m == 4: cMatrix = 'fcc'\n";
l.Add("\telif m == 5: cMatrix = '470bg'"); s += " elif m == 5: cMatrix = '470bg'\n";
l.Add("\telif m == 6: cMatrix = '170m'"); s += " elif m == 6: cMatrix = '170m'\n";
l.Add("\telif m == 7: cMatrix = '240m'"); s += " elif m == 7: cMatrix = '240m'\n";
l.Add("\telif m == 8: cMatrix = 'ycgco'"); s += " elif m == 8: cMatrix = 'ycgco'\n";
l.Add("\telif m == 9: cMatrix = '2020ncl'"); s += " elif m == 9: cMatrix = '2020ncl'\n";
l.Add("\telif m == 10: cMatrix = '2020cl'"); s += " elif m == 10: cMatrix = '2020cl'\n";
l.Add("\telif m == 12: cMatrix = 'chromancl'"); s += " elif m == 12: cMatrix = 'chromancl'\n";
l.Add("\telif m == 13: cMatrix = 'chromacl'"); s += " elif m == 13: cMatrix = 'chromacl'\n";
l.Add("\telif m == 14: cMatrix = 'ictcp'"); s += " elif m == 14: cMatrix = 'ictcp'\n";
l.Add($"except:"); s += $"except:\n";
l.Add($"\tcMatrix = '709'"); s += $" cMatrix = '709'\n";
l.Add($""); s += $"\n";
l.Add($"colRange = 'limited'"); s += $"colRange = 'limited'\n";
l.Add($""); s += $"\n";
l.Add($"try:"); s += $"try:\n";
l.Add($"\tif clip.get_frame(0).props._ColorRange == 0: colRange = 'full'"); s += $" if clip.get_frame(0).props._ColorRange == 0: colRange = 'full'\n";
l.Add($"except:"); s += $"except:\n";
l.Add($"\tcolRange = 'limited'"); s += $" colRange = 'limited'\n";
l.Add($""); s += $"\n";
} }
l.Add($"if clip.format.color_family == vs.YUV:"); s += $"if clip.format.color_family == vs.YUV:\n";
l.Add($"\tclip = core.resize.Bicubic(clip=clip, format=vs.RGBS, matrix_in_s=cMatrix, range_s=colRange{(resize ? $", width={s.InterpSettings.ScaledResolution.Width}, height={s.InterpSettings.ScaledResolution.Height}" : "")})"); s += $" clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, matrix_in_s=cMatrix, range_s=colRange{(resize ? $", width={interp.ScaledResolution.Width}, height={interp.ScaledResolution.Height}" : "")})\n";
l.Add($""); s += $"\n";
l.Add($"if clip.format.color_family == vs.RGB:"); s += $"if clip.format.color_family == vs.RGB:\n";
l.Add($"\tclip = core.resize.Bicubic(clip=clip, format=vs.RGBS{(resize ? $", width={s.InterpSettings.ScaledResolution.Width}, height={s.InterpSettings.ScaledResolution.Height}" : "")})"); s += $" clip = core.resize.Bicubic(clip=clip, format=vs.RGBS{(resize ? $", width={interp.ScaledResolution.Width}, height={interp.ScaledResolution.Height}" : "")})\n";
l.Add($""); s += $"\n";
return l; return s;
} }
static List<string> GetRedupeLines(VsSettings s) static string GetRedupeLines(VsSettings settings)
{ {
List<string> l = new List<string>(); string s = "";
l.Add(@"reorderedClip = clip[0]"); s += @"reorderedClip = clip[0]\n";
l.Add(""); s += "\n";
l.Add($"with open(r'{Path.Combine(s.InterpSettings.tempFolder, "frames.vs.json")}') as json_file:"); s += $"with open(r'{Path.Combine(inSet.tempFolder, "frames.vs.json")}') as json_file:\n";
l.Add("\tframeList = json.load(json_file)"); s += " frameList = json.load(json_file)\n";
l.Add("\t"); s += " \n";
l.Add("\tfor i in frameList:"); s += " for i in frameList:\n";
l.Add("\t\tif(i < clip.num_frames):"); s += " if(i < clip.num_frames):\n";
l.Add("\t\t\treorderedClip = reorderedClip + clip[i]"); s += " reorderedClip = reorderedClip + clip[i]\n";
l.Add(""); s += "\n";
l.Add("clip = reorderedClip.std.Trim(1, reorderedClip.num_frames - 1)"); s += "clip = reorderedClip.std.Trim(1, reorderedClip.num_frames - 1)\n";
l.Add(""); s += "\n";
return l; return s;
} }
static List<string> GetOsdLines(VsSettings s) static string GetOsdLines()
{ {
List<string> l = new List<string>(); string s = "";
l.Add($"framesProducedPrevious = 0"); s += $"framesProducedPrevious = 0 \n";
l.Add($"framesProducedCurrent = 0"); s += $"framesProducedCurrent = 0 \n";
l.Add($"lastFpsUpdateTime = time.time()"); s += $"lastFpsUpdateTime = time.time() \n";
l.Add($"startTime = time.time()"); s += $"startTime = time.time() \n";
l.Add($""); s += $" \n";
l.Add($"def onFrame(n, clip):"); s += $"def onFrame(n, clip): \n";
l.Add($"\tglobal startTime"); s += $" global startTime \n";
l.Add($"\tfpsAvgTime = 1"); s += $" fpsAvgTime = 1 \n";
l.Add($"\t"); s += $" \n";
l.Add($"\tif time.time() - startTime > fpsAvgTime:"); s += $" if time.time() - startTime > fpsAvgTime: \n";
l.Add($"\t\tglobal framesProducedPrevious"); s += $" global framesProducedPrevious \n";
l.Add($"\t\tglobal framesProducedCurrent"); s += $" global framesProducedCurrent \n";
l.Add($"\t\tglobal lastFpsUpdateTime"); s += $" global lastFpsUpdateTime \n";
l.Add($"\t\t"); s += $" \n";
l.Add($"\t\tfpsFloat = (clip.fps.numerator / clip.fps.denominator)"); s += $" fpsFloat = (clip.fps.numerator / clip.fps.denominator) \n";
l.Add($"\t\tvideoTimeFloat = (1 / fpsFloat) * n"); s += $" videoTimeFloat = (1 / fpsFloat) * n \n";
l.Add($"\t\tframesProducedCurrent+=1"); s += $" framesProducedCurrent+=1 \n";
l.Add($"\t\t"); s += $" \n";
l.Add($"\t\tif time.time() - lastFpsUpdateTime > fpsAvgTime:"); s += $" if time.time() - lastFpsUpdateTime > fpsAvgTime: \n";
l.Add($"\t\t\tlastFpsUpdateTime = time.time()"); s += $" lastFpsUpdateTime = time.time() \n";
l.Add($"\t\t\tframesProducedPrevious = framesProducedCurrent / fpsAvgTime"); s += $" framesProducedPrevious = framesProducedCurrent / fpsAvgTime \n";
l.Add($"\t\t\tframesProducedCurrent = 0"); s += $" framesProducedCurrent = 0 \n";
l.Add($"\t\t"); s += $" \n";
l.Add($"\t\tspeed = (framesProducedPrevious / fpsFloat) * 100"); s += $" speed = (framesProducedPrevious / fpsFloat) * 100 \n";
l.Add($"\t\tosdString = f\"Time: {{time.strftime(\'%H:%M:%S\', time.gmtime(videoTimeFloat))}} - FPS: {{framesProducedPrevious:.2f}}/{{fpsFloat:.2f}} ({{speed:.0f}}%){{\' [!]\' if speed < 95 else \'\'}}\""); s += $" osdString = f\"Time: {{time.strftime(\'%H:%M:%S\', time.gmtime(videoTimeFloat))}} - FPS: {{framesProducedPrevious:.2f}}/{{fpsFloat:.2f}} ({{speed:.0f}}%){{\' [!]\' if speed < 95 else \'\'}}\" \n";
l.Add($"\t\tclip = core.text.Text(clip, text=osdString, alignment=7, scale=1)"); s += $" clip = core.text.Text(clip, text=osdString, alignment=7, scale=1) \n";
l.Add($"\treturn clip"); s += $" return clip \n";
l.Add($""); s += $" \n";
l.Add($"clip = core.std.FrameEval(clip, functools.partial(onFrame, clip=clip))"); s += $"clip = core.std.FrameEval(clip, functools.partial(onFrame, clip=clip)) \n";
l.Add($""); s += $" \n";
return l; return s;
} }
public static int GetSeekSeconds(long videoLengthSeconds) public static int GetSeekSeconds(long videoLengthSeconds)