From 5a3a84bbdc4951b277dd5d58618b4d7a0626134f Mon Sep 17 00:00:00 2001
From: N00MKRAD <61149547+n00mkrad@users.noreply.github.com>
Date: Sun, 25 Aug 2024 21:18:38 +0200
Subject: [PATCH] Cleanup n stuff
---
CodeLegacy/Flowframes.csproj | 1 -
CodeLegacy/Forms/Main/Form1.cs | 5 +-
CodeLegacy/IO/IoUtils.cs | 10 +--
CodeLegacy/Main/Export.cs | 2 +-
CodeLegacy/Media/FfmpegExtract.cs | 12 ++--
CodeLegacy/Media/FfmpegUtils.cs | 14 ++--
CodeLegacy/Media/GetVideoInfo.cs | 4 +-
CodeLegacy/MiscUtils/BackgroundTaskManager.cs | 68 -------------------
8 files changed, 19 insertions(+), 97 deletions(-)
delete mode 100644 CodeLegacy/MiscUtils/BackgroundTaskManager.cs
diff --git a/CodeLegacy/Flowframes.csproj b/CodeLegacy/Flowframes.csproj
index 34ce0ab..8d01320 100644
--- a/CodeLegacy/Flowframes.csproj
+++ b/CodeLegacy/Flowframes.csproj
@@ -457,7 +457,6 @@
-
diff --git a/CodeLegacy/Forms/Main/Form1.cs b/CodeLegacy/Forms/Main/Form1.cs
index 5d80dbb..e21bfcd 100644
--- a/CodeLegacy/Forms/Main/Form1.cs
+++ b/CodeLegacy/Forms/Main/Form1.cs
@@ -613,14 +613,11 @@ namespace Flowframes.Forms.Main
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
- if (!Program.busy && !BackgroundTaskManager.IsBusy())
+ if (!Program.busy)
return;
string reason = "";
- if (BackgroundTaskManager.IsBusy())
- reason = "Some background tasks have not finished yet.";
-
if (Program.busy)
reason = "The program is still busy.";
diff --git a/CodeLegacy/IO/IoUtils.cs b/CodeLegacy/IO/IoUtils.cs
index 25f70ee..518a060 100644
--- a/CodeLegacy/IO/IoUtils.cs
+++ b/CodeLegacy/IO/IoUtils.cs
@@ -157,10 +157,7 @@ namespace Flowframes.IO
///
public static async Task DeleteContentsOfDirAsync(string path)
{
- ulong taskId = BackgroundTaskManager.Add($"DeleteContentsOfDirAsync {path}");
- bool returnVal = await Task.Run(async () => { return DeleteContentsOfDir(path); });
- BackgroundTaskManager.Remove(taskId);
- return returnVal;
+ return await Task.Run(() => DeleteContentsOfDir(path));
}
///
@@ -442,10 +439,7 @@ namespace Flowframes.IO
path = renamedPath;
- ulong taskId = BackgroundTaskManager.Add($"TryDeleteIfExistsAsync {path}");
- bool returnVal = await Task.Run(async () => { return TryDeleteIfExists(path); });
- BackgroundTaskManager.Remove(taskId);
- return returnVal;
+ return await TryDeleteIfExistsAsync(path);
}
catch (Exception e)
{
diff --git a/CodeLegacy/Main/Export.cs b/CodeLegacy/Main/Export.cs
index 75fa092..064480d 100644
--- a/CodeLegacy/Main/Export.cs
+++ b/CodeLegacy/Main/Export.cs
@@ -249,7 +249,7 @@ namespace Flowframes.Main
await MergeChunks(tempConcatFile, outPath, isBackup);
if (!isBackup)
- Task.Run(async () => { await IoUtils.TryDeleteIfExistsAsync(IoUtils.FilenameSuffix(outPath, Paths.backupSuffix)); });
+ await IoUtils.TryDeleteIfExistsAsync(IoUtils.FilenameSuffix(outPath, Paths.backupSuffix));
}
}
catch (Exception e)
diff --git a/CodeLegacy/Media/FfmpegExtract.cs b/CodeLegacy/Media/FfmpegExtract.cs
index a58a49e..33c09c5 100644
--- a/CodeLegacy/Media/FfmpegExtract.cs
+++ b/CodeLegacy/Media/FfmpegExtract.cs
@@ -308,8 +308,8 @@ namespace Flowframes.Media
string sizeStr = (size.Width > 1 && size.Height > 1) ? $"-s {size.Width}x{size.Height}" : "";
bool isPng = (Path.GetExtension(outPath).ToLowerInvariant() == ".png");
string comprArg = isPng ? pngCompr : "";
- string pixFmt = "-pix_fmt " + (isPng ? $"rgb24 {comprArg}" : "yuvj420p");
- string args = $"-i {inputFile.Wrap()} {comprArg} {sizeStr} {pixFmt} -vf {GetPadFilter()} {outPath.Wrap()}";
+ string pixFmt = isPng ? $"rgb24 {comprArg}" : "yuv420p -color_range full";
+ string args = $"-i {inputFile.Wrap()} {comprArg} {sizeStr} -pix_fmt {pixFmt} -vf {GetPadFilter()} {outPath.Wrap()}";
await RunFfmpeg(args, LogMode.Hidden);
}
@@ -317,8 +317,8 @@ namespace Flowframes.Media
{
bool isPng = (Path.GetExtension(outputPath).ToLowerInvariant() == ".png");
string comprArg = isPng ? pngCompr : "";
- string pixFmt = "-pix_fmt " + (isPng ? $"rgb24 {comprArg}" : "yuvj420p");
- string args = $"-i {inputFile.Wrap()} -vf \"select=eq(n\\,{frameNum})\" -vframes 1 {pixFmt} {outputPath.Wrap()}";
+ string pixFmt = isPng ? $"rgb24 {comprArg}" : "yuv420p -color_range full";
+ string args = $"-i {inputFile.Wrap()} -vf \"select=eq(n\\,{frameNum})\" -vframes 1 -update 1 -pix_fmt {pixFmt} {outputPath.Wrap()}";
await RunFfmpeg(args, LogMode.Hidden);
}
@@ -332,11 +332,11 @@ namespace Flowframes.Media
bool isPng = (Path.GetExtension(outputPath).ToLowerInvariant() == ".png");
string comprArg = isPng ? pngCompr : "";
- string pixFmt = "-pix_fmt " + (isPng ? $"rgb24 {comprArg}" : "yuvj420p");
+ string pixFmt = isPng ? $"rgb24 {comprArg}" : "yuv420p -color_range full";
string sizeStr = (size.Width > 1 && size.Height > 1) ? $"-s {size.Width}x{size.Height}" : "";
string trim = QuickSettingsTab.trimEnabled ? $"-ss {QuickSettingsTab.GetTrimEndMinusOne()} -to {QuickSettingsTab.trimEnd}" : "";
string sseof = string.IsNullOrWhiteSpace(trim) ? "-sseof -1" : "";
- string args = $"{sseof} -i {inputFile.Wrap()} -update 1 {pixFmt} {sizeStr} {trim} {outputPath.Wrap()}";
+ string args = $"{sseof} -i {inputFile.Wrap()} -update 1 -pix_fmt {pixFmt} {sizeStr} {trim} {outputPath.Wrap()}";
await RunFfmpeg(args, LogMode.Hidden);
}
diff --git a/CodeLegacy/Media/FfmpegUtils.cs b/CodeLegacy/Media/FfmpegUtils.cs
index 04f19f3..cbd41c7 100644
--- a/CodeLegacy/Media/FfmpegUtils.cs
+++ b/CodeLegacy/Media/FfmpegUtils.cs
@@ -434,9 +434,6 @@ namespace Flowframes.Media
public static bool ContainerSupportsAllAudioFormats(Enums.Output.Format outFormat, List codecs)
{
- if (codecs.Count < 1)
- Logger.Log($"Warning: ContainerSupportsAllAudioFormats() was called, but codec list has {codecs.Count} entries.", true, false, "ffmpeg");
-
foreach (string format in codecs)
{
if (!ContainerSupportsAudioFormat(outFormat, format))
@@ -538,17 +535,20 @@ namespace Flowframes.Media
{
containerExt = containerExt.Remove(".");
- if (containerExt == "mp4" || containerExt == "mov") return "mov_text";
- if (containerExt == "webm") return "webvtt";
+ if (containerExt == "mp4" || containerExt == "mov")
+ return "mov_text";
+
+ if (containerExt == "webm")
+ return "webvtt";
return "copy"; // Default: Copy subs
}
public static bool ContainerSupportsSubs(string containerExt, bool showWarningIfNotSupported = true)
{
- containerExt = containerExt.Remove(".");
+ containerExt = containerExt.Lower().Remove(".");
bool supported = (containerExt == "mp4" || containerExt == "mkv" || containerExt == "webm" || containerExt == "mov");
- Logger.Log($"Subtitles {(supported ? "are supported" : "not supported")} by {containerExt.ToUpper()}", true);
+ // Logger.Log($"Subtitles {(supported ? "are supported" : "not supported")} by {containerExt.ToUpper()}", true);
if (showWarningIfNotSupported && Config.GetBool(Config.Key.keepSubs) && !supported)
Logger.Log($"Warning: {containerExt.ToUpper()} exports do not include subtitles.");
diff --git a/CodeLegacy/Media/GetVideoInfo.cs b/CodeLegacy/Media/GetVideoInfo.cs
index ceca63b..6567cbb 100644
--- a/CodeLegacy/Media/GetVideoInfo.cs
+++ b/CodeLegacy/Media/GetVideoInfo.cs
@@ -99,11 +99,11 @@ namespace Flowframes.Media
if (!noCache && filesize > 0 && CacheContains(hash, ref cmdCache))
{
- Logger.Log($"GetVideoInfo: '{process.StartInfo.FileName} {process.StartInfo.Arguments}' cached, won't re-run.", true, false, "ffmpeg");
+ // Logger.Log($"GetVideoInfo: '{process.StartInfo.FileName} {process.StartInfo.Arguments}' cached, won't re-run.", true, false, "ffmpeg");
return GetFromCache(hash, ref cmdCache);
}
- Logger.Log($"GetVideoInfo: '{process.StartInfo.FileName} {process.StartInfo.Arguments}' not cached, running.", true, false, "ffmpeg");
+ Logger.Log($"GetVideoInfo: '{process.StartInfo.FileName} {process.StartInfo.Arguments}' (not cached)", true, false, "ffmpeg");
string output = await OsUtils.GetOutputAsync(process);
cmdCache.Add(hash, output);
return output;
diff --git a/CodeLegacy/MiscUtils/BackgroundTaskManager.cs b/CodeLegacy/MiscUtils/BackgroundTaskManager.cs
deleted file mode 100644
index 5bd648c..0000000
--- a/CodeLegacy/MiscUtils/BackgroundTaskManager.cs
+++ /dev/null
@@ -1,68 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Flowframes.MiscUtils
-{
- class BackgroundTaskManager
- {
- public static ulong currentId = 0;
- public static List runningTasks = new List();
-
- public class RunningTask
- {
- public NmkdStopwatch timer;
- public string name;
- public ulong id;
- public int timeoutSeconds;
-
- public RunningTask (string name, ulong id, int timeoutSeconds)
- {
- this.name = name;
- this.id = id;
- this.timeoutSeconds = timeoutSeconds;
- timer = new NmkdStopwatch();
- }
- }
-
- public static bool IsBusy ()
- {
- Logger.Log($"[BgTaskMgr] BackgroundTaskManager is busy - {runningTasks.Count} tasks running.", true);
- return runningTasks.Count > 0;
- }
-
- public static void ClearExpired ()
- {
- foreach(RunningTask task in runningTasks)
- {
- if(task.timer.Sw.ElapsedMilliseconds > task.timeoutSeconds * 1000)
- {
- Logger.Log($"[BgTaskMgr] Task with ID {task.id} timed out, has been running for {task.timer}!", true);
- runningTasks.Remove(task);
- }
- }
- }
-
- public static ulong Add(string name = "Unnamed Task", int timeoutSeconds = 120)
- {
- ulong id = currentId;
- runningTasks.Add(new RunningTask(name, currentId, timeoutSeconds));
- currentId++;
- return id;
- }
-
- public static void Remove(ulong id)
- {
- foreach(RunningTask task in new List(runningTasks))
- {
- if(task.id == id)
- {
- Logger.Log($"[BgTaskMgr] Task '{task.name}' has finished after {task.timer} (Timeout {task.timeoutSeconds}s)", true);
- runningTasks.Remove(task);
- }
- }
- }
- }
-}