From df769804f179dace09bb4764b47f99ab9e2d78cf Mon Sep 17 00:00:00 2001 From: n00mkrad Date: Tue, 31 Aug 2021 00:47:06 +0200 Subject: [PATCH] Avoid making ".old" folders for each new img seq chunk --- Code/Main/AutoEncode.cs | 12 ++++++------ Code/Main/CreateVideo.cs | 5 ++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Code/Main/AutoEncode.cs b/Code/Main/AutoEncode.cs index d33c366..6239ce2 100644 --- a/Code/Main/AutoEncode.cs +++ b/Code/Main/AutoEncode.cs @@ -62,7 +62,7 @@ namespace Flowframes.Main unencodedFrameLines.Clear(); Logger.Log($"[AE] Starting AutoEncode MainLoop - Chunk Size: {chunkSize} Frames - Safety Buffer: {safetyBufferFrames} Frames", true); - int chunkIndex = 1; + int chunkNo = 1; string encFile = Path.Combine(interpFramesPath.GetParentDir(), Paths.GetFrameOrderFilename(Interpolate.current.interpFactor)); interpFramesLines = IoUtils.ReadLines(encFile).Select(x => x.Split('/').Last().Remove("'").Split('#').First()).ToArray(); // Array with frame filenames @@ -127,12 +127,12 @@ namespace Flowframes.Main } busy = true; - string outpath = Path.Combine(videoChunksFolder, "chunks", $"{chunkIndex.ToString().PadLeft(4, '0')}{FfmpegUtils.GetExt(Interpolate.current.outMode)}"); + string outpath = Path.Combine(videoChunksFolder, "chunks", $"{chunkNo.ToString().PadLeft(4, '0')}{FfmpegUtils.GetExt(Interpolate.current.outMode)}"); string firstFile = Path.GetFileName(interpFramesLines[frameLinesToEncode.First()].Trim()); string lastFile = Path.GetFileName(interpFramesLines[frameLinesToEncode.Last()].Trim()); - Logger.Log($"[AE] Encoding Chunk #{chunkIndex} to using line {frameLinesToEncode.First()} ({firstFile}) through {frameLinesToEncode.Last()} ({lastFile})", true, false, "ffmpeg"); + Logger.Log($"[AE] Encoding Chunk #{chunkNo} to using line {frameLinesToEncode.First()} ({firstFile}) through {frameLinesToEncode.Last()} ({lastFile})", true, false, "ffmpeg"); - await CreateVideo.EncodeChunk(outpath, Interpolate.current.interpFolder, Interpolate.current.outMode, frameLinesToEncode.First(), frameLinesToEncode.Count); + await CreateVideo.EncodeChunk(outpath, Interpolate.current.interpFolder, chunkNo, Interpolate.current.outMode, frameLinesToEncode.First(), frameLinesToEncode.Count); if (Interpolate.canceled) return; @@ -143,10 +143,10 @@ namespace Flowframes.Main encodedFrameLines.AddRange(frameLinesToEncode); - Logger.Log("[AE] Done Encoding Chunk #" + chunkIndex, true, false, "ffmpeg"); + Logger.Log("[AE] Done Encoding Chunk #" + chunkNo, true, false, "ffmpeg"); lastEncodedFrameNum = (frameLinesToEncode.Last() + 1); - chunkIndex++; + chunkNo++; if(!imgSeq && Config.GetInt(Config.Key.autoEncBackupMode) > 0) { diff --git a/Code/Main/CreateVideo.cs b/Code/Main/CreateVideo.cs index df0945b..49274b2 100644 --- a/Code/Main/CreateVideo.cs +++ b/Code/Main/CreateVideo.cs @@ -221,7 +221,7 @@ namespace Flowframes.Main await Loop(outPath, await GetLoopTimes()); } - public static async Task EncodeChunk(string outPath, string interpDir, I.OutMode mode, int firstFrameNum, int framesAmount) + public static async Task EncodeChunk(string outPath, string interpDir, int chunkNo, I.OutMode mode, int firstFrameNum, int framesAmount) { string framesFileFull = Path.Combine(I.current.tempFolder, Paths.GetFrameOrderFilename(I.current.interpFactor)); string framesFileChunk = Path.Combine(I.current.tempFolder, Paths.GetFrameOrderFilenameChunk(firstFrameNum, firstFrameNum + framesAmount)); @@ -249,6 +249,9 @@ namespace Flowframes.Main string outputFolderPath = Path.Combine(I.current.outPath, await IoUtils.GetCurrentExportFilename(false, false)); int startNumber = IoUtils.GetAmountOfFiles(outputFolderPath, false) + 1; + if(chunkNo == 1) // Only check for existing folder on first chunk, otherwise each chunk makes a new folder + IoUtils.RenameExistingFolder(outputFolderPath); + if (desiredFormat.ToUpper() == availableFormat.ToUpper()) // Move if frames are already in the desired format await CopyOutputFrames(interpDir, framesFileChunk, outputFolderPath, fpsLimit); else // Encode if frames are not in desired format