From e750be7196c3667cabbacb809ff711a3c2910044 Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Thu, 21 Jan 2021 09:39:50 +0100 Subject: [PATCH] Removed old unused code --- Code/Main/FrameOrder.cs | 118 +-------------------------------------- Code/Main/Interpolate.cs | 2 +- 2 files changed, 2 insertions(+), 118 deletions(-) diff --git a/Code/Main/FrameOrder.cs b/Code/Main/FrameOrder.cs index 37a4255..0f07f86 100644 --- a/Code/Main/FrameOrder.cs +++ b/Code/Main/FrameOrder.cs @@ -17,7 +17,7 @@ namespace Flowframes.Main public enum Mode { CFR, VFR } public static int timebase = 10000; - public static async Task CreateTimecodeFiles(string framesPath, Mode mode, bool loopEnabled, int times, bool noTimestamps) + public static async Task CreateFrameOrderFile(string framesPath, Mode mode, bool loopEnabled, int times, bool noTimestamps) { Logger.Log("Generating frame order information..."); try @@ -34,122 +34,6 @@ namespace Flowframes.Main } } - public static async Task CreateTimecodeFile(string framesPath, bool loopEnabled, int interpFactor, bool notFirstRun, bool noTimestamps) - { - if (Interpolate.canceled) return; - Logger.Log($"Generating timecodes for {interpFactor}x...", false, true); - - if(noTimestamps) - Logger.Log("Timestamps are disabled, using static frame rate."); - - bool sceneDetection = true; - string ext = InterpolateUtils.GetOutExt(); - - FileInfo[] frameFiles = new DirectoryInfo(framesPath).GetFiles($"*.png"); - string vfrFile = Path.Combine(framesPath.GetParentDir(), $"vfr-{interpFactor}x.ini"); - string fileContent = ""; - - string scnFramesPath = Path.Combine(framesPath.GetParentDir(), Paths.scenesDir); - string interpPath = Paths.interpDir; - - List sceneFrames = new List(); - if (Directory.Exists(scnFramesPath)) - sceneFrames = Directory.GetFiles(scnFramesPath).Select(file => Path.GetFileNameWithoutExtension(file)).ToList(); - - float totalDuration = 0f; - //int totalFrames = 0; - int lastFrameDuration = 1; - - // Calculate time duration between frames - int totalFileCount = 1; - for (int i = 0; i < (frameFiles.Length - 1); i++) - { - if (Interpolate.canceled) return; - - int frameDuration = 100; // Default for no timestamps in input filenames (divided by output fps later) - - if (!noTimestamps) // Get timings from frame filenames - { - string filename1 = frameFiles[i].Name; - string filename2 = frameFiles[i + 1].Name; - frameDuration = Path.GetFileNameWithoutExtension(filename2).GetInt() - Path.GetFileNameWithoutExtension(filename1).GetInt(); - } - - lastFrameDuration = frameDuration; - float durationPerInterpFrame = (float)frameDuration / interpFactor; - - int interpFramesAmount = interpFactor; - - bool discardThisFrame = (sceneDetection && (i + 2) < frameFiles.Length && sceneFrames.Contains(Path.GetFileNameWithoutExtension(frameFiles[i + 1].Name))); // i+2 is in scene detection folder, means i+1 is ugly interp frame - - // If loop is enabled, account for the extra frame added to the end for loop continuity - if (loopEnabled && i == (frameFiles.Length - 2)) - interpFramesAmount = interpFramesAmount * 2; - - //Logger.Log("Writing out frames for in frame " + i, true); - // Generate frames file lines - for (int frm = 0; frm < interpFramesAmount; frm++) - { - //Logger.Log($"Writing out frame {frm+1}/{interpFramesAmount}", true); - - string durationStr = (durationPerInterpFrame / timebase).ToString("0.0000000", CultureInfo.InvariantCulture); - - if (discardThisFrame && totalFileCount > 1) // Never discard 1st frame - { - int lastNum = totalFileCount; - - // Logger.Log($"Writing frame {totalFileCount} [Discarding Next]", true); - fileContent += $"file '{interpPath}/{totalFileCount.ToString().PadLeft(Padding.interpFrames, '0')}.{ext}'\nduration {durationStr}\n"; - totalFileCount++; - totalDuration += durationPerInterpFrame; - - // Logger.Log("Discarding interp frames with out num " + totalFileCount); - for (int dupeCount = 1; dupeCount < interpFramesAmount; dupeCount++) - { - // Logger.Log($"Writing frame {totalFileCount} which is actually repeated frame {lastNum}"); - fileContent += $"file '{interpPath}/{lastNum.ToString().PadLeft(Padding.interpFrames, '0')}.{ext}'\nduration {durationStr}\n"; - totalFileCount++; - totalDuration += durationPerInterpFrame; - } - - frm = interpFramesAmount; - } - else - { - //Logger.Log($"Writing frame {totalFileCount}", true, false); - fileContent += $"file '{interpPath}/{totalFileCount.ToString().PadLeft(Padding.interpFrames, '0')}.{ext}'\nduration {durationStr}\n"; - totalFileCount++; - totalDuration += durationPerInterpFrame; - } - } - - if ((i + 1) % 100 == 0) - await Task.Delay(1); - } - - // Use average frame duration for last frame - TODO: Use real duration?? - string durationStrLast = ((totalDuration / (totalFileCount - 1)) / timebase).ToString("0.0000000", CultureInfo.InvariantCulture); - fileContent += $"file '{interpPath}/{totalFileCount.ToString().PadLeft(Padding.interpFrames, '0')}.{ext}'\nduration {durationStrLast}\n"; - totalFileCount++; - - File.WriteAllText(vfrFile, fileContent); - - if (notFirstRun) return; // Skip all steps that only need to be done once - - if (Config.GetBool("enableLoop")) - { - int lastFileNumber = frameFiles.Last().Name.GetInt(); - lastFileNumber += lastFrameDuration; - string loopFrameTargetPath = Path.Combine(frameFiles.First().FullName.GetParentDir(), lastFileNumber.ToString().PadLeft(Padding.inputFrames, '0') + $".png"); - if (File.Exists(loopFrameTargetPath)) - { - Logger.Log($"Won't copy loop frame - {Path.GetFileName(loopFrameTargetPath)} already exists.", true); - return; - } - File.Copy(frameFiles.First().FullName, loopFrameTargetPath); - } - } - static Dictionary dupesDict = new Dictionary(); static void LoadDupesFile (string path) diff --git a/Code/Main/Interpolate.cs b/Code/Main/Interpolate.cs index 6f829fe..da0ef32 100644 --- a/Code/Main/Interpolate.cs +++ b/Code/Main/Interpolate.cs @@ -137,7 +137,7 @@ namespace Flowframes if(current.alpha) await Converter.ExtractAlpha(current.framesFolder, current.framesFolder + "-a"); - await FrameOrder.CreateTimecodeFiles(current.framesFolder, FrameOrder.Mode.CFR, Config.GetBool("enableLoop"), current.interpFactor, false); + await FrameOrder.CreateFrameOrderFile(current.framesFolder, Config.GetBool("enableLoop"), current.interpFactor); if (canceled) return;