Skip to content

Commit

Permalink
CLI improvements, OneDrive path check
Browse files Browse the repository at this point in the history
  • Loading branch information
n00mkrad committed Sep 3, 2024
1 parent a5c59d2 commit c31c76f
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 41 deletions.
26 changes: 15 additions & 11 deletions CodeLegacy/Cli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public class Cli
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<string> ValidFiles = new List<string>();
Expand All @@ -40,7 +40,7 @@ public static void HandleCli()
{
string GetEnums<T>() => string.Join(", ", Enum.GetNames(typeof(T)));

var opts = new OptionSet
var optsSet = new OptionSet
{
{
"c|console", "Show console",
Expand Down Expand Up @@ -87,16 +87,16 @@ public static void HandleCli()
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()
},
{
"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)",
Expand All @@ -116,6 +116,8 @@ public static void HandleCli()
},
};

var opts = new ArgParseExtensions.Options() { OptionsSet = optsSet, BasicUsage = "<OPTIONS> <FILE(S)>", AddHelpArg = true };

try
{
if (!opts.TryParseOptions(Environment.GetCommandLineArgs()))
Expand All @@ -124,10 +126,12 @@ public static void HandleCli()
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)
{
Expand Down
12 changes: 6 additions & 6 deletions CodeLegacy/Data/Implementations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public enum Ai
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()
Expand All @@ -32,7 +32,7 @@ public enum Ai
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()
Expand All @@ -41,7 +41,7 @@ public enum Ai
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
};

Expand All @@ -60,7 +60,7 @@ public enum Ai
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()
Expand All @@ -69,7 +69,7 @@ public enum Ai
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()
Expand All @@ -90,7 +90,7 @@ public enum Ai
{ Ai.FlavrCuda, flavrCuda },
{ Ai.DainNcnn, dainNcnn },
{ Ai.XvfiCuda, xvfiCuda },
{ Ai.IfrnetNcnn, ifrnetNcnn }
/* { Ai.IfrnetNcnn, ifrnetNcnn }, */
};

public static List<AiInfo> NetworksAll => AiLookup.Values.ToList();
Expand Down
32 changes: 24 additions & 8 deletions CodeLegacy/Extensions/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ public static bool GetBool(this string str)
}
}

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);
Expand Down Expand Up @@ -142,7 +158,7 @@ public static string[] SplitIntoLines(this string str)
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;
}
Expand Down Expand Up @@ -189,7 +205,7 @@ public static string TrimWhitespaces(this string str)
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);

Expand All @@ -199,12 +215,12 @@ public static string ReplaceLast (this string str, string stringToReplace, strin
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];
}
Expand All @@ -216,9 +232,9 @@ public static string FilenameSuffix(this string path, string suffix)
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(",", ".");
Expand Down Expand Up @@ -385,12 +401,12 @@ public static string Upper(this string s)
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);
}
Expand Down
44 changes: 30 additions & 14 deletions CodeLegacy/Forms/Main/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,77 +173,93 @@ async Task Checks()

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.InterpFactor > 0)
{
interpFactorCombox.Text = Cli.InterpFactor.ToString();
ValidateFactor();
}

if(Cli.OutputFormat != (Enums.Output.Format)(-1))
if (Cli.InterpModel.IsNotEmpty())
{
SetFormat(Cli.OutputFormat);
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.InterpModel.IsNotEmpty())
if (Cli.InterpFactor > 0)
{
aiModel.SelectedIndex = aiModel.Items.Cast<string>().Select((item, index) => new { item, index }).FirstOrDefault(x => x.item.Contains(Cli.InterpModel))?.index ?? -1;
interpFactorCombox.Text = Cli.InterpFactor.ToString();
ValidateFactor();
Logger.Log($"[CLI] Using interpolation factor {interpFactorCombox.Text}", true);
}

// 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<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))
{
comboxOutputEncoder.SelectedIndex = comboxOutputEncoder.Items.Cast<string>().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<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;
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());
}
}
Expand Down
5 changes: 5 additions & 0 deletions CodeLegacy/IO/IoUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ public static bool IsPathValid(string 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)
{
Directory.CreateDirectory(targetDirectory);
Expand Down
3 changes: 3 additions & 0 deletions CodeLegacy/Main/Interpolate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ public static void Cancel(string reason = "", bool noMsgBox = false)
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}");
}
Expand Down
10 changes: 8 additions & 2 deletions CodeLegacy/Main/InterpolateUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ public static bool InputIsValid(InterpSettings s)
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!");
Expand All @@ -118,9 +124,9 @@ public static bool InputIsValid(InterpSettings s)
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;
}

Expand Down
3 changes: 3 additions & 0 deletions CodeLegacy/Ui/UiUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public static DialogResult ShowMessageBox(string text, MessageType type = Messag
{
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);
Expand Down

0 comments on commit c31c76f

Please sign in to comment.