public static async Task InitInput(TextBox outputTbox, TextBox inputTbox, TextBox fpsInTbox) { Program.mainForm.SetTab("interpolate"); Program.mainForm.ResetInputInfo(); string path = inputTbox.Text.Trim(); InterpolateUtils.PathAsciiCheck(path, "input path"); if (Config.GetBool("clearLogOnInput")) { Logger.ClearLogBox(); } outputTbox.Text = inputTbox.Text.Trim().GetParentDir(); Program.lastInputPath = path; Program.lastInputPathIsSsd = OSUtils.DriveIsSSD(path); if (!Program.lastInputPathIsSsd) { Logger.Log("Your file seems to be on an HDD or USB device. It is recommended to interpolate videos on an SSD drive for best performance."); } Logger.Log("Loading metadata..."); Program.mainForm.currInDuration = FfmpegCommands.GetDuration(path); Program.mainForm.currInDurationCut = Program.mainForm.currInDuration; int frameCount = await InterpolateUtils.GetInputFrameCountAsync(path); string fpsStr = "Not Found"; float fps = await IOUtils.GetFpsFolderOrVideo(path); fpsInTbox.Text = fps.ToString(); if (fps > 0) { fpsStr = fps.ToString(); } Logger.Log($"Video FPS: {fpsStr} - Total Number Of Frames: {frameCount}", false, true); Program.mainForm.GetInputFpsTextbox().ReadOnly = fps > 0; Program.mainForm.currInFps = fps; Program.mainForm.currInFrames = frameCount; Program.mainForm.UpdateInputInfo(); CheckExistingFolder(path, outputTbox.Text.Trim()); await Task.Delay(10); await PrintResolution(path); Dedupe.ClearCache(); await Task.Delay(10); InterpolateUtils.SetPreviewImg(await GetThumbnail(path)); }
public static async Task PostProcessFrames(bool stepByStep) { if (canceled) { return; } Program.mainForm.SetStatus("Processing frames..."); int extractedFrames = IoUtils.GetAmountOfFiles(current.framesFolder, false, "*" + current.framesExt); if (!Directory.Exists(current.framesFolder) || currentInputFrameCount <= 0 || extractedFrames < 2) { if (extractedFrames == 1) { Cancel("Only a single frame was extracted from your input file!\n\nPossibly your input is an image, not a video?"); } else { Cancel($"Frame extraction failed!\nExtracted {extractedFrames} frames - current.framesFolder exists: {Directory.Exists(current.framesFolder)} - currentInputFrameCount = {currentInputFrameCount} - extractedFrames = {extractedFrames}.\n\nYour input file might be incompatible."); } } if (Config.GetInt(Config.Key.dedupMode) == 1) { await Dedupe.Run(current.framesFolder); } else { Dedupe.ClearCache(); } if (!Config.GetBool(Config.Key.enableLoop)) { await Utils.CopyLastFrame(currentInputFrameCount); } else { FileInfo[] frameFiles = IoUtils.GetFileInfosSorted(current.framesFolder); string ext = frameFiles.First().Extension; int lastNum = frameFiles.Last().Name.GetInt() + 1; string loopFrameTargetPath = Path.Combine(current.framesFolder, lastNum.ToString().PadLeft(Padding.inputFrames, '0') + ext); File.Copy(frameFiles.First().FullName, loopFrameTargetPath, true); Logger.Log($"Copied loop frame to {loopFrameTargetPath}.", true); } }
public static async Task PostProcessFrames(bool stepByStep) { if (canceled) { return; } int extractedFrames = IOUtils.GetAmountOfFiles(current.framesFolder, false, "*.png"); if (!Directory.Exists(current.framesFolder) || currentInputFrameCount <= 0 || extractedFrames < 2) { if (extractedFrames == 1) { Cancel("Only a single frame was extracted from your input file!\n\nPossibly your input is an image, not a video?"); } else { Cancel("Frame extraction failed!\n\nYour input file might be incompatible."); } } if (Config.GetInt("dedupMode") == 1) { await Dedupe.Run(current.framesFolder); } else { Dedupe.ClearCache(); } if (!Config.GetBool("enableLoop")) { await Utils.CopyLastFrame(currentInputFrameCount); } if (Config.GetInt("dedupMode") > 0) { await Dedupe.CreateDupesFile(current.framesFolder, currentInputFrameCount); } if (canceled) { return; } await FrameOrder.CreateFrameOrderFile(current.framesFolder, Config.GetBool("enableLoop"), current.interpFactor); if (canceled) { return; } try { Dictionary <string, string> renamedFilesDict = await IOUtils.RenameCounterDirReversibleAsync(current.framesFolder, "png", 1, Padding.inputFramesRenamed); if (stepByStep) { AiProcess.filenameMap = renamedFilesDict.ToDictionary(x => Path.GetFileName(x.Key), x => Path.GetFileName(x.Value)); // Save rel paths } } catch (Exception e) { Logger.Log($"Error renaming frame files: {e.Message}"); Cancel("Error renaming frame files. Check the log for details."); } if (current.alpha) { Program.mainForm.SetStatus("Extracting transparency..."); Logger.Log("Extracting transparency... (1/2)"); await FfmpegAlpha.ExtractAlphaDir(current.framesFolder, current.framesFolder + Paths.alphaSuffix); Logger.Log("Extracting transparency... (2/2)", false, true); await FfmpegAlpha.RemoveAlpha(current.framesFolder, current.framesFolder); } }
public static async Task InitInput(TextBox outputTbox, TextBox inputTbox, TextBox fpsInTbox, bool start = false) { Program.mainForm.SetTab("interpolate"); Program.mainForm.ResetInputInfo(); string path = inputTbox.Text.Trim(); GetFrameCountCached.Clear(); GetMediaResolutionCached.Clear(); if (Config.GetBool(Config.Key.clearLogOnInput)) { Logger.ClearLogBox(); } SetOutPath(outputTbox, inputTbox.Text.Trim().GetParentDir()); Program.lastInputPath = path; Program.lastInputPathIsSsd = OsUtils.DriveIsSSD(path); if (!Program.lastInputPathIsSsd) { Logger.Log("Your file seems to be on an HDD or USB device. It is recommended to interpolate videos on an SSD drive for best performance."); } Logger.Log("Loading metadata..."); Program.mainForm.currInDuration = FfmpegCommands.GetDuration(path); Program.mainForm.currInDurationCut = Program.mainForm.currInDuration; int frameCount = await GetFrameCountCached.GetFrameCountAsync(path); string fpsStr = "Not Found"; Fraction fps = (await IoUtils.GetFpsFolderOrVideo(path)); Program.mainForm.currInFpsDetected = fps; fpsInTbox.Text = fps.GetString(); if (fps.GetFloat() > 0) { fpsStr = $"{fps} (~{fps.GetFloat()})"; } Logger.Log($"Video FPS: {fpsStr} - Total Number Of Frames: {frameCount}", false, true); Program.mainForm.GetInputFpsTextbox().ReadOnly = (fps.GetFloat() > 0 && !Config.GetBool("allowCustomInputRate", false)); Program.mainForm.currInFps = fps; Program.mainForm.currInFrames = frameCount; Program.mainForm.UpdateInputInfo(); CheckExistingFolder(path, outputTbox.Text.Trim()); await Task.Delay(10); await PrintResolution(path); Dedupe.ClearCache(); await Task.Delay(10); InterpolationProgress.SetPreviewImg(await GetThumbnail(path)); if (AutoEncodeResume.resumeNextRun) { Logger.Log($"Incomplete interpolation detected. Flowframes will resume the interpolation."); } if (start) { Program.mainForm.runBtn_Click(null, null); } }