Reduce log spam, minor refactor stuff, disable GUI when using autorun

This commit is contained in:
N00MKRAD
2024-08-25 21:43:06 +02:00
parent 5a3a84bbdc
commit 70841fe21f
5 changed files with 21 additions and 44 deletions

View File

@@ -18,8 +18,7 @@ namespace Flowframes
public static bool DisablePython = false;
public static bool ShowMdlDownloader = false;
public static bool DontSaveConfig = false;
public static bool ExitWhenDone = false;
public static bool InterpStart = false;
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;
@@ -60,19 +59,15 @@ namespace Flowframes
v => DontSaveConfig = v != null
},
{
"e|exit", "Exit automatically after interpolation has finished",
v => ExitWhenDone = v != null
},
{
"s|start", "Start interpolation automatically if valid parameters are provided",
v => InterpStart = v != null
"a|autorun", "Start interpolation automatically if valid parameters are provided and exit afterwards",
v => AutoRun = v != null
},
{
"f|factor=", "Interpolation factor",
v => InterpFactor = v.GetFloat()
},
{
"a|ai=", $"Interpolation AI implementation to use (Option: {GetEnums<Implementations.Ai>()})",
"ai=", $"Interpolation AI implementation to use (Option: {GetEnums<Implementations.Ai>()})",
v => InterpAi = ParseUtils.GetEnum<Implementations.Ai>(v.Trim().Replace("_", ""))
},
{

View File

@@ -373,7 +373,7 @@ namespace Flowframes.Forms.Main
public void CompletionAction()
{
if (Cli.ExitWhenDone)
if (Cli.AutoRun)
Application.Exit();
if (completionAction.SelectedIndex == 1)
@@ -645,7 +645,7 @@ namespace Flowframes.Forms.Main
{
if (Program.busy) return;
bool start = Program.initialRun && Cli.InterpStart;
bool start = Program.initialRun && Cli.AutoRun;
if (files.Length > 1)
{

View File

@@ -368,47 +368,40 @@ namespace Flowframes.IO
public static async Task<Size> GetVideoOrFramesRes(string path)
{
Size res = new Size();
try
{
if (!IsPathDirectory(path)) // If path is video
{
res = GetVideoRes(path);
return GetVideoRes(path);
}
else // Path is frame folder
{
Image thumb = await MainUiFunctions.GetThumbnail(path);
res = new Size(thumb.Width, thumb.Height);
return new Size(thumb.Width, thumb.Height);
}
}
catch (Exception e)
{
Logger.Log("GetVideoOrFramesRes Error: " + e.Message);
Logger.Log($"GetVideoOrFramesRes Error: {e.Message}");
return new Size();
}
return res;
}
public static Size GetVideoRes(string path)
{
Size size = new Size(0, 0);
try
{
if (path.IsConcatFile())
path = ReadFileFirstLine(path).Split('\'')[1].Split('\'')[0];
size = FfmpegCommands.GetSize(path);
Logger.Log($"Detected video size of {Path.GetFileName(path)} as {size.Width}x{size.Height}", true);
return FfmpegCommands.GetSize(path);
}
catch (Exception ex)
{
Logger.Log("Failed to read video size!");
Logger.Log(ex.ToString(), true);
return new Size();
}
return size;
}
/// <summary>

View File

@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Flowframes.Data;
using Flowframes.IO;
@@ -12,19 +14,14 @@ namespace Flowframes.Media
public static async Task<Size> GetSizeAsync(string path)
{
Logger.Log($"Getting media resolution ({path})", true);
long filesize = IoUtils.GetPathSize(path);
QueryInfo hash = new QueryInfo(path, filesize);
if (filesize > 0 && CacheContains(hash))
{
Logger.Log($"Cache contains this hash, using cached value.", true);
return GetFromCache(hash);
}
else
{
Logger.Log($"Hash not cached, reading resolution.", true);
Size cachedVal = GetFromCache(hash);
Logger.Log($"Resolution of '{Path.GetFileName(path)}': {cachedVal.Width}x{cachedVal.Height} [Cached]", true);
return cachedVal;
}
Size size;
@@ -32,29 +29,21 @@ namespace Flowframes.Media
if(size.Width > 0 && size.Height > 0)
{
Logger.Log($"Adding hash with value {size} to cache.", true);
cache.Add(hash, size);
}
Logger.Log($"Resolution of '{Path.GetFileName(path)}': {size.Width}x{size.Height}", true);
return size;
}
private static bool CacheContains(QueryInfo hash)
{
foreach (KeyValuePair<QueryInfo, Size> entry in cache)
if (entry.Key.path == hash.path && entry.Key.filesize == hash.filesize)
return true;
return false;
return cache.Any(entry => entry.Key.path == hash.path && entry.Key.filesize == hash.filesize);
}
private static Size GetFromCache(QueryInfo hash)
{
foreach (KeyValuePair<QueryInfo, Size> entry in cache)
if (entry.Key.path == hash.path && entry.Key.filesize == hash.filesize)
return entry.Value;
return new Size();
return cache.Where(entry => entry.Key.path == hash.path && entry.Key.filesize == hash.filesize).Select(entry => entry.Value).FirstOrDefault();
}
public static void Clear()

View File

@@ -66,7 +66,7 @@ namespace Flowframes
bool showMdlDownloader = Cli.ShowMdlDownloader || args.Contains("show-model-downloader"); // The latter check may be needed for legacy reasons
mainForm = new Form1() { ShowModelDownloader = showMdlDownloader, Enabled = false };
mainForm = new Form1() { ShowModelDownloader = showMdlDownloader, Enabled = !Cli.AutoRun };
Application.Run(mainForm);
}