2024-08-25 20:45:50 +02:00
|
|
|
|
using Flowframes.Data;
|
|
|
|
|
|
using Flowframes.Extensions;
|
|
|
|
|
|
using Flowframes.IO;
|
|
|
|
|
|
using Flowframes.MiscUtils;
|
|
|
|
|
|
using Flowframes.Os;
|
|
|
|
|
|
using NDesk.Options;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Flowframes
|
|
|
|
|
|
{
|
|
|
|
|
|
public class Cli
|
|
|
|
|
|
{
|
|
|
|
|
|
public static bool ShowConsole = false;
|
2024-09-06 16:11:49 +02:00
|
|
|
|
public static bool DisablePython = true;
|
2024-08-25 20:45:50 +02:00
|
|
|
|
public static bool ShowMdlDownloader = false;
|
|
|
|
|
|
public static bool DontSaveConfig = false;
|
2024-08-25 21:43:06 +02:00
|
|
|
|
public static bool AutoRun = false;
|
2024-08-25 20:45:50 +02:00
|
|
|
|
public static float InterpFactor = -1f;
|
|
|
|
|
|
public static Implementations.Ai InterpAi = (Implementations.Ai)(-1);
|
2024-09-03 22:01:32 +02:00
|
|
|
|
public static Enums.Output.Format OutputFormat = (Enums.Output.Format)(-1);
|
2024-08-25 20:45:50 +02:00
|
|
|
|
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;
|
2024-09-03 22:01:32 +02:00
|
|
|
|
public static bool? Loop = null;
|
|
|
|
|
|
public static bool? FixSceneChanges = null;
|
2024-08-25 20:45:50 +02:00
|
|
|
|
public static float FixSceneChangeVal = -1f;
|
|
|
|
|
|
public static float MaxOutFps = -1f;
|
|
|
|
|
|
public static List<string> ValidFiles = new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true)]
|
|
|
|
|
|
private static extern int FreeConsole();
|
|
|
|
|
|
|
|
|
|
|
|
public static void HandleCli()
|
|
|
|
|
|
{
|
|
|
|
|
|
string GetEnums<T>() => string.Join(", ", Enum.GetNames(typeof(T)));
|
|
|
|
|
|
|
2024-09-03 22:01:32 +02:00
|
|
|
|
var optsSet = new OptionSet
|
2024-08-25 20:45:50 +02:00
|
|
|
|
{
|
2024-09-27 14:52:37 +02:00
|
|
|
|
// {
|
|
|
|
|
|
// "c|console", "Show console",
|
|
|
|
|
|
// v => ShowConsole = v != null
|
|
|
|
|
|
// },
|
2024-08-25 20:45:50 +02:00
|
|
|
|
{
|
|
|
|
|
|
"np|no_python", "Disable Python implementations",
|
|
|
|
|
|
v => DisablePython = v != null
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2024-09-06 16:11:49 +02:00
|
|
|
|
"py|enable_python", "Enable Python implementations",
|
|
|
|
|
|
v => DisablePython = !(v != null)
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2024-08-25 20:45:50 +02:00
|
|
|
|
"md|open_model_downloader", "Open model downloader GUI on startup",
|
|
|
|
|
|
v => ShowMdlDownloader = v != null
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
"nc|no_config_save", "Do not save anything in config during this session",
|
|
|
|
|
|
v => DontSaveConfig = v != null
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2024-08-25 21:43:06 +02:00
|
|
|
|
"a|autorun", "Start interpolation automatically if valid parameters are provided and exit afterwards",
|
|
|
|
|
|
v => AutoRun = v != null
|
2024-08-25 20:45:50 +02:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
"f|factor=", "Interpolation factor",
|
|
|
|
|
|
v => InterpFactor = v.GetFloat()
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2024-08-25 21:43:06 +02:00
|
|
|
|
"ai=", $"Interpolation AI implementation to use (Option: {GetEnums<Implementations.Ai>()})",
|
2024-08-25 20:45:50 +02:00
|
|
|
|
v => InterpAi = ParseUtils.GetEnum<Implementations.Ai>(v.Trim().Replace("_", ""))
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
"m|model=", "AI model to use",
|
|
|
|
|
|
v => InterpModel = v.Trim()
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
"vf|video_format=", $"Output video format to use (Options: {GetEnums<Enums.Output.Format>()})",
|
|
|
|
|
|
v => OutputFormat = ParseUtils.GetEnum<Enums.Output.Format>(v.Trim())
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
"ve|video_encoder=", $"Output video encoder to use (Options: {GetEnums<Enums.Encoding.Encoder>()})",
|
|
|
|
|
|
v => Encoder = ParseUtils.GetEnum<Enums.Encoding.Encoder>(v.Trim())
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
"pf|pixel_format=", $"Output pixel format to use (Options: {GetEnums<Enums.Encoding.PixelFormat>()})",
|
|
|
|
|
|
v => PixFmt = ParseUtils.GetEnum<Enums.Encoding.PixelFormat>(v.Trim())
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2024-09-03 22:01:32 +02:00
|
|
|
|
"mh|max_height=", $"Max video size in height pixels. Larger videos will be downscaled. (Example: 720)",
|
2024-08-25 20:45:50 +02:00
|
|
|
|
v => MaxHeight = v.GetInt()
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2024-09-03 22:01:32 +02:00
|
|
|
|
"l|loop=", $"Enable loop output mode",
|
|
|
|
|
|
v => Loop = v.GetBoolCli()
|
2024-08-25 20:45:50 +02:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2024-09-03 22:01:32 +02:00
|
|
|
|
"scn|fix_scene_changes=", $"Do not interpolate scene cuts to avoid artifacts",
|
|
|
|
|
|
v => FixSceneChanges = v.GetBoolCli()
|
2024-08-25 20:45:50 +02:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
"scnv|scene_change_sensitivity=", $"Scene change sensitivity, lower is more sensitive (e.g. 0.18)",
|
|
|
|
|
|
v => FixSceneChangeVal = v.GetFloat()
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
"fps|max_fps=", $"Maximum FPS of output video, if the interpolation factor results in a higher FPS, it will be reduced to this value",
|
|
|
|
|
|
v => MaxOutFps = v.GetFloat()
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
"o|output_dir=", "Output folder to save the interpolated video in",
|
|
|
|
|
|
v => OutputDir = v.Trim()
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
"<>", "Input file(s)",
|
|
|
|
|
|
ValidFiles.Add
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-09-03 22:01:32 +02:00
|
|
|
|
var opts = new ArgParseExtensions.Options() { OptionsSet = optsSet, BasicUsage = "<OPTIONS> <FILE(S)>", AddHelpArg = true };
|
|
|
|
|
|
|
2024-08-25 20:45:50 +02:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!opts.TryParseOptions(Environment.GetCommandLineArgs()))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2024-09-27 14:52:37 +02:00
|
|
|
|
// if (!ShowConsole)
|
|
|
|
|
|
// FreeConsole();
|
2024-08-25 20:45:50 +02:00
|
|
|
|
|
|
|
|
|
|
Python.DisablePython = DisablePython;
|
|
|
|
|
|
Config.NoWrite = DontSaveConfig;
|
2024-09-03 22:01:32 +02:00
|
|
|
|
|
|
|
|
|
|
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
|
2024-08-25 20:45:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
catch (OptionException e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Logger.Log($"Error parsing CLI options: {e.Message}", true);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|