diff --git a/Code/Data/Padding.cs b/Code/Data/Padding.cs index ee4d937..b461217 100644 --- a/Code/Data/Padding.cs +++ b/Code/Data/Padding.cs @@ -9,6 +9,7 @@ namespace Flowframes.Data class Padding { public const int inputFrames = 9; + public const int inputFramesRenamed = 8; public const int interpFrames = 8; } } diff --git a/Code/Forms/SettingsForm.Designer.cs b/Code/Forms/SettingsForm.Designer.cs index 6354208..3508a1f 100644 --- a/Code/Forms/SettingsForm.Designer.cs +++ b/Code/Forms/SettingsForm.Designer.cs @@ -161,7 +161,6 @@ this.cmdDebugMode = new System.Windows.Forms.ComboBox(); this.titleLabel = new System.Windows.Forms.Label(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); - this.label42 = new System.Windows.Forms.Label(); this.settingsTabList.SuspendLayout(); this.generalTab.SuspendLayout(); this.tabListPage2.SuspendLayout(); @@ -460,7 +459,6 @@ // tabListPage2 // this.tabListPage2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48))))); - this.tabListPage2.Controls.Add(this.label42); this.tabListPage2.Controls.Add(this.label4); this.tabListPage2.Controls.Add(this.enableAlpha); this.tabListPage2.Controls.Add(this.label25); @@ -1582,9 +1580,9 @@ this.label8.Location = new System.Drawing.Point(10, 40); this.label8.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7); this.label8.Name = "label8"; - this.label8.Size = new System.Drawing.Size(165, 13); + this.label8.Size = new System.Drawing.Size(192, 13); this.label8.TabIndex = 30; - this.label8.Text = "Minimum Video Length (Seconds)"; + this.label8.Text = "Minimum Loop Video Length (Seconds)"; // // debugTab // @@ -1844,18 +1842,6 @@ this.titleLabel.Size = new System.Drawing.Size(119, 40); this.titleLabel.TabIndex = 1; this.titleLabel.Text = "Settings"; - // - // label42 - // - this.label42.AutoSize = true; - this.label42.ForeColor = System.Drawing.Color.Silver; - this.label42.Location = new System.Drawing.Point(277, 70); - this.label42.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7); - this.label42.Name = "label42"; - this.label42.Size = new System.Drawing.Size(346, 13); - this.label42.TabIndex = 79; - this.label42.Text = "Coming Soon " + - " "; // // SettingsForm // @@ -2028,6 +2014,5 @@ private System.Windows.Forms.ComboBox dainNcnnTilesize; private System.Windows.Forms.Label label27; private System.Windows.Forms.Label label26; - private System.Windows.Forms.Label label42; } } \ No newline at end of file diff --git a/Code/IO/Config.cs b/Code/IO/Config.cs index c8509fc..f351e3f 100644 --- a/Code/IO/Config.cs +++ b/Code/IO/Config.cs @@ -133,14 +133,15 @@ namespace Flowframes.IO if (key == "scnDetectValue") return WriteDefault(key, "0.2"); if (key == "autoEncMode") return WriteDefault(key, "2"); // Video Export - if (key == "h264Crf") return WriteDefault(key, "20"); - if (key == "h265Crf") return WriteDefault(key, "24"); - if (key == "vp9Crf") return WriteDefault(key, "32"); - if (key == "proResProfile") return WriteDefault(key, "2"); - if (key == "aviCodec") return WriteDefault(key, "ffv1"); - if (key == "aviColors") return WriteDefault(key, "yuv420p"); - if (key == "gifColors") return WriteDefault(key, "128 (High)"); - if (key == "minVidLength") return WriteDefault(key, "2"); + if (key == "minOutVidLength") return WriteDefault(key, "5"); + if (key == "h264Crf") return WriteDefault(key, "20"); + if (key == "h265Crf") return WriteDefault(key, "24"); + if (key == "vp9Crf") return WriteDefault(key, "32"); + if (key == "proResProfile") return WriteDefault(key, "2"); + if (key == "aviCodec") return WriteDefault(key, "ffv1"); + if (key == "aviColors") return WriteDefault(key, "yuv420p"); + if (key == "gifColors") return WriteDefault(key, "128 (High)"); + if (key == "minVidLength") return WriteDefault(key, "2"); // AI if (key == "uhdThresh") return WriteDefault(key, "1440"); if (key == "ncnnThreads") return WriteDefault(key, "1"); diff --git a/Code/Main/CreateVideo.cs b/Code/Main/CreateVideo.cs index 6640689..74b60cf 100644 --- a/Code/Main/CreateVideo.cs +++ b/Code/Main/CreateVideo.cs @@ -110,10 +110,7 @@ namespace Flowframes.Main { await FFmpegCommands.FramesToVideoConcat(vfrFile, outPath, mode, fps, resampleFps); await MergeAudio(i.current.inPath, outPath); - - int looptimes = GetLoopTimes(); - if (looptimes > 0) - await Loop(currentOutFile, looptimes); + await Loop(currentOutFile, GetLoopTimes()); } } @@ -154,10 +151,7 @@ namespace Flowframes.Main { await FFmpegCommands.ConcatVideos(vfrFile, outPath, -1); await MergeAudio(i.current.inPath, outPath); - - int looptimes = GetLoopTimes(); - if (looptimes > 0) - await Loop(outPath, looptimes); + await Loop(outPath, GetLoopTimes()); } public static async Task EncodeChunk(string outPath, i.OutMode mode, int firstFrameNum, int framesAmount) @@ -185,6 +179,7 @@ namespace Flowframes.Main static async Task Loop(string outPath, int looptimes) { + if (looptimes < 1 || !Config.GetBool("enableLoop")) return; Logger.Log($"Looping {looptimes} {(looptimes == 1 ? "time" : "times")} to reach target length of {Config.GetInt("minOutVidLength")}s..."); await FFmpegCommands.LoopVideo(outPath, looptimes, Config.GetInt("loopMode") == 0); } diff --git a/Code/Main/Interpolate.cs b/Code/Main/Interpolate.cs index 6a265db..ca89e45 100644 --- a/Code/Main/Interpolate.cs +++ b/Code/Main/Interpolate.cs @@ -34,6 +34,7 @@ namespace Flowframes public static async Task Start() { + if (Program.busy) return; canceled = false; if (!Utils.InputIsValid(current.inPath, current.outPath, current.outFps, current.interpFactor, current.outMode)) return; // General input checks if (!Utils.CheckAiAvailable(current.ai)) return; // Check if selected AI pkg is installed @@ -54,7 +55,7 @@ namespace Flowframes if(!currentlyUsingAutoEnc) await CreateVideo.Export(current.interpFolder, current.outFilename, current.outMode); IOUtils.ReverseRenaming(AiProcess.filenameMap, true); // Get timestamps back - Cleanup(current.interpFolder); + await Cleanup(); Program.mainForm.SetWorking(false); Logger.Log("Total processing time: " + FormatUtils.Time(sw.Elapsed)); sw.Stop(); @@ -143,7 +144,17 @@ namespace Flowframes if (canceled) return; - AiProcess.filenameMap = IOUtils.RenameCounterDirReversible(current.framesFolder, "png", 1, 8); + try + { + AiProcess.filenameMap = IOUtils.RenameCounterDirReversible(current.framesFolder, "png", 1, Padding.inputFramesRenamed); + } + catch (Exception e) + { + Logger.Log($"Error renaming frame files: {e.Message}"); + Cancel("Error renaming frame files. Check the log for details."); + } + + if (canceled) return; } public static async Task RunAi(string outpath, AI ai, bool stepByStep = false) @@ -197,19 +208,23 @@ namespace Flowframes Utils.ShowMessage($"Canceled:\n\n{reason}"); } - public static void Cleanup(string interpFramesDir, bool ignoreKeepSetting = false) + public static async Task Cleanup(bool ignoreKeepSetting = false, int retriesLeft = 3, bool isRetry = false) { - if (!ignoreKeepSetting && Config.GetBool("keepTempFolder")) return; - Logger.Log("Deleting temporary files..."); + if ((!ignoreKeepSetting && Config.GetBool("keepTempFolder")) || !Program.busy) return; + if (!isRetry) + Logger.Log("Deleting temporary files..."); try { - if (Config.GetBool("keepFrames")) - IOUtils.Copy(interpFramesDir, Path.Combine(current.tempFolder.GetParentDir(), Path.GetFileName(current.tempFolder).Replace("-temp", "-interpframes"))); Directory.Delete(current.tempFolder, true); } catch (Exception e) { Logger.Log("Cleanup Error: " + e.Message, true); + if(retriesLeft > 0) + { + await Task.Delay(1000); + await Cleanup(ignoreKeepSetting, retriesLeft - 1, true); + } } } } diff --git a/Code/Main/InterpolateSteps.cs b/Code/Main/InterpolateSteps.cs index 4d0012a..c4b76c8 100644 --- a/Code/Main/InterpolateSteps.cs +++ b/Code/Main/InterpolateSteps.cs @@ -17,12 +17,6 @@ namespace Flowframes.Main { public enum Step { ExtractScnChanges, ExtractFrames, Interpolate, CreateVid, Reset } - //public static string current.inPath; - //public static string currentOutPath; - //public static string current.interpFolder; - //public static AI currentAi; - //public static OutMode currentOutMode; - public static async Task Run(string step) { Logger.Log($"[SBS] Running step '{step}'", true); @@ -42,7 +36,7 @@ namespace Flowframes.Main if (step.Contains("Extract Frames")) { - await GetFrames(); + await ExtractFramesStep(); } if (step.Contains("Run Interpolation")) @@ -71,7 +65,7 @@ namespace Flowframes.Main await Task.Delay(10); } - public static async Task ExtractVideoFrames() + public static async Task ExtractFramesStep() { if (!IOUtils.TryDeleteIfExists(current.framesFolder)) { @@ -82,7 +76,7 @@ namespace Flowframes.Main currentInputFrameCount = await InterpolateUtils.GetInputFrameCountAsync(current.inPath); AiProcess.filenameMap.Clear(); - await ExtractFrames(current.inPath, current.framesFolder, false, true); + await GetFrames(); } public static async Task DoInterpolate() @@ -136,7 +130,7 @@ namespace Flowframes.Main public static async Task Reset() { - Cleanup(current.interpFolder, true); + await Cleanup(true); } } } diff --git a/Code/OS/AiProcess.cs b/Code/OS/AiProcess.cs index ce5b173..5a3c2e6 100644 --- a/Code/OS/AiProcess.cs +++ b/Code/OS/AiProcess.cs @@ -73,7 +73,7 @@ namespace Flowframes } if (timeSinceFfmpegRan.ElapsedMilliseconds > 3000) break; - // Logger.Log($"AiProcess loop - Program.busy = {Program.busy}"); + await Task.Delay(500); } } @@ -81,7 +81,7 @@ namespace Flowframes public static async Task RunRifeCuda(string framesPath, int interpFactor, string mdl) { string rifeDir = Path.Combine(Paths.GetPkgPath(), Path.GetFileNameWithoutExtension(Packages.rifeCuda.fileName)); - string script = "inference_video.py"; + string script = "rife.py"; if (!File.Exists(Path.Combine(rifeDir, script))) { @@ -110,9 +110,13 @@ namespace Flowframes public static async Task RunRifeCudaProcess (string inPath, string outDir, string script, int interpFactor, string mdl) { + bool parallel = false; string uhdStr = await InterpolateUtils.UseUHD() ? "--UHD" : ""; - string args = $" --input {inPath.Wrap()} --model {mdl} --exp {(int)Math.Log(interpFactor, 2)} {uhdStr} --imgformat {InterpolateUtils.GetOutExt()} --output {outDir}"; - + string outPath = Path.Combine(inPath.GetParentDir(), outDir); + string args = $" --input {inPath.Wrap()} --output {outDir} --model {mdl} --exp {(int)Math.Log(interpFactor, 2)} "; + if (parallel) args = $" --input {inPath.Wrap()} --output {outPath} --model {mdl} --factor {interpFactor}"; + if (parallel) script = "rife-parallel.py"; + Process rifePy = OSUtils.NewProcess(!OSUtils.ShowHiddenCmd()); AiStarted(rifePy, 3500); SetProgressCheck(Path.Combine(Interpolate.current.tempFolder, outDir), interpFactor);