From 9f251cde54472b2381813effbd00da56d79081ba Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Wed, 23 Dec 2020 17:15:42 +0100 Subject: [PATCH] Fixed AutoEncode with non-MP4 output formats --- Code/Data/InterpSettings.cs | 2 +- Code/Main/AutoEncode.cs | 5 +++-- Code/Main/CreateVideo.cs | 6 ++---- Code/Main/Interpolate.cs | 3 ++- Code/Main/InterpolateSteps.cs | 5 +++-- Code/Main/InterpolateUtils.cs | 9 --------- Code/UI/FormatUtils.cs | 2 +- 7 files changed, 12 insertions(+), 20 deletions(-) diff --git a/Code/Data/InterpSettings.cs b/Code/Data/InterpSettings.cs index c053c0d..8c5c8e9 100644 --- a/Code/Data/InterpSettings.cs +++ b/Code/Data/InterpSettings.cs @@ -69,7 +69,7 @@ namespace Flowframes framesFolder = Path.Combine(tempFolder, Paths.framesDir); interpFolder = Path.Combine(tempFolder, Paths.interpDir); inputIsFrames = IOUtils.IsPathDirectory(inPath); - outFilename = Path.Combine(outPath, Path.GetFileNameWithoutExtension(inPath) + IOUtils.GetAiSuffix(ai, interpFactor) + InterpolateUtils.GetExt(outMode)); + outFilename = Path.Combine(outPath, Path.GetFileNameWithoutExtension(inPath) + IOUtils.GetAiSuffix(ai, interpFactor) + FFmpegUtils.GetExt(outMode)); } public Size GetInputRes () diff --git a/Code/Main/AutoEncode.cs b/Code/Main/AutoEncode.cs index 044f8d2..cb732a4 100644 --- a/Code/Main/AutoEncode.cs +++ b/Code/Main/AutoEncode.cs @@ -1,4 +1,5 @@ -using Flowframes.Data; +using Flowframes.AudioVideo; +using Flowframes.Data; using Flowframes.IO; using System; using System.Collections.Generic; @@ -67,7 +68,7 @@ namespace Flowframes.Main IOUtils.ZeroPadDir(framesToEncode, Padding.interpFrames); // Zero-pad frames before encoding to make sure filenames match with VFR file - string outpath = Path.Combine(videoChunksFolder, $"{videoIndex.ToString().PadLeft(4, '0')}{InterpolateUtils.GetExt(Interpolate.current.outMode)}"); + string outpath = Path.Combine(videoChunksFolder, $"{videoIndex.ToString().PadLeft(4, '0')}{FFmpegUtils.GetExt(Interpolate.current.outMode)}"); int firstFrameNum = Path.GetFileNameWithoutExtension(framesToEncode[0]).GetInt(); await CreateVideo.EncodeChunk(outpath, Interpolate.current.outMode, firstFrameNum - 1, framesToEncode.Count); diff --git a/Code/Main/CreateVideo.cs b/Code/Main/CreateVideo.cs index 4c628c8..edf8b69 100644 --- a/Code/Main/CreateVideo.cs +++ b/Code/Main/CreateVideo.cs @@ -14,6 +14,7 @@ using System.Windows.Forms; using Padding = Flowframes.Data.Padding; using i = Flowframes.Interpolate; using System.Diagnostics; +using Flowframes.AudioVideo; namespace Flowframes.Main { @@ -130,7 +131,7 @@ namespace Flowframes.Main public static async Task ChunksToVideo(string chunksPath, string vfrFile, string outPath) { - if (IOUtils.GetAmountOfFiles(chunksPath, false, "*.mp4") < 1) + if (IOUtils.GetAmountOfFiles(chunksPath, false, $"*{FFmpegUtils.GetExt(i.current.outMode)}") < 1) { i.Cancel("No video chunks found - An error must have occured during chunk encoding!", AiProcess.hasShownError); return; @@ -180,9 +181,6 @@ namespace Flowframes.Main public static async Task EncodeChunk(string outPath, i.OutMode mode, int firstFrameNum, int framesAmount) { - bool h265 = Config.GetInt("mp4Enc") == 1; - int crf = h265 ? Config.GetInt("h265Crf") : Config.GetInt("h264Crf"); - string vfrFileOriginal = Path.Combine(i.current.tempFolder, $"vfr-{i.current.interpFactor}x.ini"); string vfrFile = Path.Combine(i.current.tempFolder, $"vfr-chunk-{firstFrameNum}-{firstFrameNum + framesAmount}.ini"); File.WriteAllLines(vfrFile, IOUtils.ReadLines(vfrFileOriginal).Skip(firstFrameNum * 2).Take(framesAmount * 2)); diff --git a/Code/Main/Interpolate.cs b/Code/Main/Interpolate.cs index b7a911e..1b2e651 100644 --- a/Code/Main/Interpolate.cs +++ b/Code/Main/Interpolate.cs @@ -133,8 +133,9 @@ namespace Flowframes public static async Task RunAi(string outpath, int targetFrames, int tilesize, AI ai, bool stepByStep = false) { + bool vidMode = current.outMode.ToString().ToLower().Contains("vid"); if ((stepByStep && Config.GetBool("sbsAllowAutoEnc")) || (!stepByStep && Config.GetInt("autoEncMode") > 0)) - currentlyUsingAutoEnc = current.outMode == OutMode.VidMp4 && IOUtils.GetAmountOfFiles(current.framesFolder, false) * current.interpFactor >= (AutoEncode.chunkSize + AutoEncode.safetyBufferFrames) * 1.1f; + currentlyUsingAutoEnc = vidMode && IOUtils.GetAmountOfFiles(current.framesFolder, false) * current.interpFactor >= (AutoEncode.chunkSize + AutoEncode.safetyBufferFrames) * 1.1f; else currentlyUsingAutoEnc = false; diff --git a/Code/Main/InterpolateSteps.cs b/Code/Main/InterpolateSteps.cs index 80f1901..609e2ad 100644 --- a/Code/Main/InterpolateSteps.cs +++ b/Code/Main/InterpolateSteps.cs @@ -1,4 +1,5 @@ -using Flowframes.Data; +using Flowframes.AudioVideo; +using Flowframes.Data; using Flowframes.IO; using System; using System.Collections.Generic; @@ -149,7 +150,7 @@ namespace Flowframes.Main return; } - string outPath = Path.Combine(current.outPath, Path.GetFileNameWithoutExtension(current.inPath) + IOUtils.GetAiSuffix(current.ai, current.interpFactor) + InterpolateUtils.GetExt(current.outMode)); + string outPath = Path.Combine(current.outPath, Path.GetFileNameWithoutExtension(current.inPath) + IOUtils.GetAiSuffix(current.ai, current.interpFactor) + FFmpegUtils.GetExt(current.outMode)); await CreateVideo.Export(current.interpFolder, outPath, current.outMode); } diff --git a/Code/Main/InterpolateUtils.cs b/Code/Main/InterpolateUtils.cs index b175adf..1047674 100644 --- a/Code/Main/InterpolateUtils.cs +++ b/Code/Main/InterpolateUtils.cs @@ -270,15 +270,6 @@ namespace Flowframes.Main return true; } - public static string GetExt(i.OutMode format) - { - if (format == i.OutMode.VidMp4) - return ".mp4"; - if (format == i.OutMode.VidGif) - return ".gif"; - return ".mp4"; - } - public static void ShowMessage(string msg, string title = "Message") { if (!BatchProcessing.busy) diff --git a/Code/UI/FormatUtils.cs b/Code/UI/FormatUtils.cs index 4b34b21..e8afe2f 100644 --- a/Code/UI/FormatUtils.cs +++ b/Code/UI/FormatUtils.cs @@ -43,7 +43,7 @@ namespace Flowframes.UI return span.ToString(@"mm\:ss"); if (span.TotalSeconds >= 1f || !allowMs) - return span.ToString(@"ss") + "s"; + return span.ToString(@"ss".TrimStart('0').PadLeft(1, '0')) + "s"; return span.ToString(@"fff").TrimStart('0').PadLeft(1, '0') + "ms"; }