SBS: Only create timecodes for selected factor + disable autoenc, code cleanup

This commit is contained in:
N00MKRAD 2020-12-07 10:48:50 +01:00
parent 8df71c54c0
commit a29c654dbb
6 changed files with 20 additions and 36 deletions

View File

@ -207,7 +207,7 @@ namespace Flowframes
DeleteSource(inputFile);
}
public static async Task Encode (string inputFile, string vcodec, string acodec, int crf, int audioKbps, bool delSrc)
public static async Task Encode (string inputFile, string vcodec, string acodec, int crf, int audioKbps = 0, bool delSrc = false)
{
string outPath = Path.ChangeExtension(inputFile, null) + "-convert.mp4";
string args = $" -i {inputFile.Wrap()} -c:v {vcodec} -crf {crf} -pix_fmt yuv420p -c:a {acodec} -b:a {audioKbps}k {outPath.Wrap()}";

View File

@ -79,11 +79,11 @@ namespace Flowframes.Main
if (mode == i.OutMode.VidMp4)
{
int looptimes = GetLoopTimes(framesPath);
int looptimes = GetLoopTimes();
bool h265 = Config.GetInt("mp4Enc") == 1;
int crf = h265 ? Config.GetInt("h265Crf") : Config.GetInt("h264Crf");
string vfrFile = Path.Combine(framesPath.GetParentDir(), $"vfr-x{i.lastInterpFactor}.ini");
string vfrFile = Path.Combine(framesPath.GetParentDir(), $"vfr-{i.lastInterpFactor}x.ini");
await FFmpegCommands.FramesToMp4Vfr(vfrFile, outPath, h265, crf, fps, i.constantFrameRate);
/* DELETE THIS AS SOON AS I'M SURE I CAN USE VFR WITH TIMING DISABLED
@ -143,7 +143,7 @@ namespace Flowframes.Main
static async Task MergeChunks(string chunksPath, string vfrFile, string outPath, float fps, float changeFps = -1, bool keepOriginalFpsVid = true)
{
int looptimes = GetLoopTimes(Path.Combine(chunksPath.GetParentDir(), Paths.interpDir));
int looptimes = GetLoopTimes();
bool h265 = Config.GetInt("mp4Enc") == 1;
int crf = h265 ? Config.GetInt("h265Crf") : Config.GetInt("h264Crf");
@ -170,7 +170,7 @@ namespace Flowframes.Main
bool h265 = Config.GetInt("mp4Enc") == 1;
int crf = h265 ? Config.GetInt("h265Crf") : Config.GetInt("h264Crf");
string vfrFileOriginal = Path.Combine(i.currentTempDir, $"vfr-x{i.lastInterpFactor}.ini");
string vfrFileOriginal = Path.Combine(i.currentTempDir, $"vfr-{i.lastInterpFactor}x.ini");
string vfrFile = Path.Combine(i.currentTempDir, $"vfr-chunk-temp.ini");
File.WriteAllLines(vfrFile, IOUtils.ReadLines(vfrFileOriginal).Skip(firstFrameNum * 2).Take(framesAmount * 2));
@ -180,11 +180,11 @@ namespace Flowframes.Main
static async Task Loop(string outPath, int looptimes)
{
Logger.Log($"Looping {looptimes} times to reach target length");
Logger.Log($"Looping {looptimes} times to reach target length...");
await FFmpegCommands.LoopVideo(outPath, looptimes, Config.GetInt("loopMode") == 0);
}
static int GetLoopTimes(string framesOutPath)
static int GetLoopTimes()
{
//Logger.Log("Getting loop times for path " + framesOutPath);
int times = -1;

View File

@ -157,25 +157,21 @@ namespace Flowframes
int frameCountAfterDedupe = IOUtils.GetAmountOfFiles(currentFramesPath, false, "*.png");
int dupesPercent = 100 - (((float)frameCountAfterDedupe / currentInputFrameCount) * 100f).RoundToInt();
constantFrameRate = dupesPercent < 5f; // Ignore VFR timings for CFR input. TODO: Figure out how to avoid dupes when using VFR timings
Logger.Log($"{dupesPercent}% of frames are dupes, so constantFrameRate = {constantFrameRate}");
Logger.Log($"{dupesPercent}% of frames are dupes, so constantFrameRate = {constantFrameRate}", true);
if (canceled) return;
bool useTimestamps = Config.GetInt("timingMode") == 1; // TODO: Auto-Disable timestamps if input frames are sequential, not timestamped
if(sbsMode)
await VfrDedupe.CreateTimecodeFiles(currentFramesPath, Config.GetBool("enableLoop"), -1, !useTimestamps);
else
await VfrDedupe.CreateTimecodeFiles(currentFramesPath, Config.GetBool("enableLoop"), lastInterpFactor, !useTimestamps);
await VfrDedupe.CreateTimecodeFiles(currentFramesPath, Config.GetBool("enableLoop"), lastInterpFactor, !useTimestamps);
if (canceled) return;
AiProcess.filenameMap = IOUtils.RenameCounterDirReversible(currentFramesPath, "png", 1, 8);
}
public static async Task RunAi(string outpath, int targetFrames, int tilesize, AI ai)
public static async Task RunAi(string outpath, int targetFrames, int tilesize, AI ai, bool stepByStep = false)
{
if (Config.GetInt("autoEncMode") > 0)
if (!stepByStep && Config.GetInt("autoEncMode") > 0)
currentlyUsingAutoEnc = IOUtils.GetAmountOfFiles(currentFramesPath, false) * lastInterpFactor >= (AutoEncode.chunkSize + AutoEncode.safetyBufferFrames) * 1.1f;
else
currentlyUsingAutoEnc = false;

View File

@ -63,6 +63,7 @@ namespace Flowframes.Main
{
BatchEntry e = Program.mainForm.GetBatchEntry();
interpFactor = e.interpFactor;
Logger.Log("interpFactor from gui batchentry: " + interpFactor);
currentAi = e.ai;
try
@ -154,17 +155,17 @@ namespace Flowframes.Main
IOUtils.TryDeleteIfExists(ini);
IOUtils.ReverseRenaming(AiProcess.filenameMap, true); // Get timestamps back
lastInterpFactor = interpFactor;
await PostProcessFrames(true);
lastInterpFactor = interpFactor;
int frames = IOUtils.GetAmountOfFiles(currentFramesPath, false, "*.png");
int targetFrameCount = frames * lastInterpFactor;
GetProgressByFrameAmount(currentInterpFramesDir, targetFrameCount);
if (canceled) return;
Program.mainForm.SetStatus("Running AI...");
int tilesize = currentAi.supportsTiling ? Config.GetInt($"tilesize_{currentAi.aiName}") : 512;
await RunAi(currentInterpFramesDir, targetFrameCount, tilesize, currentAi);
await RunAi(currentInterpFramesDir, targetFrameCount, tilesize, currentAi, true);
Program.mainForm.SetProgress(0);
}

View File

@ -17,22 +17,10 @@ namespace Flowframes.Main
public static async Task CreateTimecodeFiles(string framesPath, bool loopEnabled, int times, bool noTimestamps)
{
Logger.Log("Generating timecodes...");
if(times <= 0)
{
await CreateTimecodeFile(framesPath, loopEnabled, 2, false, noTimestamps);
await CreateTimecodeFile(framesPath, loopEnabled, 4, true, noTimestamps);
await CreateTimecodeFile(framesPath, loopEnabled, 8, true, noTimestamps);
}
else
{
await CreateTimecodeFile(framesPath, loopEnabled, times, false, noTimestamps);
}
frameFiles = null;
await CreateTimecodeFile(framesPath, loopEnabled, times, false, noTimestamps);
Logger.Log($"Generating timecodes... Done.", false, true);
}
static FileInfo[] frameFiles;
public static async Task CreateTimecodeFile(string framesPath, bool loopEnabled, int interpFactor, bool notFirstRun, bool noTimestamps)
{
if (Interpolate.canceled) return;
@ -43,9 +31,8 @@ namespace Flowframes.Main
bool sceneDetection = true;
if(frameFiles == null || frameFiles.Length < 1)
frameFiles = new DirectoryInfo(framesPath).GetFiles("*.png");
string vfrFile = Path.Combine(framesPath.GetParentDir(), $"vfr-x{interpFactor}.ini");
FileInfo[] frameFiles = new DirectoryInfo(framesPath).GetFiles("*.png");
string vfrFile = Path.Combine(framesPath.GetParentDir(), $"vfr-{interpFactor}x.ini");
string fileContent = "";
string scnFramesPath = Path.Combine(framesPath.GetParentDir(), Paths.scenesDir);

View File

@ -53,10 +53,10 @@ namespace Flowframes.UI
return;
int crf = crfBox.GetInt();
Logger.Log("Creating MP4 with CRF " + crf + "...", true);
if(Formats.noEncodeSupport.Contains(Path.GetExtension(inputFile)))
await FFmpegCommands.Encode(inputFile, "libx264", "aac", crf, 112, false); // Use AAC if there is no audio enc for this format
if(Path.GetExtension(inputFile).ToUpper() != ".MP4")
await FFmpegCommands.Encode(inputFile, "libx264", "aac", crf, 128);
else
await FFmpegCommands.Encode(inputFile, "libx264", "copy", crf, 0, false); // Copy audio if compatible
await FFmpegCommands.Encode(inputFile, "libx264", "copy", crf); // Copy audio if input is MP4
Logger.Log("Done", true);
}