2021-02-02 12:56:48 +01:00
|
|
|
|
using Flowframes.Media;
|
2020-11-29 16:10:31 +01:00
|
|
|
|
using Flowframes.IO;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2021-04-04 11:05:38 +02:00
|
|
|
|
using Flowframes.MiscUtils;
|
2021-05-07 23:06:43 +02:00
|
|
|
|
using System.Windows.Forms;
|
2020-11-29 16:10:31 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Flowframes.Main
|
|
|
|
|
|
{
|
|
|
|
|
|
using static Interpolate;
|
|
|
|
|
|
|
|
|
|
|
|
class InterpolateSteps
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public static async Task Run(string step)
|
|
|
|
|
|
{
|
2021-01-05 23:13:29 +01:00
|
|
|
|
Logger.Log($"[SBS] Running step '{step}'", true);
|
2020-11-29 16:10:31 +01:00
|
|
|
|
canceled = false;
|
|
|
|
|
|
Program.mainForm.SetWorking(true);
|
2021-05-07 23:06:43 +02:00
|
|
|
|
|
|
|
|
|
|
if(current == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Logger.Log($"[SBS] Getting new current settings", true);
|
|
|
|
|
|
current = Program.mainForm.GetCurrentSettings();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Logger.Log($"[SBS] Updating current settings", true);
|
|
|
|
|
|
current = Program.mainForm.UpdateCurrentSettings(current);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-26 20:46:05 +01:00
|
|
|
|
current.RefreshAlpha();
|
2021-02-10 23:16:04 +01:00
|
|
|
|
current.stepByStep = true;
|
2020-11-29 16:10:31 +01:00
|
|
|
|
|
2021-01-13 23:05:23 +01:00
|
|
|
|
if (!InterpolateUtils.InputIsValid(current.inPath, current.outPath, current.outFps, current.interpFactor, current.outMode)) return; // General input checks
|
2021-02-21 21:18:31 +01:00
|
|
|
|
if (!InterpolateUtils.CheckPathValid(current.inPath)) return; // Check if input path/file is valid
|
2020-12-02 14:36:41 +01:00
|
|
|
|
|
2020-12-02 23:53:27 +01:00
|
|
|
|
if (step.Contains("Extract Frames"))
|
2021-01-26 16:45:02 +01:00
|
|
|
|
await ExtractFramesStep();
|
2020-12-02 14:36:41 +01:00
|
|
|
|
|
2020-11-29 16:10:31 +01:00
|
|
|
|
if (step.Contains("Run Interpolation"))
|
|
|
|
|
|
await DoInterpolate();
|
2020-12-02 14:36:41 +01:00
|
|
|
|
|
2020-12-02 23:53:27 +01:00
|
|
|
|
if (step.Contains("Export"))
|
2020-11-29 16:10:31 +01:00
|
|
|
|
await CreateOutputVid();
|
2020-12-02 14:36:41 +01:00
|
|
|
|
|
2020-11-29 16:10:31 +01:00
|
|
|
|
if (step.Contains("Cleanup"))
|
|
|
|
|
|
await Reset();
|
|
|
|
|
|
|
|
|
|
|
|
Program.mainForm.SetWorking(false);
|
2021-01-27 21:14:55 +01:00
|
|
|
|
Program.mainForm.SetStatus("Done running step.");
|
2020-11-29 16:10:31 +01:00
|
|
|
|
Logger.Log("Done running this step.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-26 16:45:02 +01:00
|
|
|
|
public static async Task ExtractFramesStep()
|
2020-11-29 16:10:31 +01:00
|
|
|
|
{
|
2021-03-10 20:45:48 +01:00
|
|
|
|
// if (Config.GetBool("scnDetect") && !current.inputIsFrames) // Input is video - extract frames first
|
|
|
|
|
|
// await ExtractSceneChanges();
|
2021-02-21 12:39:25 +01:00
|
|
|
|
|
2020-12-17 11:32:45 +01:00
|
|
|
|
if (!IOUtils.TryDeleteIfExists(current.framesFolder))
|
2020-12-02 00:44:43 +01:00
|
|
|
|
{
|
|
|
|
|
|
InterpolateUtils.ShowMessage("Failed to delete existing frames folder - Make sure no file is opened in another program!", "Error");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2020-12-15 14:46:33 +01:00
|
|
|
|
|
2021-04-18 18:11:47 +02:00
|
|
|
|
currentInputFrameCount = await GetFrameCountCached.GetFrameCountAsync(current.inPath);
|
2020-12-15 14:46:33 +01:00
|
|
|
|
|
2021-03-10 20:45:48 +01:00
|
|
|
|
await GetFrames();
|
2021-02-21 12:39:25 +01:00
|
|
|
|
await PostProcessFrames(true);
|
2020-11-29 16:10:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-02 23:11:27 +01:00
|
|
|
|
public static async Task DoInterpolate()
|
2020-11-29 16:10:31 +01:00
|
|
|
|
{
|
2021-02-21 21:18:31 +01:00
|
|
|
|
if (!InterpolateUtils.CheckAiAvailable(current.ai)) return;
|
|
|
|
|
|
|
2020-12-17 11:32:45 +01:00
|
|
|
|
current.framesFolder = Path.Combine(current.tempFolder, Paths.framesDir);
|
2021-01-26 20:46:05 +01:00
|
|
|
|
|
2021-05-07 23:06:43 +02:00
|
|
|
|
if (IOUtils.GetAmountOfFiles(current.framesFolder, false, "*") < 2)
|
2020-12-02 00:44:43 +01:00
|
|
|
|
{
|
|
|
|
|
|
InterpolateUtils.ShowMessage("There are no extracted frames that can be interpolated!\nDid you run the extraction step?", "Error");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2020-12-17 11:32:45 +01:00
|
|
|
|
if (!IOUtils.TryDeleteIfExists(current.interpFolder))
|
2020-12-02 00:44:43 +01:00
|
|
|
|
{
|
|
|
|
|
|
InterpolateUtils.ShowMessage("Failed to delete existing frames folder - Make sure no file is opened in another program!", "Error");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-18 18:11:47 +02:00
|
|
|
|
currentInputFrameCount = await GetFrameCountCached.GetFrameCountAsync(current.inPath);
|
2020-12-07 00:41:07 +01:00
|
|
|
|
|
2021-02-21 21:18:31 +01:00
|
|
|
|
if (Config.GetBool("sbsAllowAutoEnc") && !(await InterpolateUtils.CheckEncoderValid())) return;
|
|
|
|
|
|
|
2020-11-29 16:10:31 +01:00
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
Program.mainForm.SetStatus("Running AI...");
|
2021-01-14 12:06:55 +01:00
|
|
|
|
await RunAi(current.interpFolder, current.ai, true);
|
2021-04-04 11:05:38 +02:00
|
|
|
|
await FrameRename.Unrename(); // Get timestamps back
|
2020-11-29 16:10:31 +01:00
|
|
|
|
Program.mainForm.SetProgress(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-02 23:11:27 +01:00
|
|
|
|
public static async Task CreateOutputVid()
|
2020-11-29 16:10:31 +01:00
|
|
|
|
{
|
2021-04-04 15:51:43 +02:00
|
|
|
|
if (IOUtils.GetAmountOfFiles(current.interpFolder, false) < 2)
|
2021-02-08 21:24:28 +01:00
|
|
|
|
{
|
|
|
|
|
|
Cancel($"There are no interpolated frames to encode!\n\nDid you delete the folder?");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-21 21:18:31 +01:00
|
|
|
|
if (!(await InterpolateUtils.CheckEncoderValid())) return;
|
|
|
|
|
|
|
2021-04-22 16:15:17 +02:00
|
|
|
|
string[] outFrames = IOUtils.GetFilesSorted(current.interpFolder, current.interpExt);
|
2021-01-27 21:14:55 +01:00
|
|
|
|
|
2020-12-07 12:34:12 +01:00
|
|
|
|
if (outFrames.Length > 0 && !IOUtils.CheckImageValid(outFrames[0]))
|
|
|
|
|
|
{
|
|
|
|
|
|
InterpolateUtils.ShowMessage("Invalid frame files detected!\n\nIf you used Auto-Encode, this is normal, and you don't need to run " +
|
|
|
|
|
|
"this step as the video was already created in the \"Interpolate\" step.", "Error");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-09 15:55:50 +01:00
|
|
|
|
await CreateVideo.Export(current.interpFolder, current.outPath, current.outMode, true);
|
2020-11-29 16:10:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-02 23:11:27 +01:00
|
|
|
|
public static async Task Reset()
|
2020-11-29 16:10:31 +01:00
|
|
|
|
{
|
2021-05-07 23:06:43 +02:00
|
|
|
|
DialogResult dialog = MessageBox.Show($"Are you sure you want to remove all temporary files?", "Are you sure?", MessageBoxButtons.YesNo);
|
|
|
|
|
|
|
|
|
|
|
|
if (dialog == DialogResult.Yes)
|
|
|
|
|
|
await Cleanup(true);
|
2020-11-29 16:10:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|