diff --git a/Code/IO/IOUtils.cs b/Code/IO/IOUtils.cs index ec5291b..aa18672 100644 --- a/Code/IO/IOUtils.cs +++ b/Code/IO/IOUtils.cs @@ -403,6 +403,9 @@ namespace Flowframes.IO InterpSettings curr = Interpolate.current; float fps = fpsLimit ? Config.GetFloat("maxFps") : curr.outFps.GetFloat(); + if (curr.outMode == Interpolate.OutMode.VidGif && fps > 50f) + fps = 50f; + string pattern = Config.Get("exportNamePattern"); string inName = Interpolate.current.inputIsFrames ? Path.GetFileName(curr.inPath) : Path.GetFileNameWithoutExtension(curr.inPath); bool encodeBoth = Config.GetInt("maxFpsMode") == 0; diff --git a/Code/Main/InterpolateUtils.cs b/Code/Main/InterpolateUtils.cs index 7cc770a..868f354 100644 --- a/Code/Main/InterpolateUtils.cs +++ b/Code/Main/InterpolateUtils.cs @@ -306,28 +306,25 @@ namespace Flowframes.Main ShowMessage("Input path is not valid!"); passes = false; } + if (passes && !IOUtils.IsDirValid(outDir)) { ShowMessage("Output path is not valid!"); passes = false; } - if (passes && /*factor != 2 && factor != 4 && factor != 8*/ factor > 16) - { - ShowMessage("Interpolation factor is not valid!"); - passes = false; - } - if (passes && outMode == I.OutMode.VidGif && fpsOut.GetFloat() > 50 && !(Config.GetFloat("maxFps") != 0 && Config.GetFloat("maxFps") <= 50)) - { - ShowMessage("Invalid output frame rate!\nGIF does not properly support frame rates above 50 FPS.\nPlease use MP4, WEBM or another video format."); - passes = false; - } + if (passes && fpsOut.GetFloat() < 1f || fpsOut.GetFloat() > 1000f) { ShowMessage($"Invalid output frame rate ({fpsOut.GetFloat()}).\nMust be 1-1000."); passes = false; } + + if (outMode == I.OutMode.VidGif && fpsOut.GetFloat() > 50 && !(Config.GetFloat("maxFps") != 0 && Config.GetFloat("maxFps") <= 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) I.Cancel("Invalid settings detected.", true); + return passes; } diff --git a/Code/Media/FfmpegEncode.cs b/Code/Media/FfmpegEncode.cs index 1b24e1f..5eaf226 100644 --- a/Code/Media/FfmpegEncode.cs +++ b/Code/Media/FfmpegEncode.cs @@ -70,8 +70,12 @@ namespace Flowframes.Media public static async Task FramesToGifConcat(string framesFile, string outPath, Fraction rate, bool palette, int colors = 64, float resampleFps = -1, LogMode logMode = LogMode.OnlyLastLine) { + if (rate.GetFloat() > 50f && resampleFps < 50f) + resampleFps = 50f; // Force limit framerate as encoding above 50 will cause problems + if (logMode != LogMode.Hidden) Logger.Log((resampleFps <= 0) ? $"Encoding GIF..." : $"Encoding GIF resampled to {resampleFps.ToString().Replace(",", ".")} FPS..."); + string vfrFilename = Path.GetFileName(framesFile); string dither = Config.Get("gifDitherType").Split(' ').First(); string paletteFilter = palette ? $"-vf \"split[s0][s1];[s0]palettegen={colors}[p];[s1][p]paletteuse=dither={dither}\"" : ""; @@ -80,18 +84,5 @@ namespace Flowframes.Media string args = $"-f concat -r {rate} -i {vfrFilename.Wrap()} -f gif {vf} {outPath.Wrap()}"; await RunFfmpeg(args, framesFile.GetParentDir(), LogMode.OnlyLastLine, "error", TaskType.Encode); } - - public static async Task Encode(string inputFile, string vcodec, string acodec, int crf, int audioKbps = 0, bool delSrc = false) - { - string outPath = Path.ChangeExtension(inputFile, null) + "-convert.mp4"; - string args = $" -i {inputFile.Wrap()} -c:v {vcodec} -crf {crf} -pix_fmt yuv420p -c:a {acodec} -b:a {audioKbps}k -vf {GetPadFilter()} {outPath.Wrap()}"; - if (string.IsNullOrWhiteSpace(acodec)) - args = args.Replace("-c:a", "-an"); - if (audioKbps < 0) - args = args.Replace($" -b:a {audioKbps}", ""); - await RunFfmpeg(args, LogMode.OnlyLastLine, TaskType.Encode, true); - if (delSrc) - DeleteSource(inputFile); - } } }