CLI improvements, OneDrive path check

This commit is contained in:
N00MKRAD
2024-09-03 22:01:32 +02:00
parent a5c59d27d0
commit c31c76f423
8 changed files with 94 additions and 41 deletions

View File

@@ -21,14 +21,14 @@ namespace Flowframes
public static bool AutoRun = false; public static bool AutoRun = false;
public static float InterpFactor = -1f; public static float InterpFactor = -1f;
public static Implementations.Ai InterpAi = (Implementations.Ai)(-1); 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.Encoder Encoder = (Enums.Encoding.Encoder)(-1);
public static Enums.Encoding.PixelFormat PixFmt = (Enums.Encoding.PixelFormat)(-1); public static Enums.Encoding.PixelFormat PixFmt = (Enums.Encoding.PixelFormat)(-1);
public static string InterpModel = ""; public static string InterpModel = "";
public static string OutputDir = ""; public static string OutputDir = "";
public static int MaxHeight = -1; public static int MaxHeight = -1;
public static bool? Loop = false; public static bool? Loop = null;
public static bool? FixSceneChanges = false; public static bool? FixSceneChanges = null;
public static float FixSceneChangeVal = -1f; public static float FixSceneChangeVal = -1f;
public static float MaxOutFps = -1f; public static float MaxOutFps = -1f;
public static List<string> ValidFiles = new List<string>(); public static List<string> ValidFiles = new List<string>();
@@ -40,7 +40,7 @@ namespace Flowframes
{ {
string GetEnums<T>() => string.Join(", ", Enum.GetNames(typeof(T))); string GetEnums<T>() => string.Join(", ", Enum.GetNames(typeof(T)));
var opts = new OptionSet var optsSet = new OptionSet
{ {
{ {
"c|console", "Show console", "c|console", "Show console",
@@ -87,16 +87,16 @@ namespace Flowframes
v => PixFmt = ParseUtils.GetEnum<Enums.Encoding.PixelFormat>(v.Trim()) v => PixFmt = ParseUtils.GetEnum<Enums.Encoding.PixelFormat>(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() v => MaxHeight = v.GetInt()
}, },
{ {
"l|loop", $"Enable loop output mode", "l|loop=", $"Enable loop output mode",
v => Loop = v != null ? true : (bool?)null v => Loop = v.GetBoolCli()
}, },
{ {
"scn|fix_scene_changes", $"Do not interpolate scene cuts to avoid artifacts", "scn|fix_scene_changes=", $"Do not interpolate scene cuts to avoid artifacts",
v => FixSceneChanges = v != null ? true : (bool?)null v => FixSceneChanges = v.GetBoolCli()
}, },
{ {
"scnv|scene_change_sensitivity=", $"Scene change sensitivity, lower is more sensitive (e.g. 0.18)", "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 = "<OPTIONS> <FILE(S)>", AddHelpArg = true };
try try
{ {
if (!opts.TryParseOptions(Environment.GetCommandLineArgs())) if (!opts.TryParseOptions(Environment.GetCommandLineArgs()))
@@ -124,10 +126,12 @@ namespace Flowframes
if (!ShowConsole) if (!ShowConsole)
FreeConsole(); FreeConsole();
ValidFiles = ValidFiles.Where(f => File.Exists(f) && Path.GetExtension(f).Lower() != ".exe").Distinct().ToList();
Python.DisablePython = DisablePython; Python.DisablePython = DisablePython;
Config.NoWrite = DontSaveConfig; 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) catch (OptionException e)
{ {

View File

@@ -23,7 +23,7 @@ namespace Flowframes.Data
NameInternal = "RIFE_CUDA", NameInternal = "RIFE_CUDA",
NameLong = "Real-Time Intermediate Flow Estimation", NameLong = "Real-Time Intermediate Flow Estimation",
FactorSupport = AiInfo.InterpFactorSupport.AnyInteger, 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() public static AiInfo rifeNcnn = new AiInfo()
@@ -32,7 +32,7 @@ namespace Flowframes.Data
NameInternal = "RIFE_NCNN", NameInternal = "RIFE_NCNN",
NameLong = "Real-Time Intermediate Flow Estimation", NameLong = "Real-Time Intermediate Flow Estimation",
FactorSupport = AiInfo.InterpFactorSupport.AnyFloat, 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() public static AiInfo rifeNcnnVs = new AiInfo()
@@ -41,7 +41,7 @@ namespace Flowframes.Data
NameInternal = "RIFE_NCNN_VS", NameInternal = "RIFE_NCNN_VS",
NameLong = "Real-Time Intermediate Flow Estimation", NameLong = "Real-Time Intermediate Flow Estimation",
FactorSupport = AiInfo.InterpFactorSupport.AnyFloat, 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 Piped = true
}; };
@@ -60,7 +60,7 @@ namespace Flowframes.Data
NameInternal = "DAIN_NCNN", NameInternal = "DAIN_NCNN",
NameLong = "Depth-Aware Video Frame Interpolation", NameLong = "Depth-Aware Video Frame Interpolation",
FactorSupport = AiInfo.InterpFactorSupport.AnyFloat, 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() public static AiInfo xvfiCuda = new AiInfo()
@@ -69,7 +69,7 @@ namespace Flowframes.Data
NameInternal = "XVFI_CUDA", NameInternal = "XVFI_CUDA",
NameLong = "eXtreme Video Frame Interpolation", NameLong = "eXtreme Video Frame Interpolation",
FactorSupport = AiInfo.InterpFactorSupport.AnyInteger, 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() public static AiInfo ifrnetNcnn = new AiInfo()
@@ -90,7 +90,7 @@ namespace Flowframes.Data
{ Ai.FlavrCuda, flavrCuda }, { Ai.FlavrCuda, flavrCuda },
{ Ai.DainNcnn, dainNcnn }, { Ai.DainNcnn, dainNcnn },
{ Ai.XvfiCuda, xvfiCuda }, { Ai.XvfiCuda, xvfiCuda },
{ Ai.IfrnetNcnn, ifrnetNcnn } /* { Ai.IfrnetNcnn, ifrnetNcnn }, */
}; };
public static List<AiInfo> NetworksAll => AiLookup.Values.ToList(); public static List<AiInfo> NetworksAll => AiLookup.Values.ToList();

View File

@@ -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) public static float GetFloat(this TextBox textbox)
{ {
return GetFloat(textbox.Text); return GetFloat(textbox.Text);
@@ -142,7 +158,7 @@ namespace Flowframes
public static string Trunc(this string inStr, int maxChars, bool addEllipsis = true) public static string Trunc(this string inStr, int maxChars, bool addEllipsis = true)
{ {
string str = inStr.Length <= maxChars ? inStr : inStr.Substring(0, maxChars); string str = inStr.Length <= maxChars ? inStr : inStr.Substring(0, maxChars);
if(addEllipsis && inStr.Length > maxChars) if (addEllipsis && inStr.Length > maxChars)
str += "…"; str += "…";
return str; return str;
} }
@@ -189,7 +205,7 @@ namespace Flowframes
return newString.ToString(); 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); int place = str.LastIndexOf(stringToReplace);
@@ -199,12 +215,12 @@ namespace Flowframes
return str.Remove(place, stringToReplace.Length).Insert(place, replaceWith); 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); 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]; return str.Split('#')[0].SplitBy("//")[0];
} }
@@ -216,9 +232,9 @@ namespace Flowframes
return filename + suffix + ext; 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(",", "."); return f.ToString().Replace(",", ".");
else else
return f.ToString(format).Replace(",", "."); return f.ToString(format).Replace(",", ".");
@@ -385,12 +401,12 @@ namespace Flowframes
return s.ToUpperInvariant(); 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); return OutputUtils.GetEncoderInfoVideo(enc);
} }
public static bool IsEmpty (this string s) public static bool IsEmpty(this string s)
{ {
return string.IsNullOrWhiteSpace(s); return string.IsNullOrWhiteSpace(s);
} }

