Fixed dupes dict bug, fixed autoenc getting stuck (i think?)

This commit is contained in:
N00MKRAD
2021-01-05 13:00:27 +01:00
parent 17a59a36a5
commit e6f129e4e5
5 changed files with 22 additions and 18 deletions

View File

@@ -77,7 +77,7 @@ namespace Flowframes.Magick
bool hasReachedEnd = false;
string infoFile = Path.Combine(path.GetParentDir(), $"dupes.ini");
string infoFile = Path.Combine(path.GetParentDir(), $"dupes-magick.ini");
string fileContent = "";
for (int i = 0; i < framePaths.Length; i++) // Loop through frames
@@ -169,7 +169,7 @@ namespace Flowframes.Magick
}
}
File.WriteAllText(infoFile, fileContent);
// File.WriteAllText(infoFile, fileContent); // DISABLED FOR NOW as we use a single piece of code for mpdec and this code
foreach (string frame in framesToDelete)
IOUtils.TryDeleteIfExists(frame);

View File

@@ -59,7 +59,7 @@ namespace Flowframes.Main
//unencodedFrameLines = interpFramesLines.Select(x => x.GetInt()).ToList().Except(encodedFrameLines).ToList();
Logger.Log($"{unencodedFrameLines.Count} unencoded frame lines, {encodedFrameLines.Count} encoded frame lines", true, false, "ffmpeg");
//Logger.Log($"{unencodedFrameLines.Count} unencoded frame lines, {encodedFrameLines.Count} encoded frame lines", true, false, "ffmpeg");
unencodedFrameLines.Clear();
for(int vfrLine = 0; vfrLine < interpFramesLines.Length; vfrLine++)
@@ -77,14 +77,14 @@ namespace Flowframes.Main
busy = true;
List<int> frameLinesToEncode = aiRunning ? unencodedFrameLines.Take(chunkSize).ToList() : unencodedFrameLines; // Take all remaining frames if process is done
Logger.Log($"{unencodedFrameLines.Count} unencoded frame lines, {IOUtils.GetAmountOfFiles(interpFramesFolder, false)} frames in interp folder", true, false, "ffmpeg");
//Logger.Log($"{unencodedFrameLines.Count} unencoded frame lines, {IOUtils.GetAmountOfFiles(interpFramesFolder, false)} frames in interp folder", true, false, "ffmpeg");
Logger.Log($"Encoding Chunk #{videoIndex} using {Path.GetFileName(interpFramesLines[frameLinesToEncode.First()])} through {Path.GetFileName(Path.GetFileName(interpFramesLines[frameLinesToEncode.Last()]))}", true, false, "ffmpeg");
//IOUtils.ZeroPadDir(framesToEncode, Padding.interpFrames); // Zero-pad frames before encoding to make sure filenames match with VFR file
string outpath = Path.Combine(videoChunksFolder, $"{videoIndex.ToString().PadLeft(4, '0')}{FFmpegUtils.GetExt(Interpolate.current.outMode)}");
int firstFrameNum = frameLinesToEncode[0];
await CreateVideo.EncodeChunk(outpath, Interpolate.current.outMode, firstFrameNum - 1, frameLinesToEncode.Count);
await CreateVideo.EncodeChunk(outpath, Interpolate.current.outMode, firstFrameNum, frameLinesToEncode.Count);
if(Interpolate.canceled) return;
@@ -101,6 +101,7 @@ namespace Flowframes.Main
}
encodedFrameLines.AddRange(frameLinesToEncode);
//Logger.Log($"Adding {frameLinesToEncode.Count} frameLinesToEncode to encodedFrameLines, new count is {encodedFrameLines.Count}");
Logger.Log("Done Encoding Chunk #" + videoIndex, true, false, "ffmpeg");
videoIndex++;
@@ -125,6 +126,7 @@ namespace Flowframes.Main
public static bool HasWorkToDo ()
{
if (Interpolate.canceled || interpFramesFolder == null) return false;
//Logger.Log($"HasWorkToDo - Process Running: {(AiProcess.currentAiProcess != null && !AiProcess.currentAiProcess.HasExited)} - encodedFrameLines.Count: {encodedFrameLines.Count} - interpFramesLines.Length: {interpFramesLines.Length}");
return ((AiProcess.currentAiProcess != null && !AiProcess.currentAiProcess.HasExited) || encodedFrameLines.Count < interpFramesLines.Length);
}

View File

