mirror of
https://github.com/n00mkrad/flowframes.git
synced 2025-12-17 00:47:48 +01:00
Retry GetFrameCountCached up to 3x, clear cmd output caches on new file
This commit is contained in:
@@ -229,7 +229,7 @@ namespace Flowframes
|
|||||||
public void UpdateInputInfo()
|
public void UpdateInputInfo()
|
||||||
{
|
{
|
||||||
string str = $"Size: {(!currInRes.IsEmpty ? $"{currInRes.Width}x{currInRes.Height}" : "Unknown")} - ";
|
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 += $"Frames: {(currInFrames > 0 ? $"{currInFrames}" : "Unknown")} - ";
|
||||||
str += $"Duration: {(currInDuration > 0 ? FormatUtils.MsToTimestamp(currInDuration) : "Unknown")}";
|
str += $"Duration: {(currInDuration > 0 ? FormatUtils.MsToTimestamp(currInDuration) : "Unknown")}";
|
||||||
inputInfo.Text = str;
|
inputInfo.Text = str;
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ namespace Flowframes
|
|||||||
if(extractedFrames == 1)
|
if(extractedFrames == 1)
|
||||||
Cancel("Only a single frame was extracted from your input file!\n\nPossibly your input is an image, not a video?");
|
Cancel("Only a single frame was extracted from your input file!\n\nPossibly your input is an image, not a video?");
|
||||||
else
|
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)
|
if (Config.GetInt(Config.Key.dedupMode) == 1)
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ namespace Flowframes.Media
|
|||||||
|
|
||||||
static bool HideMessage(string msg)
|
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)
|
foreach (string str in hiddenMsgs)
|
||||||
if (msg.MatchesWildcard($"*{str}*"))
|
if (msg.MatchesWildcard($"*{str}*"))
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ namespace Flowframes
|
|||||||
frames = await ReadFrameCountFfmpegAsync(inputFile); // Try reading frame count with ffmpeg
|
frames = await ReadFrameCountFfmpegAsync(inputFile); // Try reading frame count with ffmpeg
|
||||||
if (frames > 0) return frames;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ namespace Flowframes.Media
|
|||||||
{
|
{
|
||||||
class GetFrameCountCached
|
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);
|
Logger.Log($"Getting frame count ({path})", true);
|
||||||
|
|
||||||
@@ -35,8 +35,23 @@ namespace Flowframes.Media
|
|||||||
else
|
else
|
||||||
frameCount = await FfmpegCommands.GetFrameCountAsync(path);
|
frameCount = await FfmpegCommands.GetFrameCountAsync(path);
|
||||||
|
|
||||||
Logger.Log($"Adding hash with value {frameCount} to cache.", true);
|
if(frameCount > 0)
|
||||||
cache.Add(hash, frameCount);
|
{
|
||||||
|
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;
|
return frameCount;
|
||||||
}
|
}
|
||||||
@@ -58,5 +73,10 @@ namespace Flowframes.Media
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Clear ()
|
||||||
|
{
|
||||||
|
cache.Clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace Flowframes.Media
|
|||||||
{
|
{
|
||||||
class GetMediaResolutionCached
|
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)
|
public static async Task<Size> GetSizeAsync(string path)
|
||||||
{
|
{
|
||||||
@@ -31,8 +31,11 @@ namespace Flowframes.Media
|
|||||||
Size size;
|
Size size;
|
||||||
size = await IoUtils.GetVideoOrFramesRes(path);
|
size = await IoUtils.GetVideoOrFramesRes(path);
|
||||||
|
|
||||||
Logger.Log($"Adding hash with value {size} to cache.", true);
|
if(size.Width > 0 && size.Height > 0)
|
||||||
cache.Add(hash, size);
|
{
|
||||||
|
Logger.Log($"Adding hash with value {size} to cache.", true);
|
||||||
|
cache.Add(hash, size);
|
||||||
|
}
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
@@ -54,5 +57,10 @@ namespace Flowframes.Media
|
|||||||
|
|
||||||
return new Size();
|
return new Size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Clear()
|
||||||
|
{
|
||||||
|
cache.Clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ namespace Flowframes.Ui
|
|||||||
Program.mainForm.ResetInputInfo();
|
Program.mainForm.ResetInputInfo();
|
||||||
string path = inputTbox.Text.Trim();
|
string path = inputTbox.Text.Trim();
|
||||||
|
|
||||||
|
GetFrameCountCached.Clear();
|
||||||
|
GetMediaResolutionCached.Clear();
|
||||||
|
|
||||||
if (Config.GetBool(Config.Key.clearLogOnInput))
|
if (Config.GetBool(Config.Key.clearLogOnInput))
|
||||||
Logger.ClearLogBox();
|
Logger.ClearLogBox();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user