View File

@@ -173,77 +173,93 @@ namespace Flowframes.Forms.Main
void HandleArgs() void HandleArgs()
{ {
// Input & interpolation settings
if (Cli.ValidFiles.Any()) if (Cli.ValidFiles.Any())
{
Logger.Log($"[CLI] Loading file(s): {string.Join(", ", Cli.ValidFiles)}", true);
DragDropHandler(Cli.ValidFiles.ToArray()); DragDropHandler(Cli.ValidFiles.ToArray());
}
if (Cli.InterpAi != (Implementations.Ai)(-1)) if (Cli.InterpAi != (Implementations.Ai)(-1))
{ {
string name = Implementations.GetAi(Cli.InterpAi).NameInternal; string name = Implementations.GetAi(Cli.InterpAi).NameInternal;
aiCombox.SelectedIndex = Implementations.NetworksAvailable.IndexOf(Implementations.NetworksAvailable.Where(ai => ai.NameInternal == name).FirstOrDefault()); 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<string>().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) if (Cli.InterpFactor > 0)
{ {
interpFactorCombox.Text = Cli.InterpFactor.ToString(); interpFactorCombox.Text = Cli.InterpFactor.ToString();
ValidateFactor(); ValidateFactor();
Logger.Log($"[CLI] Using interpolation factor {interpFactorCombox.Text}", true);
} }
if(Cli.OutputFormat != (Enums.Output.Format)(-1)) // Output
{
SetFormat(Cli.OutputFormat);
}
if (Cli.InterpModel.IsNotEmpty())
{
aiModel.SelectedIndex = aiModel.Items.Cast<string>().Select((item, index) => new { item, index }).FirstOrDefault(x => x.item.Contains(Cli.InterpModel))?.index ?? -1;
}
if (Cli.OutputDir.IsNotEmpty()) if (Cli.OutputDir.IsNotEmpty())
{ {
outputTbox.Text = Cli.OutputDir; 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<string>().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)) if (Cli.Encoder != (Enums.Encoding.Encoder)(-1))
{ {
comboxOutputEncoder.SelectedIndex = comboxOutputEncoder.Items.Cast<string>().Select((item, index) => new { item, index }) comboxOutputEncoder.SelectedIndex = comboxOutputEncoder.Items.Cast<string>().Select((item, index) => new { item, index })
.FirstOrDefault(x => x.item == Strings.Encoder[Cli.Encoder.ToString()])?.index ?? -1; .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)) if (Cli.PixFmt != (Enums.Encoding.PixelFormat)(-1))
{ {
comboxOutputEncoder.SelectedIndex = comboxOutputEncoder.Items.Cast<string>().Select((item, index) => new { item, index }) comboxOutputColors.SelectedIndex = comboxOutputColors.Items.Cast<string>().Select((item, index) => new { item, index })
.FirstOrDefault(x => x.item == Strings.PixelFormat[Cli.PixFmt.ToString()])?.index ?? -1; .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) 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()); Config.Set(Config.Key.maxVidHeight, Cli.MaxHeight.ToString());
} }
if (Cli.Loop != null) 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()); Config.Set(Config.Key.enableLoop, ((bool)Cli.Loop).ToString());
} }
if (Cli.FixSceneChanges != null) 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) if (Cli.FixSceneChangeVal > 0f)
{ {
Logger.Log($"[CLI] Set scene change sensitivity value to {Cli.FixSceneChangeVal}", true);
Config.Set(Config.Key.scnDetectValue, Cli.FixSceneChangeVal.ToString()); Config.Set(Config.Key.scnDetectValue, Cli.FixSceneChangeVal.ToString());
} }
if (Cli.MaxOutFps >= 1f) if (Cli.MaxOutFps >= 1f)
{ {
Logger.Log($"[CLI] Set max output (encoding) FPS to {Cli.MaxOutFps}", true);
Config.Set(Config.Key.maxFps, Cli.MaxOutFps.ToString()); Config.Set(Config.Key.maxFps, Cli.MaxOutFps.ToString());
} }
} }

