mirror of
https://github.com/n00mkrad/flowframes.git
synced 2026-09-01 19:51:28 +02:00
New autoencode chunk-based saving system for resuming
This commit is contained in:
@@ -198,11 +198,7 @@ namespace Flowframes.Data
|
||||
|
||||
public static Fraction operator *(Fraction fract, long multi)
|
||||
{
|
||||
Logger.Log($"=> {fract} * {multi}");
|
||||
|
||||
long numerator = (long)fract.Numerator * (long)multi;
|
||||
Logger.Log($"=> numerator = {numerator}");
|
||||
|
||||
long denomenator = fract.Denominator;
|
||||
|
||||
return new Fraction(numerator, denomenator).GetReduced();
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace Flowframes.Data
|
||||
|
||||
if (!validColorSpaces.Contains(colorSpace.Trim()))
|
||||
{
|
||||
Logger.Log($"Warning: Color Space '{colorSpace.Trim()}' not valid.", true, false, "ffmpeg");
|
||||
Logger.Log($"Warning: Ignoring invalid color space '{colorSpace.Trim()}'.", true, false, "ffmpeg");
|
||||
colorSpace = "";
|
||||
}
|
||||
|
||||
|
||||
@@ -396,6 +396,7 @@
|
||||
<Compile Include="Magick\SceneDetect.cs" />
|
||||
<Compile Include="Main\AiModels.cs" />
|
||||
<Compile Include="Main\AutoEncode.cs" />
|
||||
<Compile Include="Main\AutoEncodeResume.cs" />
|
||||
<Compile Include="Main\BatchProcessing.cs" />
|
||||
<Compile Include="Main\Export.cs" />
|
||||
<Compile Include="Main\InterpolateSteps.cs" />
|
||||
|
||||
@@ -45,6 +45,7 @@ namespace Flowframes.Main
|
||||
|
||||
public static async Task MainLoop(string interpFramesPath)
|
||||
{
|
||||
AutoEncodeResume.Reset();
|
||||
debug = Config.GetBool("autoEncDebug", false);
|
||||
|
||||
try
|
||||
@@ -142,11 +143,10 @@ namespace Flowframes.Main
|
||||
if (Interpolate.canceled) return;
|
||||
|
||||
encodedFrameLines.AddRange(frameLinesToEncode);
|
||||
|
||||
Logger.Log("[AE] Done Encoding Chunk #" + chunkNo, true, false, "ffmpeg");
|
||||
lastEncodedFrameNum = (frameLinesToEncode.Last() + 1);
|
||||
|
||||
chunkNo++;
|
||||
AutoEncodeResume.Save();
|
||||
|
||||
if(!imgSeq && Config.GetInt(Config.Key.autoEncBackupMode) > 0)
|
||||
{
|
||||
|
||||
44
Code/Main/AutoEncodeResume.cs
Normal file
44
Code/Main/AutoEncodeResume.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Flowframes.Data;
|
||||
using Flowframes.IO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Flowframes.MiscUtils;
|
||||
using Flowframes.Ui;
|
||||
using I = Flowframes.Interpolate;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Flowframes.Main
|
||||
{
|
||||
class AutoEncodeResume
|
||||
{
|
||||
public static List<string> processedInputFrames = new List<string>();
|
||||
public static int encodedChunks = 0;
|
||||
public static int encodedFrames = 0;
|
||||
|
||||
public static void Reset ()
|
||||
{
|
||||
processedInputFrames = new List<string>();
|
||||
encodedChunks = 0;
|
||||
encodedFrames = 0;
|
||||
}
|
||||
|
||||
public static void Save ()
|
||||
{
|
||||
string saveDir = Path.Combine(I.current.tempFolder, Paths.resumeDir);
|
||||
Directory.CreateDirectory(saveDir);
|
||||
string chunksJsonPath = Path.Combine(saveDir, "chunks.json");
|
||||
Dictionary<string, string> saveData = new Dictionary<string, string>();
|
||||
saveData.Add("encodedChunks", encodedChunks.ToString());
|
||||
saveData.Add("encodedFrames", encodedFrames.ToString());
|
||||
File.WriteAllText(chunksJsonPath, JsonConvert.SerializeObject(saveData, Formatting.Indented));
|
||||
|
||||
string inputFramesJsonPath = Path.Combine(saveDir, "input-frames.json");
|
||||
File.WriteAllText(inputFramesJsonPath, JsonConvert.SerializeObject(processedInputFrames, Formatting.Indented));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ using Flowframes.Data;
|
||||
using Flowframes.Media;
|
||||
using Flowframes.MiscUtils;
|
||||
using Flowframes.Os;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Flowframes.Main
|
||||
{
|
||||
@@ -256,6 +258,8 @@ namespace Flowframes.Main
|
||||
string concatFile = Path.Combine(I.current.tempFolder, Paths.GetFrameOrderFilenameChunk(firstFrameNum, firstFrameNum + framesAmount));
|
||||
File.WriteAllLines(concatFile, IoUtils.ReadLines(framesFileFull).Skip(firstFrameNum).Take(framesAmount));
|
||||
|
||||
List<string> inputFrames = JsonConvert.DeserializeObject<List<string>>(File.ReadAllText(framesFileFull + ".inputframes.json")).Skip(firstFrameNum).Take(framesAmount).ToList();
|
||||
|
||||
if (Config.GetInt(Config.Key.sceneChangeFillMode) == 1)
|
||||
await Blend.BlendSceneChanges(concatFile, false);
|
||||
|
||||
@@ -305,6 +309,10 @@ namespace Flowframes.Main
|
||||
await FfmpegEncode.FramesToVideo(concatFile, outPath, mode, I.current.outFps, maxFps, I.current.outItsScale, extraData, AvProcess.LogMode.Hidden, true); // Encode with limited fps
|
||||
}
|
||||
}
|
||||
|
||||
AutoEncodeResume.encodedChunks += 1;
|
||||
AutoEncodeResume.encodedFrames += framesAmount;
|
||||
AutoEncodeResume.processedInputFrames.AddRange(inputFrames);
|
||||
}
|
||||
|
||||
static async Task Loop(string outPath, int looptimes)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Flowframes.Data;
|
||||
using Flowframes.IO;
|
||||
using Flowframes.MiscUtils;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -17,6 +18,7 @@ namespace Flowframes.Main
|
||||
static FileInfo[] frameFilesWithoutLast;
|
||||
static List<string> sceneFrames = new List<string>();
|
||||
static Dictionary<int, string> frameFileContents = new Dictionary<int, string>();
|
||||
static List<string> inputFilenames = new List<string>();
|
||||
static int lastOutFileCount;
|
||||
|
||||
public static async Task CreateFrameOrderFile(string framesPath, bool loopEnabled, float times)
|
||||
@@ -80,6 +82,7 @@ namespace Flowframes.Main
|
||||
if (Directory.Exists(scnFramesPath))
|
||||
sceneFrames = Directory.GetFiles(scnFramesPath).Select(file => GetNameNoExt(file)).ToList();
|
||||
|
||||
inputFilenames.Clear();
|
||||
bool debug = Config.GetBool("frameOrderDebug", false);
|
||||
List<Task> tasks = new List<Task>();
|
||||
int linesPerTask = 400 / (int)interpFactor;
|
||||
@@ -100,12 +103,19 @@ namespace Flowframes.Main
|
||||
int lastFrameTimes = Config.GetBool(Config.Key.fixOutputDuration) ? (int)interpFactor : 1;
|
||||
|
||||
for(int i = 0; i < lastFrameTimes; i++)
|
||||
{
|
||||
fileContent += $"{(i > 0 ? "\n" : "")}file '{Paths.interpDir}/{lastOutFileCount.ToString().PadLeft(Padding.interpFrames, '0')}{ext}'"; // Last frame (source)
|
||||
|
||||
inputFilenames.Add(frameFiles.Last().Name);
|
||||
}
|
||||
|
||||
if (loop)
|
||||
{
|
||||
fileContent = fileContent.Remove(fileContent.LastIndexOf("\n"));
|
||||
inputFilenames.Remove(inputFilenames.Last());
|
||||
}
|
||||
|
||||
File.WriteAllText(framesFile, fileContent);
|
||||
File.WriteAllText(framesFile + ".inputframes.json", JsonConvert.SerializeObject(inputFilenames, Formatting.Indented));
|
||||
}
|
||||
|
||||
static async Task GenerateFrameLines(int number, int startIndex, int count, int factor, bool loopEnabled, bool sceneDetection, bool debug)
|
||||
@@ -163,6 +173,8 @@ namespace Flowframes.Main
|
||||
totalFileCount++;
|
||||
fileContent = WriteFrameWithDupes(dupesAmount, fileContent, totalFileCount, ext, debug, $"[In: {frameName}] [{((frm == 0) ? " Source " : $"Interp {frm}")}]");
|
||||
}
|
||||
|
||||
inputFilenames.Add(frameFilesWithoutLast[i].Name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,6 +192,9 @@ namespace Flowframes.Main
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
static string GetNameNoExt (string path) { return Path.GetFileNameWithoutExtension(path); }
|
||||
static string GetNameNoExt (string path)
|
||||
{
|
||||
return Path.GetFileNameWithoutExtension(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user