mirror of
https://github.com/n00mkrad/flowframes.git
synced 2026-09-01 19:51:28 +02:00
Resuming WIP
This commit is contained in:
@@ -11,7 +11,9 @@ namespace Flowframes.IO
|
||||
public const string chunksDir = "vchunks";
|
||||
public const string resumeDir = "resumedata";
|
||||
public const string scenesDir = "scenes";
|
||||
|
||||
public const string alphaSuffix = "-a";
|
||||
public const string prevSuffix = "-previous";
|
||||
|
||||
public static string GetVerPath()
|
||||
{
|
||||
|
||||
@@ -8,13 +8,37 @@ namespace Flowframes.Data
|
||||
{
|
||||
public struct ResumeState
|
||||
{
|
||||
bool autoEncode;
|
||||
int lastInterpolatedInputFrame;
|
||||
public bool autoEncode;
|
||||
public int interpolatedInputFrames;
|
||||
|
||||
public ResumeState (bool autoEncArg, int lastInterpInFrameArg)
|
||||
{
|
||||
autoEncode = autoEncArg;
|
||||
lastInterpolatedInputFrame = lastInterpInFrameArg;
|
||||
interpolatedInputFrames = lastInterpInFrameArg;
|
||||
}
|
||||
|
||||
public ResumeState(string serializedData)
|
||||
{
|
||||
autoEncode = false;
|
||||
interpolatedInputFrames = 0;
|
||||
|
||||
Dictionary<string, string> entries = new Dictionary<string, string>();
|
||||
|
||||
foreach (string line in serializedData.SplitIntoLines())
|
||||
{
|
||||
if (line.Length < 3) continue;
|
||||
string[] keyValuePair = line.Split('|');
|
||||
entries.Add(keyValuePair[0], keyValuePair[1]);
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<string, string> entry in entries)
|
||||
{
|
||||
switch (entry.Key)
|
||||
{
|
||||
case "AUTOENC": autoEncode = bool.Parse(entry.Value); break;
|
||||
case "INTERPOLATEDINPUTFRAMES": interpolatedInputFrames = entry.Value.GetInt(); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
@@ -23,7 +47,7 @@ namespace Flowframes.Data
|
||||
|
||||
if (!autoEncode)
|
||||
{
|
||||
s += $"LASTINPUTFRAME|{lastInterpolatedInputFrame}";
|
||||
s += $"INTERPOLATEDINPUTFRAMES|{interpolatedInputFrames}";
|
||||
}
|
||||
|
||||
return s;
|
||||
|
||||
@@ -339,7 +339,10 @@ namespace Flowframes
|
||||
Logger.Log("Selected video/directory: " + Path.GetFileName(files[0]));
|
||||
inputTbox.Text = files[0];
|
||||
|
||||
if (IOUtils.GetAmountOfFiles(Path.Combine(files[0], Paths.resumeDir), true) > 0)
|
||||
bool resume = (IOUtils.GetAmountOfFiles(Path.Combine(files[0], Paths.resumeDir), true) > 0);
|
||||
ResumeUtils.resumeNextRun = resume;
|
||||
|
||||
if (resume)
|
||||
ResumeUtils.LoadTempFolder(files[0]);
|
||||
|
||||
MainUiFunctions.InitInput(outputTbox, inputTbox, fpsInTbox);
|
||||
|
||||
@@ -36,19 +36,25 @@ namespace Flowframes
|
||||
canceled = false;
|
||||
if (!Utils.InputIsValid(current.inPath, current.outPath, current.outFps, current.interpFactor, current.outMode)) return; // General input checks
|
||||
if (!Utils.CheckAiAvailable(current.ai)) return; // Check if selected AI pkg is installed
|
||||
if (!Utils.CheckDeleteOldTempFolder()) return; // Try to delete temp folder if an old one exists
|
||||
if (!ResumeUtils.resumeNextRun && !Utils.CheckDeleteOldTempFolder()) return; // Try to delete temp folder if an old one exists
|
||||
if (!Utils.CheckPathValid(current.inPath)) return; // Check if input path/file is valid
|
||||
Utils.PathAsciiCheck(current.outPath, "output path");
|
||||
currentInputFrameCount = await Utils.GetInputFrameCountAsync(current.inPath);
|
||||
current.stepByStep = false;
|
||||
Program.mainForm.SetStatus("Starting...");
|
||||
Program.mainForm.SetWorking(true);
|
||||
await GetFrames();
|
||||
|
||||
if (!ResumeUtils.resumeNextRun)
|
||||
{
|
||||
await GetFrames();
|
||||
if (canceled) return;
|
||||
sw.Restart();
|
||||
await PostProcessFrames();
|
||||
}
|
||||
|
||||
if (canceled) return;
|
||||
sw.Restart();
|
||||
await PostProcessFrames();
|
||||
if (canceled) return;
|
||||
Task.Run(() => Utils.DeleteInterpolatedInputFrames());
|
||||
await ResumeUtils.PrepareResumedRun();
|
||||
//Task.Run(() => Utils.DeleteInterpolatedInputFrames());
|
||||
await RunAi(current.interpFolder, current.ai);
|
||||
if (canceled) return;
|
||||
Program.mainForm.SetProgress(100);
|
||||
@@ -90,6 +96,7 @@ namespace Flowframes
|
||||
await Task.Delay(10);
|
||||
}
|
||||
|
||||
if (canceled) return;
|
||||
Program.mainForm.SetStatus("Extracting frames from video...");
|
||||
bool mpdecimate = Config.GetInt("dedupMode") == 2;
|
||||
await FfmpegExtract.VideoToFrames(inPath, outPath, alpha, current.inFps, mpdecimate, false, await Utils.GetOutputResolution(inPath, true, true), false);
|
||||
@@ -106,6 +113,8 @@ namespace Flowframes
|
||||
if(!Config.GetBool("allowConsecutiveSceneChanges", true))
|
||||
Utils.FixConsecutiveSceneFrames(Path.Combine(current.tempFolder, Paths.scenesDir), current.framesFolder);
|
||||
|
||||
if (canceled) return;
|
||||
|
||||
if (extractAudio)
|
||||
{
|
||||
string audioFile = Path.Combine(current.tempFolder, "audio");
|
||||
@@ -113,6 +122,8 @@ namespace Flowframes
|
||||
await FfmpegAudioAndMetadata.ExtractAudio(inPath, audioFile);
|
||||
}
|
||||
|
||||
if (canceled) return;
|
||||
|
||||
await FfmpegAudioAndMetadata.ExtractSubtitles(inPath, current.tempFolder, current.outMode);
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ namespace Flowframes.Main
|
||||
|
||||
for (int i = 0; i < inputFrames.Length; i++)
|
||||
{
|
||||
while (Program.busy && (i + 20) > interpolatedInputFramesCount) await Task.Delay(1000);
|
||||
while (Program.busy && (i + 10) > interpolatedInputFramesCount) await Task.Delay(1000);
|
||||
if (!Program.busy) break;
|
||||
if(i != 0 && i != inputFrames.Length - 1)
|
||||
IOUtils.OverwriteFileWithText(inputFrames[i]);
|
||||
|
||||
@@ -13,6 +13,8 @@ namespace Flowframes.Main
|
||||
|
||||
class ResumeUtils
|
||||
{
|
||||
public static bool resumeNextRun;
|
||||
|
||||
public static float timeBetweenSaves = 10;
|
||||
public static int minFrames = 100;
|
||||
public static int safetyDelayFrames = 50;
|
||||
@@ -63,8 +65,8 @@ namespace Flowframes.Main
|
||||
|
||||
static void SaveInterpSettings ()
|
||||
{
|
||||
string filePath = Path.Combine(Interpolate.current.tempFolder, Paths.resumeDir, interpSettingsFilename);
|
||||
File.WriteAllText(filePath, Interpolate.current.Serialize());
|
||||
string filepath = Path.Combine(Interpolate.current.tempFolder, Paths.resumeDir, interpSettingsFilename);
|
||||
File.WriteAllText(filepath, Interpolate.current.Serialize());
|
||||
}
|
||||
|
||||
public static void LoadTempFolder (string tempFolderPath)
|
||||
@@ -75,6 +77,22 @@ namespace Flowframes.Main
|
||||
Program.mainForm.LoadBatchEntry(interpSettings);
|
||||
}
|
||||
|
||||
public static async Task PrepareResumedRun ()
|
||||
{
|
||||
if (!resumeNextRun) return;
|
||||
|
||||
string stateFilepath = Path.Combine(Interpolate.current.tempFolder, Paths.resumeDir, resumeFilename);
|
||||
ResumeState state = new ResumeState(File.ReadAllText(stateFilepath));
|
||||
|
||||
string[] inputFrames = IOUtils.GetFilesSorted(Interpolate.current.framesFolder);
|
||||
|
||||
for (int i = 0; i < state.interpolatedInputFrames; i++)
|
||||
{
|
||||
IOUtils.TryDeleteIfExists(inputFrames[i]);
|
||||
if (i % 100 == 0) await Task.Delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
static void LoadFilenameMap()
|
||||
{
|
||||
Dictionary<string, string> dict = new Dictionary<string, string>();
|
||||
|
||||
Reference in New Issue
Block a user