View File

@@ -127,6 +127,11 @@ namespace Flowframes.IO
return IsFileValid(path); 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) public static void CopyDir(string sourceDirectory, string targetDirectory, bool move = false)
{ {
Directory.CreateDirectory(targetDirectory); Directory.CreateDirectory(targetDirectory);

View File

@@ -290,6 +290,9 @@ namespace Flowframes
Program.mainForm.SetTab(Program.mainForm.interpOptsTab.Name); Program.mainForm.SetTab(Program.mainForm.interpOptsTab.Name);
Logger.LogIfLastLineDoesNotContainMsg("Canceled interpolation."); Logger.LogIfLastLineDoesNotContainMsg("Canceled interpolation.");
if(Cli.ShowConsole)
Application.Exit();
if (!string.IsNullOrWhiteSpace(reason) && !noMsgBox) if (!string.IsNullOrWhiteSpace(reason) && !noMsgBox)
UiUtils.ShowMessageBox($"Canceled:\n\n{reason}"); UiUtils.ShowMessageBox($"Canceled:\n\n{reason}");
} }

View File

@@ -106,6 +106,12 @@ namespace Flowframes.Main
bool passes = true; bool passes = true;
bool isFile = !IoUtils.IsPathDirectory(s.inPath); 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))) if ((passes && isFile && !IoUtils.IsFileValid(s.inPath)) || (!isFile && !IoUtils.IsDirValid(s.inPath)))
{ {
UiUtils.ShowMessageBox("Input path is not valid!"); UiUtils.ShowMessageBox("Input path is not valid!");
@@ -118,9 +124,9 @@ namespace Flowframes.Main
passes = false; 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; passes = false;
} }

View File

@@ -86,6 +86,9 @@ namespace Flowframes.Ui
{ {
Logger.Log($"MessageBox: {text} ({type}){(BatchProcessing.busy ? "[Batch Mode - Will not display messagebox]" : "")}", true); Logger.Log($"MessageBox: {text} ({type}){(BatchProcessing.busy ? "[Batch Mode - Will not display messagebox]" : "")}", true);
if(Cli.ShowConsole)
return DialogResult.OK;
if (BatchProcessing.busy) if (BatchProcessing.busy)
{ {
Logger.Log(text); Logger.Log(text);