BlendSceneChanges now works with auto-encode

This commit is contained in:
N00MKRAD
2021-03-21 16:00:53 +01:00
parent 19bf558132
commit 0455e60cc4
3 changed files with 20 additions and 29 deletions

View File

@@ -8,7 +8,6 @@ using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Flowframes.Magick
@@ -21,13 +20,22 @@ namespace Flowframes.Magick
sw.Restart();
int totalFrames = 0;
string keyword = "SCN:";
string fileContent = File.ReadAllText(framesFilePath);
if (!fileContent.Contains(keyword))
{
Logger.Log("Skipping BlendSceneChanges as there are no scene changes in this frames file.", true);
return;
}
string[] framesLines = fileContent.SplitIntoLines(); // Array with frame filenames
string oldStatus = Program.mainForm.GetStatus();
if(setStatus)
if (setStatus)
Program.mainForm.SetStatus("Blending scene transitions...");
string keyword = "SCN:";
string[] framesLines = IOUtils.ReadLines(framesFilePath); // Array with frame filenames
int amountOfBlendFrames = (int)Interpolate.current.interpFactor - 1;
List<Task> runningTasks = new List<Task>();
@@ -143,7 +151,6 @@ namespace Flowframes.Magick
img1Inst.Format = MagickFormat.Png24;
img1Inst.Quality = 10;
img1Inst.Write(outPath);
//await WriteImageSafe(img1Inst, outPath);
await Task.Delay(1);
}
}
@@ -152,22 +159,5 @@ namespace Flowframes.Magick
Logger.Log("BlendImages Error: " + e.Message);
}
}
static async Task WriteImageSafe (MagickImage img, string path)
{
img.Write(path);
try
{
MagickImage imgRead = new MagickImage(path);
Size res = new Size(imgRead.Width, imgRead.Height);
}
catch(Exception e)
{
Logger.Log($"Failed to write '{path}' correctly, will retry. {e.Message}", true);
await Task.Delay(100);
await WriteImageSafe(img, path);
}
}
}
}

View File

@@ -70,8 +70,6 @@ namespace Flowframes.Main
{
if (Interpolate.canceled) return;
Logger.Log($"AutoEnc Loop iteration runs. Paused: {paused}", true);
if (paused)
{
await Task.Delay(200);

View File

@@ -176,9 +176,12 @@ namespace Flowframes.Main
public static async Task EncodeChunk(string outPath, I.OutMode mode, int firstFrameNum, int framesAmount)
{
string vfrFileOriginal = Path.Combine(I.current.tempFolder, Paths.GetFrameOrderFilename(I.current.interpFactor));
string vfrFile = Path.Combine(I.current.tempFolder, Paths.GetFrameOrderFilenameChunk(firstFrameNum, firstFrameNum + framesAmount));
File.WriteAllLines(vfrFile, IOUtils.ReadLines(vfrFileOriginal).Skip(firstFrameNum).Take(framesAmount));
string framesFileFull = Path.Combine(I.current.tempFolder, Paths.GetFrameOrderFilename(I.current.interpFactor));
string framesFileChunk = Path.Combine(I.current.tempFolder, Paths.GetFrameOrderFilenameChunk(firstFrameNum, firstFrameNum + framesAmount));
File.WriteAllLines(framesFileChunk, IOUtils.ReadLines(framesFileFull).Skip(firstFrameNum).Take(framesAmount));
if (Config.GetInt("sceneChangeFillMode") == 1)
await Blend.BlendSceneChanges(framesFileChunk);
float maxFps = Config.GetFloat("maxFps");
bool fpsLimit = maxFps != 0 && I.current.outFps > maxFps;
@@ -186,14 +189,14 @@ namespace Flowframes.Main
bool dontEncodeFullFpsVid = fpsLimit && Config.GetInt("maxFpsMode") == 0;
if (!dontEncodeFullFpsVid)
await FfmpegEncode.FramesToVideoConcat(vfrFile, outPath, mode, I.current.outFps, AvProcess.LogMode.Hidden, true); // Encode
await FfmpegEncode.FramesToVideoConcat(framesFileChunk, outPath, mode, I.current.outFps, AvProcess.LogMode.Hidden, true); // Encode
if (fpsLimit)
{
string filename = Path.GetFileName(outPath);
string newParentDir = outPath.GetParentDir() + Paths.fpsLimitSuffix;
outPath = Path.Combine(newParentDir, filename);
await FfmpegEncode.FramesToVideoConcat(vfrFile, outPath, mode, I.current.outFps, maxFps, AvProcess.LogMode.Hidden, true); // Encode with limited fps
await FfmpegEncode.FramesToVideoConcat(framesFileChunk, outPath, mode, I.current.outFps, maxFps, AvProcess.LogMode.Hidden, true); // Encode with limited fps
}
}