Retry GetFrameCountCached up to 3x, clear cmd output caches on new file

This commit is contained in:
n00mkrad 2022-04-05 18:07:05 +02:00
parent dd98b02355
commit 483aa46ebb
7 changed files with 42 additions and 11 deletions

View File

@ -229,7 +229,7 @@ namespace Flowframes
public void UpdateInputInfo()
{
string str = $"Size: {(!currInRes.IsEmpty ? $"{currInRes.Width}x{currInRes.Height}" : "Unknown")} - ";
str += $"Rate: {(currInFpsDetected.GetFloat() > 0f ? $"{currInFpsDetected} ({currInFpsDetected.GetFloat()})" : "Unknown")} - ";
str += $"FPS: {(currInFpsDetected.GetFloat() > 0f ? $"{currInFpsDetected} ({currInFpsDetected.GetFloat().ToString("0.000")})" : "Unknown")} - ";
str += $"Frames: {(currInFrames > 0 ? $"{currInFrames}" : "Unknown")} - ";
str += $"Duration: {(currInDuration > 0 ? FormatUtils.MsToTimestamp(currInDuration) : "Unknown")}";
inputInfo.Text = str;

View File

@ -149,7 +149,7 @@ namespace Flowframes
if(extractedFrames == 1)
Cancel("Only a single frame was extracted from your input file!\n\nPossibly your input is an image, not a video?");
else
Cancel($"Frame extraction failed!\nExtracted {extractedFrames} frames.\n\nYour input file might be incompatible.");
Cancel($"Frame extraction failed!\nExtracted {extractedFrames} frames - current.framesFolder exists: {Directory.Exists(current.framesFolder)} - currentInputFrameCount = {currentInputFrameCount} - extractedFrames = {extractedFrames}.\n\nYour input file might be incompatible.");
}
if (Config.GetInt(Config.Key.dedupMode) == 1)

View File

@ -120,7 +120,7 @@ namespace Flowframes.Media
static bool HideMessage(string msg)
{
string[] hiddenMsgs = new string[] { "can produce invalid output", "pixel format", "provided invalid" };
string[] hiddenMsgs = new string[] { "can produce invalid output", "pixel format", "provided invalid", "Non-monotonous", "not enough frames to estimate rate", "invalid dropping", "message repeated" };
foreach (string str in hiddenMsgs)
if (msg.MatchesWildcard($"*{str}*"))

View File

@ -170,7 +170,7 @@ namespace Flowframes
frames = await ReadFrameCountFfmpegAsync(inputFile); // Try reading frame count with ffmpeg
if (frames > 0) return frames;
Logger.Log("Failed to get total frame count of video.");
Logger.Log("Failed to get total frame count of video.", true);
return 0;
}

View File

@ -9,9 +9,9 @@ namespace Flowframes.Media
{
class GetFrameCountCached
{
public static Dictionary<QueryInfo, int> cache = new Dictionary<QueryInfo, int>();
private static Dictionary<QueryInfo, int> cache = new Dictionary<QueryInfo, int>();
public static async Task<int> GetFrameCountAsync(string path)
public static async Task<int> GetFrameCountAsync(string path, int retryCount = 3)
{
Logger.Log($"Getting frame count ({path})", true);
@ -35,8 +35,23 @@ namespace Flowframes.Media
else
frameCount = await FfmpegCommands.GetFrameCountAsync(path);
Logger.Log($"Adding hash with value {frameCount} to cache.", true);
cache.Add(hash, frameCount);
if(frameCount > 0)
{
Logger.Log($"Adding hash with value {frameCount} to cache.", true);
cache.Add(hash, frameCount);
}
else
{
if (retryCount > 0)
{
Logger.Log($"Got {frameCount} frames, retrying ({retryCount} left)", true);
frameCount = await GetFrameCountAsync(path, retryCount - 1);
}
else
{
Logger.Log($"Failed to get frames and out of retries ({frameCount} frames for {path})", true);
}
}
return frameCount;
}
@ -58,5 +73,10 @@ namespace Flowframes.Media
return 0;
}
public static void Clear ()
{
cache.Clear();
}
}
}

View File

@ -9,7 +9,7 @@ namespace Flowframes.Media
{
class GetMediaResolutionCached
{
public static Dictionary<QueryInfo, Size> cache = new Dictionary<QueryInfo, Size>();
private static Dictionary<QueryInfo, Size> cache = new Dictionary<QueryInfo, Size>();
public static async Task<Size> GetSizeAsync(string path)
{
@ -31,8 +31,11 @@ namespace Flowframes.Media
Size size;
size = await IoUtils.GetVideoOrFramesRes(path);
Logger.Log($"Adding hash with value {size} to cache.", true);
cache.Add(hash, size);
if(size.Width > 0 && size.Height > 0)
{
Logger.Log($"Adding hash with value {size} to cache.", true);
cache.Add(hash, size);
}
return size;
}
@ -54,5 +57,10 @@ namespace Flowframes.Media
return new Size();
}
public static void Clear()
{
cache.Clear();
}
}
}

View File

@ -23,6 +23,9 @@ namespace Flowframes.Ui
Program.mainForm.ResetInputInfo();
string path = inputTbox.Text.Trim();
GetFrameCountCached.Clear();
GetMediaResolutionCached.Clear();
if (Config.GetBool(Config.Key.clearLogOnInput))
Logger.ClearLogBox();