Cleaner logging, minor refactoring for ffmpeg caching

This commit is contained in:
n00mkrad
2025-12-22 21:59:09 +01:00
parent aed095f88b
commit b01a9984da
7 changed files with 12 additions and 45 deletions

View File

@@ -223,7 +223,7 @@ namespace Flowframes
float maxDeviationMs = (timestampDurations.Max() - timestampDurations.Min()) * 1000f;
float maxDeviationPercent = ((timestampDurations.Max() / timestampDurations.Min()) * 100f) - 100;
// float maxDeviationMsResampled = (timestampDurationsRes.Max() - timestampDurationsRes.Min()) * 1000f;
Logger.Log($"Timestamp durations - Min: {timestampDurations.Min() * 1000f} ms - Max: {timestampDurations.Max() * 1000f} ms - Avg: {avgDuration * 1000f} - Biggest deviation: {maxDeviationMs.ToString("0.##")} ms", hidden: true);
Logger.Log($"[VFR Check] Timestamp durations - Min: {timestampDurations.Min() * 1000f} ms - Max: {timestampDurations.Max() * 1000f} ms - Avg: {avgDuration * 1000f} - Biggest deviation: {maxDeviationMs.ToString("0.##")} ms", hidden: true);
// Logger.Log($"Resampled - Min ts duration: {timestampDurationsRes.Min() * 1000f} ms - Max ts duration: {timestampDurationsRes.Max() * 1000f} ms - Biggest deviation: {maxDeviationMsResampled.ToString("0.##")} ms", hidden: true);
mediaFile.InputTimestampDurations = new List<float>(timestampDurations);
@@ -305,7 +305,6 @@ namespace Flowframes
public static Size GetSize(string inputFile)
{
Logger.Log($"GetSize('{inputFile}')", true, false, "ffmpeg");
string args = $" -v panic -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 {inputFile.Wrap()}";
string[] outputLines = GetFfprobeOutput(args).SplitIntoLines();

View File

@@ -28,7 +28,6 @@ namespace Flowframes.Media
public static async Task<int> GetStreamCount(string path)
{
Logger.Log($"GetStreamCount({path})", true);
string output = await GetFfmpegInfoAsync(path, "Stream #0:");
if (string.IsNullOrWhiteSpace(output.Trim()))
@@ -179,7 +178,7 @@ namespace Flowframes.Media
Fraction fps = ffprobeFps.Float > 0f ? ffprobeFps : new Fraction(ffmpegFps);
Fraction avgFps = ffprobeFpsAvg.Float > 0f ? ffprobeFpsAvg : new Fraction(ffmpegTbr);
Logger.Log($"Ffprobe FPS: {ffprobeFps} ({ffprobeFps.GetString()}) - Ffprobe Avg FPS: {ffprobeFpsAvg} ({ffprobeFpsAvg.GetString()}) - Ffmpeg FPS: {ffmpegFps} - Ffmpeg TBR: {ffmpegTbr} - Est. FPS: {calculatedFps.ToString("0.#####")}", true);
Logger.Log($"[FPS Detection] ffprobe FPS: {ffprobeFps} ({ffprobeFps.GetString()}) - ffprobe avg FPS: {ffprobeFpsAvg} ({ffprobeFpsAvg.GetString()}) - ffmpeg FPS: {ffmpegFps} - ffmpeg TBR: {ffmpegTbr} - est. FPS: {calculatedFps.ToString("0.#####")}", true);
var info = new FpsInfo(fps); // Set both true FPS and average FPS to this number, assuming they match
@@ -192,7 +191,7 @@ namespace Flowframes.Media
if (allowFpsOverride && Math.Abs(fps.Float - calculatedFps) > fpsEstTolerance)
{
Logger.Log($"Detected FPS {fps} is not within tolerance (+-{fpsEstTolerance}) of calculated FPS ({calculatedFps}), using estimated FPS.", true);
Logger.Log($"[FPS Detection] Detected FPS {fps} is not within tolerance (+-{fpsEstTolerance}) of calculated FPS ({calculatedFps}), using estimated FPS.", true);
info.Fps = new Fraction(calculatedFps); // Change true FPS to the estimated FPS if the estimate does not match the specified FPS
}

View File

@@ -26,7 +26,7 @@ namespace Flowframes.Media
if (filesize > 0 && cache.ContainsKey(hash))
{
Logger.Log($"Using cached frame count value.", true);
Logger.Log($"Using cached frame count: {cache[hash]}", true);
return cache[hash];
}
@@ -50,7 +50,7 @@ namespace Flowframes.Media
if (frameCount > 0)
{
Logger.Log($"Caching frame count ({frameCount}).", true);
Logger.Log($"Got frame count of {frameCount} (caching)", true);
cache.Add(hash, frameCount);
}
else

View File

@@ -17,9 +17,9 @@ namespace Flowframes.Media
long filesize = IoUtils.GetPathSize(path);
QueryInfo hash = new QueryInfo(path, filesize);
if (filesize > 0 && CacheContains(hash))
if (filesize > 0 && cache.ContainsKey(hash))
{
Size cachedVal = GetFromCache(hash);
Size cachedVal = cache[hash];
Logger.Log($"Resolution of '{Path.GetFileName(path)}': {cachedVal.Width}x{cachedVal.Height} [Cached]", true);
return cachedVal;
}
@@ -36,16 +36,6 @@ namespace Flowframes.Media
return size;
}
private static bool CacheContains(QueryInfo hash)
{
return cache.Any(entry => entry.Key.Path == hash.Path && entry.Key.SizeBytes == hash.SizeBytes);
}
private static Size GetFromCache(QueryInfo hash)
{
return cache.Where(entry => entry.Key.Path == hash.Path && entry.Key.SizeBytes == hash.SizeBytes).Select(entry => entry.Value).FirstOrDefault();
}
public static void Clear()
{
cache.Clear();

View File

@@ -97,36 +97,15 @@ namespace Flowframes.Media
long filesize = IoUtils.GetPathSize(path);
QueryInfo hash = new QueryInfo(path, filesize, process.StartInfo.Arguments);
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");
return GetFromCache(hash, ref cmdCache);
}
if (!noCache && filesize > 0 && cmdCache.ContainsKey(hash))
return cmdCache[hash];
Logger.Log($"GetVideoInfo: '{process.StartInfo.FileName} {process.StartInfo.Arguments}' (not cached)", true, false, "ffmpeg");
Logger.Log($"GetVideoInfo: '{path}' (not cached)", true, false, "ffmpeg");
string output = await OsUtils.GetOutputAsync(process);
cmdCache.Add(hash, output);
return output;
}
private static bool CacheContains(QueryInfo hash, ref Dictionary<QueryInfo, string> cacheDict)
{
foreach (KeyValuePair<QueryInfo, string> entry in cacheDict)
if (entry.Key.Path == hash.Path && entry.Key.SizeBytes == hash.SizeBytes && entry.Key.Command == hash.Command)
return true;
return false;
}
private static string GetFromCache(QueryInfo hash, ref Dictionary<QueryInfo, string> cacheDict)
{
foreach (KeyValuePair<QueryInfo, string> entry in cacheDict)
if (entry.Key.Path == hash.Path && entry.Key.SizeBytes == hash.SizeBytes && entry.Key.Command == hash.Command)
return entry.Value;
return "";
}
public static void ClearCache()
{
cmdCache.Clear();

View File

@@ -38,7 +38,7 @@ namespace Flowframes.Os
}
catch (Exception e)
{
Logger.Log($"Failed to kill currentAiProcess process tree: {e.Message}", true);
Logger.Log($"Failed to kill process tree: {e.Message}", true);
}
}

View File

@@ -223,7 +223,7 @@ namespace Flowframes.Os
while (timeSinceLastOutput.ElapsedMilliseconds < 100) await Task.Delay(50);
output = output.Trim('\r', '\n');
Logger.Log($"Output (after {sw}): {output.Replace("\r", " / ").Replace("\n", " / ").Trunc(250)}", true);
Logger.Log($"Output (after {sw}): {output.Replace("\r", " / ").Replace("\n", " / ").Trunc(250)}", true, toConsole: Cli.Verbose);
if (onlyLastLine)
output = output.SplitIntoLines().LastOrDefault();