@@ -154,8 +154,8 @@ namespace Flowframes.Main
static void LoadDupesFile (string path)
{
if (!File.Exists(path)) return;
dupesDict.Clear();
if (!File.Exists(path)) return;
string[] dupesFileLines = IOUtils.ReadLines(path);
foreach(string line in dupesFileLines)
{
@@ -186,6 +186,8 @@ namespace Flowframes.Main
if (Directory.Exists(scnFramesPath))
sceneFrames = Directory.GetFiles(scnFramesPath).Select(file => Path.GetFileNameWithoutExtension(file)).ToList();
bool debug = false;
int totalFileCount = 1;
for (int i = 0; i < (frameFiles.Length - 1); i++)
{
@@ -194,7 +196,8 @@ namespace Flowframes.Main
int interpFramesAmount = interpFactor;
string inputFilenameNoExt = Path.GetFileNameWithoutExtension(frameFiles[i].Name);
int dupesAmount = dupesDict.ContainsKey(inputFilenameNoExt) ? dupesDict[inputFilenameNoExt] : 0;
//Logger.Log($"{Path.GetFileNameWithoutExtension(frameFiles[i].Name)} has {dupesAmount} dupes", true);
if(debug) Logger.Log($"{Path.GetFileNameWithoutExtension(frameFiles[i].Name)} has {dupesAmount} dupes", true);
bool discardThisFrame = (sceneDetection && (i + 2) < frameFiles.Length && sceneFrames.Contains(Path.GetFileNameWithoutExtension(frameFiles[i + 1].Name))); // i+2 is in scene detection folder, means i+1 is ugly interp frame
@@ -203,25 +206,24 @@ namespace Flowframes.Main
if (loopEnabled && i == (frameFiles.Length - 2))
interpFramesAmount = interpFramesAmount * 2;
//Logger.Log($"Writing out frames for in frame {i} which has {dupesAmount} dupes", true);
if (debug) Logger.Log($"Writing out frames for in frame {i} which has {dupesAmount} dupes", true);
// Generate frames file lines
for (int frm = 0; frm < interpFramesAmount; frm++)
{
//Logger.Log($"Writing out frame {frm+1}/{interpFramesAmount}", true);
if (debug) Logger.Log($"Writing out frame {frm+1}/{interpFramesAmount}", true);
if (discardThisFrame && totalFileCount > 1) // If frame is scene cut frame
{
int lastNum = totalFileCount;
//Logger.Log($"Writing frame {totalFileCount} [Discarding Next]", true);
if (debug) Logger.Log($"Writing frame {totalFileCount} [Discarding Next]", true);
fileContent += $"file '{interpPath}/{totalFileCount.ToString().PadLeft(Padding.interpFrames, '0')}.{ext}'\n";
totalFileCount++;
//Logger.Log("Discarding interp frames with out num " + totalFileCount);
if (debug) Logger.Log("Discarding interp frames with out num " + totalFileCount);
for (int dupeCount = 1; dupeCount < interpFramesAmount; dupeCount++)
{
//Logger.Log($"Writing frame {totalFileCount} which is actually repeated frame {lastNum}");
if (debug) Logger.Log($"Writing frame {totalFileCount} which is actually repeated frame {lastNum}");
fileContent += $"file '{interpPath}/{lastNum.ToString().PadLeft(Padding.interpFrames, '0')}.{ext}'\n";
totalFileCount++;
}
@@ -232,7 +234,7 @@ namespace Flowframes.Main
{
for(int writtenDupes = -1; writtenDupes < dupesAmount; writtenDupes++) // Write duplicates
{
//Logger.Log($"Writing frame {totalFileCount}", true, false);
if (debug) Logger.Log($"Writing frame {totalFileCount} (writtenDupes {writtenDupes})", true, false);
fileContent += $"file '{interpPath}/{totalFileCount.ToString().PadLeft(Padding.interpFrames, '0')}.{ext}'\n";
}
totalFileCount++;
@@ -261,11 +263,11 @@ namespace Flowframes.Main
string loopFrameTargetPath = Path.Combine(frameFiles.First().FullName.GetParentDir(), lastFileNumber.ToString().PadLeft(Padding.inputFrames, '0') + $".png");
if (File.Exists(loopFrameTargetPath))
{
Logger.Log($"Won't copy loop frame - {Path.GetFileName(loopFrameTargetPath)} already exists.", true);
if (debug) Logger.Log($"Won't copy loop frame - {Path.GetFileName(loopFrameTargetPath)} already exists.", true);
return;
}
File.Copy(frameFiles.First().FullName, loopFrameTargetPath);
Logger.Log($"Copied loop frame to {loopFrameTargetPath}.", true);
if (debug) Logger.Log($"Copied loop frame to {loopFrameTargetPath}.", true);
}
}
}

View File

@@ -122,7 +122,7 @@ namespace Flowframes
else
Dedupe.ClearCache();
if (Config.GetInt("dedupMode") == 2)
if (Config.GetInt("dedupMode") == 2 || Config.GetInt("dedupMode") == 1)
await Dedupe.CreateDupesFileMpdecimate(current.framesFolder, currentInputFrameCount);
if (canceled) return;

View File

@@ -86,7 +86,7 @@ namespace Flowframes.OS
public static bool HasEmbeddedPyFolder ()
{
return Directory.Exists(GetPyFolder());
return (Directory.Exists(GetPyFolder()) && IOUtils.GetDirSize(GetPyFolder(), false) > 1024 * 1024 * 5);
}
public static string GetPyFolder ()