From c31c76f42351f103e58061fea222288519d7dee9 Mon Sep 17 00:00:00 2001 From: N00MKRAD <61149547+n00mkrad@users.noreply.github.com> Date: Tue, 3 Sep 2024 22:01:32 +0200 Subject: [PATCH] CLI improvements, OneDrive path check --- CodeLegacy/Cli.cs | 26 ++++++++------ CodeLegacy/Data/Implementations.cs | 12 +++---- CodeLegacy/Extensions/ExtensionMethods.cs | 32 ++++++++++++----- CodeLegacy/Forms/Main/Form1.cs | 44 +++++++++++++++-------- CodeLegacy/IO/IoUtils.cs | 5 +++ CodeLegacy/Main/Interpolate.cs | 3 ++ CodeLegacy/Main/InterpolateUtils.cs | 10 ++++-- CodeLegacy/Ui/UiUtils.cs | 3 ++ 8 files changed, 94 insertions(+), 41 deletions(-) diff --git a/CodeLegacy/Cli.cs b/CodeLegacy/Cli.cs index c314aab..fbd91d1 100644 --- a/CodeLegacy/Cli.cs +++ b/CodeLegacy/Cli.cs @@ -21,14 +21,14 @@ namespace Flowframes public static bool AutoRun = false; public static float InterpFactor = -1f; public static Implementations.Ai InterpAi = (Implementations.Ai)(-1); - public static Enums.Output.Format OutputFormat = Enums.Output.Format.Mp4; + public static Enums.Output.Format OutputFormat = (Enums.Output.Format)(-1); public static Enums.Encoding.Encoder Encoder = (Enums.Encoding.Encoder)(-1); public static Enums.Encoding.PixelFormat PixFmt = (Enums.Encoding.PixelFormat)(-1); public static string InterpModel = ""; public static string OutputDir = ""; public static int MaxHeight = -1; - public static bool? Loop = false; - public static bool? FixSceneChanges = false; + public static bool? Loop = null; + public static bool? FixSceneChanges = null; public static float FixSceneChangeVal = -1f; public static float MaxOutFps = -1f; public static List ValidFiles = new List(); @@ -40,7 +40,7 @@ namespace Flowframes { string GetEnums() => string.Join(", ", Enum.GetNames(typeof(T))); - var opts = new OptionSet + var optsSet = new OptionSet { { "c|console", "Show console", @@ -87,16 +87,16 @@ namespace Flowframes v => PixFmt = ParseUtils.GetEnum(v.Trim()) }, { - "h|max_height=", $"Max video size (pixels height). Larger videos will be downscaled.", + "mh|max_height=", $"Max video size in height pixels. Larger videos will be downscaled. (Example: 720)", v => MaxHeight = v.GetInt() }, { - "l|loop", $"Enable loop output mode", - v => Loop = v != null ? true : (bool?)null + "l|loop=", $"Enable loop output mode", + v => Loop = v.GetBoolCli() }, { - "scn|fix_scene_changes", $"Do not interpolate scene cuts to avoid artifacts", - v => FixSceneChanges = v != null ? true : (bool?)null + "scn|fix_scene_changes=", $"Do not interpolate scene cuts to avoid artifacts", + v => FixSceneChanges = v.GetBoolCli() }, { "scnv|scene_change_sensitivity=", $"Scene change sensitivity, lower is more sensitive (e.g. 0.18)", @@ -116,6 +116,8 @@ namespace Flowframes }, }; + var opts = new ArgParseExtensions.Options() { OptionsSet = optsSet, BasicUsage = " ", AddHelpArg = true }; + try { if (!opts.TryParseOptions(Environment.GetCommandLineArgs())) @@ -124,10 +126,12 @@ namespace Flowframes if (!ShowConsole) FreeConsole(); - ValidFiles = ValidFiles.Where(f => File.Exists(f) && Path.GetExtension(f).Lower() != ".exe").Distinct().ToList(); - Python.DisablePython = DisablePython; Config.NoWrite = DontSaveConfig; + + ValidFiles = ValidFiles.Where(f => File.Exists(f) && Path.GetExtension(f).Lower() != ".exe").Distinct().ToList(); + AutoRun = AutoRun && ValidFiles.Any(); // Only AutoRun if valid files are provided + DontSaveConfig = DontSaveConfig || AutoRun; // Never save config in AutoRun mode } catch (OptionException e) { diff --git a/CodeLegacy/Data/Implementations.cs b/CodeLegacy/Data/Implementations.cs index 1e875e0..fc75fd5 100644 --- a/CodeLegacy/Data/Implementations.cs +++ b/CodeLegacy/Data/Implementations.cs @@ -23,7 +23,7 @@ namespace Flowframes.Data NameInternal = "RIFE_CUDA", NameLong = "Real-Time Intermediate Flow Estimation", FactorSupport = AiInfo.InterpFactorSupport.AnyInteger, - SupportedFactors = Enumerable.Range(2, 15).ToArray(), // Generates numbers from 2 to 16 + SupportedFactors = Enumerable.Range(2, 15).ToArray(), // 2 to 16 }; public static AiInfo rifeNcnn = new AiInfo() @@ -32,7 +32,7 @@ namespace Flowframes.Data NameInternal = "RIFE_NCNN", NameLong = "Real-Time Intermediate Flow Estimation", FactorSupport = AiInfo.InterpFactorSupport.AnyFloat, - SupportedFactors = Enumerable.Range(2, 15).ToArray(), // Generates numbers from 2 to 16 + SupportedFactors = Enumerable.Range(2, 15).ToArray(), // 2 to 16 }; public static AiInfo rifeNcnnVs = new AiInfo() @@ -41,7 +41,7 @@ namespace Flowframes.Data NameInternal = "RIFE_NCNN_VS", NameLong = "Real-Time Intermediate Flow Estimation", FactorSupport = AiInfo.InterpFactorSupport.AnyFloat, - SupportedFactors = Enumerable.Range(2, 15).ToArray(), // Generates numbers from 2 to 16 + SupportedFactors = Enumerable.Range(2, 15).ToArray(), // 2 to 16 Piped = true }; @@ -60,7 +60,7 @@ namespace Flowframes.Data NameInternal = "DAIN_NCNN", NameLong = "Depth-Aware Video Frame Interpolation", FactorSupport = AiInfo.InterpFactorSupport.AnyFloat, - SupportedFactors = Enumerable.Range(2, 7).ToArray(), // Generates numbers from 2 to 8 + SupportedFactors = Enumerable.Range(2, 7).ToArray(), // 2 to 8 }; public static AiInfo xvfiCuda = new AiInfo() @@ -69,7 +69,7 @@ namespace Flowframes.Data NameInternal = "XVFI_CUDA", NameLong = "eXtreme Video Frame Interpolation", FactorSupport = AiInfo.InterpFactorSupport.AnyInteger, - SupportedFactors = Enumerable.Range(2, 9).ToArray(), // Generates numbers from 2 to 10 + SupportedFactors = Enumerable.Range(2, 9).ToArray(), // 2 to 10 }; public static AiInfo ifrnetNcnn = new AiInfo() @@ -90,7 +90,7 @@ namespace Flowframes.Data { Ai.FlavrCuda, flavrCuda }, { Ai.DainNcnn, dainNcnn }, { Ai.XvfiCuda, xvfiCuda }, - { Ai.IfrnetNcnn, ifrnetNcnn } + /* { Ai.IfrnetNcnn, ifrnetNcnn }, */ }; public static List NetworksAll => AiLookup.Values.ToList(); diff --git a/CodeLegacy/Extensions/ExtensionMethods.cs b/CodeLegacy/Extensions/ExtensionMethods.cs index db743df..f0ce0d5 100644 --- a/CodeLegacy/Extensions/ExtensionMethods.cs +++ b/CodeLegacy/Extensions/ExtensionMethods.cs @@ -66,6 +66,22 @@ namespace Flowframes } } + public static bool? GetBoolCli(this string str) + { + if (str == null) + return null; + + str = str.Trim().Lower(); + + if (str == "true" || str == "1" || str == "yes") + return true; + + if (str == "false" || str == "0" || str == "no") + return false; + + return null; + } + public static float GetFloat(this TextBox textbox) { return GetFloat(textbox.Text); @@ -142,7 +158,7 @@ namespace Flowframes public static string Trunc(this string inStr, int maxChars, bool addEllipsis = true) { string str = inStr.Length <= maxChars ? inStr : inStr.Substring(0, maxChars); - if(addEllipsis && inStr.Length > maxChars) + if (addEllipsis && inStr.Length > maxChars) str += "…"; return str; } @@ -189,7 +205,7 @@ namespace Flowframes return newString.ToString(); } - public static string ReplaceLast (this string str, string stringToReplace, string replaceWith) + public static string ReplaceLast(this string str, string stringToReplace, string replaceWith) { int place = str.LastIndexOf(stringToReplace); @@ -199,12 +215,12 @@ namespace Flowframes return str.Remove(place, stringToReplace.Length).Insert(place, replaceWith); } - public static string[] SplitBy (this string str, string splitBy) + public static string[] SplitBy(this string str, string splitBy) { return str.Split(new string[] { splitBy }, StringSplitOptions.None); } - public static string RemoveComments (this string str) + public static string RemoveComments(this string str) { return str.Split('#')[0].SplitBy("//")[0]; } @@ -216,9 +232,9 @@ namespace Flowframes return filename + suffix + ext; } - public static string ToStringDot (this float f, string format = "") + public static string ToStringDot(this float f, string format = "") { - if(string.IsNullOrWhiteSpace(format)) + if (string.IsNullOrWhiteSpace(format)) return f.ToString().Replace(",", "."); else return f.ToString(format).Replace(",", "."); @@ -385,12 +401,12 @@ namespace Flowframes return s.ToUpperInvariant(); } - public static EncoderInfoVideo GetInfo (this Enums.Encoding.Encoder enc) + public static EncoderInfoVideo GetInfo(this Enums.Encoding.Encoder enc) { return OutputUtils.GetEncoderInfoVideo(enc); } - public static bool IsEmpty (this string s) + public static bool IsEmpty(this string s) { return string.IsNullOrWhiteSpace(s); } diff --git a/CodeLegacy/Forms/Main/Form1.cs b/CodeLegacy/Forms/Main/Form1.cs index 8ca6b08..76aff95 100644 --- a/CodeLegacy/Forms/Main/Form1.cs +++ b/CodeLegacy/Forms/Main/Form1.cs @@ -173,77 +173,93 @@ namespace Flowframes.Forms.Main void HandleArgs() { + // Input & interpolation settings if (Cli.ValidFiles.Any()) + { + Logger.Log($"[CLI] Loading file(s): {string.Join(", ", Cli.ValidFiles)}", true); DragDropHandler(Cli.ValidFiles.ToArray()); + } if (Cli.InterpAi != (Implementations.Ai)(-1)) { string name = Implementations.GetAi(Cli.InterpAi).NameInternal; aiCombox.SelectedIndex = Implementations.NetworksAvailable.IndexOf(Implementations.NetworksAvailable.Where(ai => ai.NameInternal == name).FirstOrDefault()); + Logger.Log($"[CLI] Using AI implementation '{aiCombox.Text}' ('{Cli.InterpAi}')", true); + + } + + if (Cli.InterpModel.IsNotEmpty()) + { + aiModel.SelectedIndex = aiModel.Items.Cast().Select((item, index) => new { item, index }).FirstOrDefault(x => x.item.Contains(Cli.InterpModel))?.index ?? -1; + Logger.Log($"[CLI] Using interpolation model '{aiModel.Text}'", true); } if (Cli.InterpFactor > 0) { interpFactorCombox.Text = Cli.InterpFactor.ToString(); ValidateFactor(); + Logger.Log($"[CLI] Using interpolation factor {interpFactorCombox.Text}", true); } - if(Cli.OutputFormat != (Enums.Output.Format)(-1)) - { - SetFormat(Cli.OutputFormat); - } - - if (Cli.InterpModel.IsNotEmpty()) - { - aiModel.SelectedIndex = aiModel.Items.Cast().Select((item, index) => new { item, index }).FirstOrDefault(x => x.item.Contains(Cli.InterpModel))?.index ?? -1; - } + // Output if (Cli.OutputDir.IsNotEmpty()) { outputTbox.Text = Cli.OutputDir; - Directory.CreateDirectory(Cli.OutputDir); + Directory.CreateDirectory(outputTbox.Text); + Logger.Log($"[CLI] Using output directory '{outputTbox.Text}'", true); } - if (Cli.InterpModel.IsNotEmpty()) + if (Cli.OutputFormat != (Enums.Output.Format)(-1)) { - aiModel.SelectedIndex = aiModel.Items.Cast().Select((item, index) => new { item, index }).FirstOrDefault(x => x.item.Contains(Cli.InterpModel))?.index ?? -1; + SetFormat(Cli.OutputFormat); + Logger.Log($"[CLI] Using output format '{comboxOutputFormat.Text}'", true); } if (Cli.Encoder != (Enums.Encoding.Encoder)(-1)) { comboxOutputEncoder.SelectedIndex = comboxOutputEncoder.Items.Cast().Select((item, index) => new { item, index }) .FirstOrDefault(x => x.item == Strings.Encoder[Cli.Encoder.ToString()])?.index ?? -1; + Logger.Log($"[CLI] Using video encoder {comboxOutputEncoder.Text} ('{Cli.Encoder}')", true); } if (Cli.PixFmt != (Enums.Encoding.PixelFormat)(-1)) { - comboxOutputEncoder.SelectedIndex = comboxOutputEncoder.Items.Cast().Select((item, index) => new { item, index }) + comboxOutputColors.SelectedIndex = comboxOutputColors.Items.Cast().Select((item, index) => new { item, index }) .FirstOrDefault(x => x.item == Strings.PixelFormat[Cli.PixFmt.ToString()])?.index ?? -1; + Logger.Log($"[CLI] Using color format {comboxOutputColors.Text} ('{Cli.PixFmt}')", true); } + // Video processing settings + if (Cli.MaxHeight >= 64 && Cli.MaxHeight <= 16384) { + Logger.Log($"[CLI] Set max video height to {Cli.MaxHeight} px", true); Config.Set(Config.Key.maxVidHeight, Cli.MaxHeight.ToString()); } if (Cli.Loop != null) { + Logger.Log($"[CLI] Set loop mode to {(Cli.Loop == true ? "Enabled" : "Disabled")}", true); Config.Set(Config.Key.enableLoop, ((bool)Cli.Loop).ToString()); } if (Cli.FixSceneChanges != null) { - Config.Set(Config.Key.scnDetect, ((bool)Cli.Loop).ToString()); + Logger.Log($"[CLI] Set scene change fix mode to {(Cli.FixSceneChanges == true ? "Enabled" : "Disabled")}", true); + Config.Set(Config.Key.scnDetect, ((bool)Cli.FixSceneChanges).ToString()); } if (Cli.FixSceneChangeVal > 0f) { + Logger.Log($"[CLI] Set scene change sensitivity value to {Cli.FixSceneChangeVal}", true); Config.Set(Config.Key.scnDetectValue, Cli.FixSceneChangeVal.ToString()); } if (Cli.MaxOutFps >= 1f) { + Logger.Log($"[CLI] Set max output (encoding) FPS to {Cli.MaxOutFps}", true); Config.Set(Config.Key.maxFps, Cli.MaxOutFps.ToString()); } } diff --git a/CodeLegacy/IO/IoUtils.cs b/CodeLegacy/IO/IoUtils.cs index 2613b11..056a903 100644 --- a/CodeLegacy/IO/IoUtils.cs +++ b/CodeLegacy/IO/IoUtils.cs @@ -127,6 +127,11 @@ namespace Flowframes.IO return IsFileValid(path); } + public static bool IsPathOneDrive(string path) + { + return path.Lower().Replace("\\", "/").MatchesWildcard("*:/users/*/onedrive*"); + } + public static void CopyDir(string sourceDirectory, string targetDirectory, bool move = false) { Directory.CreateDirectory(targetDirectory); diff --git a/CodeLegacy/Main/Interpolate.cs b/CodeLegacy/Main/Interpolate.cs index 1d87295..03e9e52 100644 --- a/CodeLegacy/Main/Interpolate.cs +++ b/CodeLegacy/Main/Interpolate.cs @@ -290,6 +290,9 @@ namespace Flowframes Program.mainForm.SetTab(Program.mainForm.interpOptsTab.Name); Logger.LogIfLastLineDoesNotContainMsg("Canceled interpolation."); + if(Cli.ShowConsole) + Application.Exit(); + if (!string.IsNullOrWhiteSpace(reason) && !noMsgBox) UiUtils.ShowMessageBox($"Canceled:\n\n{reason}"); } diff --git a/CodeLegacy/Main/InterpolateUtils.cs b/CodeLegacy/Main/InterpolateUtils.cs index ab8273d..4199c6d 100644 --- a/CodeLegacy/Main/InterpolateUtils.cs +++ b/CodeLegacy/Main/InterpolateUtils.cs @@ -106,6 +106,12 @@ namespace Flowframes.Main bool passes = true; bool isFile = !IoUtils.IsPathDirectory(s.inPath); + if (passes && IoUtils.IsPathOneDrive(s.inPath) || IoUtils.IsPathOneDrive(s.outPath)) + { + UiUtils.ShowMessageBox("OneDrive paths are not supported. Please use a local path instead."); + passes = false; + } + if ((passes && isFile && !IoUtils.IsFileValid(s.inPath)) || (!isFile && !IoUtils.IsDirValid(s.inPath))) { UiUtils.ShowMessageBox("Input path is not valid!"); @@ -118,9 +124,9 @@ namespace Flowframes.Main passes = false; } - if (passes && s.tempFolder.StartsWith(@"\\")) + if (passes && s.tempFolder.StartsWith(@"\\") || IoUtils.IsPathOneDrive(s.tempFolder)) { - UiUtils.ShowMessageBox("Flowframes does not support UNC/Network paths as a temp folder!\nPlease use a local path instead."); + UiUtils.ShowMessageBox("Flowframes does not support network paths as a temp folder!\nPlease use a local path instead."); passes = false; } diff --git a/CodeLegacy/Ui/UiUtils.cs b/CodeLegacy/Ui/UiUtils.cs index ba1b309..290f3a6 100644 --- a/CodeLegacy/Ui/UiUtils.cs +++ b/CodeLegacy/Ui/UiUtils.cs @@ -86,6 +86,9 @@ namespace Flowframes.Ui { Logger.Log($"MessageBox: {text} ({type}){(BatchProcessing.busy ? "[Batch Mode - Will not display messagebox]" : "")}", true); + if(Cli.ShowConsole) + return DialogResult.OK; + if (BatchProcessing.busy) { Logger.Log(text);