From 91320f536e41927ae56f28e07edbb98ca6fa928a Mon Sep 17 00:00:00 2001 From: n00mkrad <61149547+n00mkrad@users.noreply.github.com> Date: Mon, 12 Jan 2026 16:16:12 +0100 Subject: [PATCH] Cleaner syntax and logging --- CodeLegacy/Media/FfmpegCommands.cs | 43 +++++++++---------------- CodeLegacy/Media/GetFrameCountCached.cs | 10 +++--- 2 files changed, 21 insertions(+), 32 deletions(-) diff --git a/CodeLegacy/Media/FfmpegCommands.cs b/CodeLegacy/Media/FfmpegCommands.cs index 2a34b3e..d3c383a 100644 --- a/CodeLegacy/Media/FfmpegCommands.cs +++ b/CodeLegacy/Media/FfmpegCommands.cs @@ -17,7 +17,7 @@ namespace Flowframes public static string pngCompr = "-compression_level 3"; /// Lookup table for mpdecimate sensitivity preset values (lo/hi/frac). - public static Dictionary MpDecSensLookup = new Dictionary + public static Dictionary MpDecSensLookup = new Dictionary { { Enums.Interpolation.MpDecimateSens.Low, (3, 10, 0.33f) }, { Enums.Interpolation.MpDecimateSens.Normal, (4, 12, 0.50f) }, @@ -228,7 +228,7 @@ namespace Flowframes mediaFile.InputTimestampDurations = new List(timestampDurations); - if(Config.GetInt(Config.Key.vfrHandling) == 1) + if (Config.GetInt(Config.Key.vfrHandling) == 1) { Logger.Log($"Ignoring VFR deviation threshold of {maxDeviationPercent.ToString("0.##")}%, force-enabling VFR mode due to settings"); mediaFile.IsVfr = true; @@ -250,7 +250,7 @@ namespace Flowframes public static async Task GetFramerate(string inputFile, bool preferFfmpeg = false) { - Logger.Log($"Getting FPS from '{inputFile}', preferFfmpeg = {preferFfmpeg}", true, false, "ffmpeg"); + Logger.Log($"Getting FPS from '{inputFile}', preferring {(preferFfmpeg ? "ffmpeg" : "ffprobe")}", true, false, "ffmpeg"); Fraction ffprobeFps = new Fraction(0, 1); Fraction ffmpegFps = new Fraction(0, 1); @@ -259,12 +259,12 @@ namespace Flowframes string ffprobeOutput = await GetVideoInfo.GetFfprobeInfoAsync(inputFile, GetVideoInfo.FfprobeMode.ShowStreams, "r_frame_rate"); string fpsStr = ffprobeOutput.SplitIntoLines().First(); string[] numbers = fpsStr.Split('/'); - Logger.Log($"Fractional FPS from ffprobe: {numbers[0]}/{numbers[1]} = {((float)numbers[0].GetInt() / numbers[1].GetInt())}", true, false, "ffmpeg"); + Logger.Log($"Fractional FPS from ffprobe: {numbers[0]}/{numbers[1]} = {(float)numbers[0].GetInt() / numbers[1].GetInt()}", true, false, "ffmpeg"); ffprobeFps = new Fraction(numbers[0].GetInt(), numbers[1].GetInt()); } - catch (Exception ffprobeEx) + catch (Exception ex) { - Logger.Log("GetFramerate ffprobe Error: " + ffprobeEx.Message, true, false); + Logger.Log($"GetFramerate ffprobe error: {ex.Message}", true, false); } try @@ -282,25 +282,14 @@ namespace Flowframes } } } - catch (Exception ffmpegEx) + catch (Exception ex) { - Logger.Log("GetFramerate ffmpeg Error: " + ffmpegEx.Message, true, false); + Logger.Log($"GetFramerate ffmpeg error: {ex.Message}", true, false); } - if (preferFfmpeg) - { - if (ffmpegFps.Float > 0) - return ffmpegFps; - else - return ffprobeFps; - } - else - { - if (ffprobeFps.Float > 0) - return ffprobeFps; - else - return ffmpegFps; - } + Fraction preferredFps = preferFfmpeg ? ffmpegFps : ffprobeFps; + Fraction fallbackFps = preferFfmpeg ? ffprobeFps : ffmpegFps; + return preferredFps.Float > 0 ? preferredFps : fallbackFps; } public static Size GetSize(string inputFile) @@ -322,19 +311,19 @@ namespace Flowframes public static async Task GetFrameCountAsync(string inputFile) { - Logger.Log($"[Get Frame Count] Trying ffprobe packet counting first (fastest).", true, false, "ffmpeg"); + Logger.Log($"[Frame Count] Trying ffprobe packet counting first (fastest).", true, false, "ffmpeg"); int frames = await ReadFrameCountFfprobePacketCount(inputFile); // Try reading frame count with ffprobe packet counting if (frames > 0) return frames; - Logger.Log($"[Get Frame Count] Trying ffmpeg demuxing.", true, false, "ffmpeg"); + Logger.Log($"[Frame Count] Trying ffmpeg demuxing.", true, false, "ffmpeg"); frames = await ReadFrameCountFfmpegAsync(inputFile); // Try reading frame count with ffmpeg if (frames > 0) return frames; - Logger.Log($"[Get Frame Count] Trying ffprobe demuxing.", true, false, "ffmpeg"); + Logger.Log($"[Frame Count] Trying ffprobe demuxing.", true, false, "ffmpeg"); frames = await ReadFrameCountFfprobe(inputFile); // Try reading frame count with ffprobe decoding if (frames > 0) return frames; - Logger.Log("[Get Frame Count] Failed to get total frame count of video.", true); + Logger.Log("[Frame Count] Failed to get total frame count of video.", true); return 0; } @@ -343,7 +332,7 @@ namespace Flowframes float durationSeconds = durationMs / 1000f; float frameCount = durationSeconds * fps; int frameCountRounded = frameCount.RoundToInt(); - Logger.Log($"ReadFrameCountFromDuration: Got frame count of {frameCount}, rounded to {frameCountRounded}"); + Logger.Log($"[Frame Count] Estimated frame count to {frameCount}, rounded to {frameCountRounded}"); return frameCountRounded; } diff --git a/CodeLegacy/Media/GetFrameCountCached.cs b/CodeLegacy/Media/GetFrameCountCached.cs index 37a7e27..7e6478d 100644 --- a/CodeLegacy/Media/GetFrameCountCached.cs +++ b/CodeLegacy/Media/GetFrameCountCached.cs @@ -17,14 +17,14 @@ namespace Flowframes.Media public static async Task GetFrameCountAsync(string path, int retryCount = 3) { - Logger.Log($"Getting frame count ({path})...", true); + Logger.Log($"[Frame Count] Getting frame count ({path})...", true); long filesize = IoUtils.GetPathSize(path); QueryInfo hash = new QueryInfo(path, filesize); if (filesize > 0 && cache.ContainsKey(hash)) { - Logger.Log($"Using cached frame count: {cache[hash]}", true); + Logger.Log($"[Frame Count] {cache[hash]} frames (cached)", true); return cache[hash]; } @@ -48,20 +48,20 @@ namespace Flowframes.Media if (frameCount > 0) { - Logger.Log($"Got frame count of {frameCount} (caching)", true); + Logger.Log($"[Frame Count] {frameCount} frames", true); cache.Add(hash, frameCount); } else { if (retryCount > 0) { - Logger.Log($"Got {frameCount} frames, retrying ({retryCount} left)", true); + Logger.Log($"[Frame Count] Got {frameCount} frames, retrying ({retryCount} left)", true); Clear(); frameCount = await GetFrameCountAsync(path, retryCount - 1); } else { - Logger.Log($"Failed to get frames and out of retries ({frameCount} frames for {path})", true); + Logger.Log($"[Frame Count] Failed to get frames and out of retries ({frameCount} frames for {path})", true); } }