mirror of
https://github.com/n00mkrad/flowframes.git
synced 2026-07-13 22:09:40 +02:00
Fixed step-by-step frame renaming & added SBS scene blending support
This commit is contained in:
@@ -36,6 +36,14 @@ namespace Flowframes.Magick
|
||||
if (setStatus)
|
||||
Program.mainForm.SetStatus("Blending scene transitions...");
|
||||
|
||||
bool renameFramesFirst = !AiProcess.framesAreRenamed;
|
||||
|
||||
if (renameFramesFirst)
|
||||
{
|
||||
Dictionary<string, string> renamedFilesDict = await IOUtils.RenameCounterDirReversibleAsync(Interpolate.current.framesFolder, "png", 1, Padding.inputFramesRenamed);
|
||||
AiProcess.SetFilenameMap(renamedFilesDict.ToDictionary(x => Path.GetFileName(x.Key), x => Path.GetFileName(x.Value)), true);
|
||||
}
|
||||
|
||||
int amountOfBlendFrames = (int)Interpolate.current.interpFactor - 1;
|
||||
|
||||
List<Task> runningTasks = new List<Task>();
|
||||
@@ -52,12 +60,12 @@ namespace Flowframes.Magick
|
||||
string[] inputFrameNames = trimmedLine.Split('>');
|
||||
string img1 = Path.Combine(Interpolate.current.framesFolder, inputFrameNames[0]);
|
||||
string img2 = Path.Combine(Interpolate.current.framesFolder, inputFrameNames[1]);
|
||||
|
||||
|
||||
string firstOutputFrameName = line.Split('/').Last().Remove("'").Split('#').First();
|
||||
string ext = Path.GetExtension(firstOutputFrameName);
|
||||
int firstOutputFrameNum = firstOutputFrameName.GetInt();
|
||||
List<string> outputFilenames = new List<string>();
|
||||
|
||||
|
||||
for (int blendFrameNum = 1; blendFrameNum <= amountOfBlendFrames; blendFrameNum++)
|
||||
{
|
||||
int outputNum = firstOutputFrameNum + blendFrameNum;
|
||||
@@ -79,7 +87,7 @@ namespace Flowframes.Magick
|
||||
Task newTask = Task.Run(() => BlendImages(img1, img2, outputFilenames.ToArray()));
|
||||
runningTasks.Add(newTask);
|
||||
totalFrames += outputFilenames.Count;
|
||||
|
||||
|
||||
await Task.Delay(1);
|
||||
}
|
||||
}
|
||||
@@ -101,11 +109,17 @@ namespace Flowframes.Magick
|
||||
|
||||
Logger.Log($"Created {totalFrames} blend frames in {FormatUtils.TimeSw(sw)} ({(totalFrames / (sw.ElapsedMilliseconds / 1000f)).ToString("0.00")} FPS)", true);
|
||||
|
||||
if (renameFramesFirst)
|
||||
{
|
||||
await IOUtils.ReverseRenaming(Interpolate.current.framesFolder, AiProcess.filenameMap); // Get timestamps back
|
||||
AiProcess.SetFilenameMap(null, false);
|
||||
}
|
||||
|
||||
if (setStatus)
|
||||
Program.mainForm.SetStatus(oldStatus);
|
||||
}
|
||||
|
||||
static void RemoveCompletedTasks (List<Task> runningTasks)
|
||||
static void RemoveCompletedTasks(List<Task> runningTasks)
|
||||
{
|
||||
foreach (Task task in new List<Task>(runningTasks))
|
||||
{
|
||||
@@ -126,7 +140,7 @@ namespace Flowframes.Magick
|
||||
img1.Write(imgOutPath);
|
||||
}
|
||||
|
||||
public static async Task BlendImages (string img1Path, string img2Path, string[] imgOutPaths)
|
||||
public static async Task BlendImages(string img1Path, string img2Path, string[] imgOutPaths)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -58,9 +58,16 @@ namespace Flowframes
|
||||
await RunAi(current.interpFolder, current.ai);
|
||||
if (canceled) return;
|
||||
Program.mainForm.SetProgress(100);
|
||||
|
||||
if(!currentlyUsingAutoEnc)
|
||||
await CreateVideo.Export(current.interpFolder, current.outPath, current.outMode, false);
|
||||
await IOUtils.ReverseRenaming(current.framesFolder, AiProcess.filenameMap); // Get timestamps back
|
||||
|
||||
if (Config.GetBool("keepTempFolder"))
|
||||
{
|
||||
await IOUtils.ReverseRenaming(current.framesFolder, AiProcess.filenameMap); // Get timestamps back
|
||||
AiProcess.SetFilenameMap(null, false);
|
||||
}
|
||||
|
||||
AiProcess.filenameMap.Clear();
|
||||
await Cleanup();
|
||||
Program.mainForm.SetWorking(false);
|
||||
@@ -151,17 +158,18 @@ namespace Flowframes
|
||||
|
||||
if (canceled) return;
|
||||
|
||||
try
|
||||
if (!stepByStep)
|
||||
{
|
||||
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.");
|
||||
try
|
||||
{
|
||||
Dictionary<string, string> renamedFilesDict = await IOUtils.RenameCounterDirReversibleAsync(current.framesFolder, "png", 1, Padding.inputFramesRenamed);
|
||||
AiProcess.SetFilenameMap(null, true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Log($"Error renaming frame files: {e.Message}");
|
||||
Cancel("Error renaming frame files. Check the log for details.");
|
||||
}
|
||||
}
|
||||
|
||||
if (current.alpha)
|
||||
|
||||
@@ -80,6 +80,9 @@ namespace Flowframes.Main
|
||||
return;
|
||||
}
|
||||
|
||||
Dictionary<string, string> renamedFilesDict = await IOUtils.RenameCounterDirReversibleAsync(current.framesFolder, "png", 1, Padding.inputFramesRenamed);
|
||||
AiProcess.SetFilenameMap(renamedFilesDict.ToDictionary(x => Path.GetFileName(x.Key), x => Path.GetFileName(x.Value)), true); // Save rel paths
|
||||
|
||||
currentInputFrameCount = await InterpolateUtils.GetInputFrameCountAsync(current.inPath);
|
||||
|
||||
// TODO: Check if this works lol, remove if it does
|
||||
@@ -92,10 +95,15 @@ namespace Flowframes.Main
|
||||
Program.mainForm.SetStatus("Running AI...");
|
||||
await RunAi(current.interpFolder, current.ai, true);
|
||||
await IOUtils.ReverseRenaming(current.framesFolder, AiProcess.filenameMap); // Get timestamps back
|
||||
AiProcess.filenameMap.Clear();
|
||||
AiProcess.SetFilenameMap(null, false);
|
||||
Program.mainForm.SetProgress(0);
|
||||
}
|
||||
|
||||
void RenameFrames ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static async Task CreateOutputVid()
|
||||
{
|
||||
if (!Directory.Exists(current.interpFolder) || IOUtils.GetAmountOfFiles(current.interpFolder, false) < 2)
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace Flowframes
|
||||
public static int lastStartupTimeMs = 1000;
|
||||
static string lastInPath;
|
||||
|
||||
public static bool framesAreRenamed;
|
||||
public static Dictionary<string, string> filenameMap = new Dictionary<string, string>(); // TODO: Store on disk instead for crashes?
|
||||
|
||||
public static void Kill ()
|
||||
@@ -45,6 +46,16 @@ namespace Flowframes
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetFilenameMap (Dictionary<string, string> map, bool isRenamed)
|
||||
{
|
||||
if (map == null)
|
||||
filenameMap.Clear();
|
||||
else
|
||||
filenameMap = map;
|
||||
|
||||
framesAreRenamed = isRenamed;
|
||||
}
|
||||
|
||||
static void AiStarted (Process proc, int startupTimeMs, string inPath = "")
|
||||
{
|
||||
lastStartupTimeMs = startupTimeMs;
|
||||
|
||||
Reference in New Issue
Block a user