From 607bbc6ae2a200a028efc94821fa10cf3ee44ed9 Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Tue, 18 May 2021 20:44:08 +0200 Subject: [PATCH] Fix problems with automatic GIF 50 fps resampling --- Code/Main/InterpolateUtils.cs | 5 +++-- Code/Media/FfmpegEncode.cs | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Code/Main/InterpolateUtils.cs b/Code/Main/InterpolateUtils.cs index f4b7880..11254ab 100644 --- a/Code/Main/InterpolateUtils.cs +++ b/Code/Main/InterpolateUtils.cs @@ -120,9 +120,10 @@ namespace Flowframes.Main passes = false; } - Fraction fpsLimit = new Fraction(Config.Get(Config.Key.maxFps)); + string fpsLimitValue = Config.Get(Config.Key.maxFps); + float fpsLimit = (fpsLimitValue.Contains("/") ? new Fraction(Config.Get(Config.Key.maxFps)).GetFloat() : fpsLimitValue.GetFloat()); - if (outMode == I.OutMode.VidGif && fpsOut.GetFloat() > 50 && !(fpsLimit.GetFloat() > 0 && fpsLimit.GetFloat() <= 50)) + if (outMode == I.OutMode.VidGif && fpsOut.GetFloat() > 50 && !(fpsLimit > 0 && fpsLimit <= 50)) Logger.Log($"Warning: GIF will be encoded at 50 FPS instead of {fpsOut.GetFloat()} as the format doesn't support frame rates that high."); if (!passes) diff --git a/Code/Media/FfmpegEncode.cs b/Code/Media/FfmpegEncode.cs index ca7a296..14ef949 100644 --- a/Code/Media/FfmpegEncode.cs +++ b/Code/Media/FfmpegEncode.cs @@ -86,11 +86,13 @@ namespace Flowframes.Media public static async Task FramesToGifConcat(string framesFile, string outPath, Fraction rate, bool palette, int colors, Fraction resampleFps, LogMode logMode = LogMode.OnlyLastLine) { - if (rate.GetFloat() > 50f && resampleFps.GetFloat() < 50f) + Logger.Log($"GIF Rate: {rate} (Float: {rate.GetFloat()}) - Resample Rate: {resampleFps} (Float: {resampleFps.GetFloat()})"); + + if (rate.GetFloat() > 50f && (resampleFps.GetFloat() > 50f || resampleFps.GetFloat() < 1)) resampleFps = new Fraction(50, 1); // Force limit framerate as encoding above 50 will cause problems if (logMode != LogMode.Hidden) - Logger.Log((resampleFps.GetFloat() <= 0) ? $"Encoding GIF..." : $"Encoding GIF resampled to {resampleFps.ToString().Replace(",", ".")} FPS..."); + Logger.Log((resampleFps.GetFloat() <= 0) ? $"Encoding GIF..." : $"Encoding GIF resampled to {resampleFps.GetFloat().ToString().Replace(",", ".")} FPS..."); string framesFilename = Path.GetFileName(framesFile); string dither = Config.Get(Config.Key.gifDitherType).Split(' ').First();