Fixed broken autoenc performance fix lol, some cleanup

This commit is contained in:
N00MKRAD
2021-01-07 11:02:43 +01:00
parent 68ed5fc7d5
commit dc9035caa1
6 changed files with 23 additions and 75 deletions

View File

@@ -30,7 +30,8 @@ namespace Flowframes
Logger.Log("Extracting scene changes..."); Logger.Log("Extracting scene changes...");
await VideoToFrames(inputFile, frameFolderPath, rate, false, false, new Size(320, 180), false, true); await VideoToFrames(inputFile, frameFolderPath, rate, false, false, new Size(320, 180), false, true);
bool hiddenLog = Interpolate.currentInputFrameCount <= 50; bool hiddenLog = Interpolate.currentInputFrameCount <= 50;
Logger.Log($"Detected {IOUtils.GetAmountOfFiles(frameFolderPath, false)} scene changes.".Replace(" 0 ", " no "), false, !hiddenLog); int amount = IOUtils.GetAmountOfFiles(frameFolderPath, false);
Logger.Log($"Detected {amount} scene {(amount == 1 ? "change" : "changes")}.".Replace(" 0 ", " no "), false, !hiddenLog);
} }
public static async Task VideoToFrames(string inputFile, string frameFolderPath, float rate, bool deDupe, bool delSrc, bool timecodes = true) public static async Task VideoToFrames(string inputFile, string frameFolderPath, float rate, bool deDupe, bool delSrc, bool timecodes = true)
@@ -46,15 +47,15 @@ namespace Flowframes
string timecodeStr = timecodes ? $"-copyts -r {FrameTiming.timebase} -frame_pts true" : "-copyts -frame_pts true"; string timecodeStr = timecodes ? $"-copyts -r {FrameTiming.timebase} -frame_pts true" : "-copyts -frame_pts true";
string scnDetect = sceneDetect ? $"\"select='gt(scene,{Config.GetFloatString("scnDetectValue")})'\"" : ""; string scnDetect = sceneDetect ? $"\"select='gt(scene,{Config.GetFloatString("scnDetectValue")})'\"" : "";
string mpStr = deDupe ? ((Config.GetInt("mpdecimateMode") == 0) ? mpDecDef : mpDecAggr) : ""; string mpStr = deDupe ? ((Config.GetInt("mpdecimateMode") == 0) ? mpDecDef : mpDecAggr) : "";
string fpsFilter = $"\"fps=fps={Interpolate.current.inFps.ToString().Replace(",", ".")}\""; string filters = FormatUtils.ConcatStrings(new string[] { scnDetect, mpStr } );
string filters = FormatUtils.ConcatStrings(new string[] { scnDetect, mpStr/*, fpsFilter*/ } );
string vf = filters.Length > 2 ? $"-vf {filters}" : ""; string vf = filters.Length > 2 ? $"-vf {filters}" : "";
string rateArg = (rate > 0) ? $" -r {rate.ToStringDot()}" : ""; string rateArg = (rate > 0) ? $" -r {rate.ToStringDot()}" : "";
string pad = Padding.inputFrames.ToString(); string pad = Padding.inputFrames.ToString();
string args = $"{rateArg} -i {inputFile.Wrap()} {pngComprArg} -vsync 0 -pix_fmt rgb24 {timecodeStr} {vf} {sizeStr} \"{frameFolderPath}/%{pad}d.png\""; string args = $"{rateArg} -i {inputFile.Wrap()} {pngComprArg} -vsync 0 -pix_fmt rgb24 {timecodeStr} {vf} {sizeStr} \"{frameFolderPath}/%{pad}d.png\"";
AvProcess.LogMode logMode = Interpolate.currentInputFrameCount > 50 ? AvProcess.LogMode.OnlyLastLine : AvProcess.LogMode.Hidden; AvProcess.LogMode logMode = Interpolate.currentInputFrameCount > 50 ? AvProcess.LogMode.OnlyLastLine : AvProcess.LogMode.Hidden;
await AvProcess.RunFfmpeg(args, logMode); await AvProcess.RunFfmpeg(args, logMode, AvProcess.TaskType.ExtractFrames);
if (!sceneDetect) Logger.Log($"Extracted {IOUtils.GetAmountOfFiles(frameFolderPath, false, "*.png")} frames from input.", false, true); int amount = IOUtils.GetAmountOfFiles(frameFolderPath, false, "*.png");
if (!sceneDetect) Logger.Log($"Extracted {amount} {(amount == 1 ? "frame" : "frames")} from input.", false, true);
await Task.Delay(1); await Task.Delay(1);
if (delSrc) if (delSrc)
DeleteSource(inputFile); DeleteSource(inputFile);
@@ -122,17 +123,6 @@ namespace Flowframes
await AvProcess.RunFfmpeg(args, concatFile.GetParentDir(), AvProcess.LogMode.Hidden, AvProcess.TaskType.Merge); await AvProcess.RunFfmpeg(args, concatFile.GetParentDir(), AvProcess.LogMode.Hidden, AvProcess.TaskType.Merge);
} }
public static async Task ConvertFramerate(string inputPath, string outPath, bool useH265, int crf, float newFps, bool delSrc = false)
{
Logger.Log($"Changing video frame rate...");
string enc = useH265 ? "libx265" : "libx264";
string presetStr = $"-preset {Config.Get("ffEncPreset")}";
string args = $" -i {inputPath.Wrap()} -filter:v fps=fps={newFps} -c:v {enc} -crf {crf} {presetStr} {videoEncArgs} {outPath.Wrap()}";
await AvProcess.RunFfmpeg(args, AvProcess.LogMode.OnlyLastLine);
if (delSrc)
DeleteSource(inputPath);
}
public static async Task FramesToGifConcat(string framesFile, string outPath, float fps, bool palette, int colors = 64, float resampleFps = -1, AvProcess.LogMode logMode = AvProcess.LogMode.OnlyLastLine) public static async Task FramesToGifConcat(string framesFile, string outPath, float fps, bool palette, int colors = 64, float resampleFps = -1, AvProcess.LogMode logMode = AvProcess.LogMode.OnlyLastLine)
{ {
if (logMode != AvProcess.LogMode.Hidden) if (logMode != AvProcess.LogMode.Hidden)
@@ -196,7 +186,6 @@ namespace Flowframes
public static async Task ExtractAudio(string inputFile, string outFile) // https://stackoverflow.com/a/27413824/14274419 public static async Task ExtractAudio(string inputFile, string outFile) // https://stackoverflow.com/a/27413824/14274419
{ {
Logger.Log($"[FFCmds] Extracting audio from {inputFile} to {outFile}", true); Logger.Log($"[FFCmds] Extracting audio from {inputFile} to {outFile}", true);
//string ext = GetAudioExt(inputFile);
outFile = Path.ChangeExtension(outFile, ".ogg"); outFile = Path.ChangeExtension(outFile, ".ogg");
string args = $" -loglevel panic -i {inputFile.Wrap()} -vn -acodec libopus -b:a 256k {outFile.Wrap()}"; string args = $" -loglevel panic -i {inputFile.Wrap()} -vn -acodec libopus -b:a 256k {outFile.Wrap()}";
await AvProcess.RunFfmpeg(args, AvProcess.LogMode.Hidden); await AvProcess.RunFfmpeg(args, AvProcess.LogMode.Hidden);
@@ -383,20 +372,7 @@ namespace Flowframes
foreach (string entry in entries) foreach (string entry in entries)
{ {
if (entry.Contains("codec_name=")) if (entry.Contains("codec_name="))
{
Logger.Log($"[FFCmds] Audio Codec Entry: {entry}", true);
return entry.Split('=')[1]; return entry.Split('=')[1];
}
}
return "";
}
static string GetFirstStreamInfo(string ffmpegOutput)
{
foreach (string line in Regex.Split(ffmpegOutput, "\r\n|\r|\n"))
{
if (line.Contains("Stream #0"))
return line;
} }
return ""; return "";
} }

View File

@@ -77,7 +77,6 @@ namespace Flowframes.Magick
bool hasReachedEnd = false; bool hasReachedEnd = false;
string infoFile = Path.Combine(path.GetParentDir(), $"dupes-magick.ini");
string fileContent = ""; string fileContent = "";
for (int i = 0; i < framePaths.Length; i++) // Loop through frames for (int i = 0; i < framePaths.Length; i++) // Loop through frames
@@ -86,8 +85,6 @@ namespace Flowframes.Magick
break; break;
string frame1 = framePaths[i].FullName; string frame1 = framePaths[i].FullName;
//if (!File.Exists(framePaths[i].FullName)) // Skip if file doesn't exist (already deleted / used to be a duped frame)
// continue;
int compareWithIndex = i + 1; int compareWithIndex = i + 1;
@@ -107,22 +104,13 @@ namespace Flowframes.Magick
} }
else else
{ {
//if (compareWithIndex >= framePaths.Length)
// hasReachedEnd = true;
string frame2 = framePaths[compareWithIndex].FullName; string frame2 = framePaths[compareWithIndex].FullName;
// if (oldIndex >= 0)
// i = oldIndex;
float diff = GetDifference(frame1, frame2); float diff = GetDifference(frame1, frame2);
string delStr = "Keeping";
if (diff < threshold) // Is a duped frame. if (diff < threshold) // Is a duped frame.
{ {
if (!testRun) if (!testRun)
{ {
delStr = "Deleting";
//File.Delete(frame2);
framesToDelete.Add(frame2); framesToDelete.Add(frame2);
if (debugLog) Logger.Log("[Deduplication] Deleted " + Path.GetFileName(frame2)); if (debugLog) Logger.Log("[Deduplication] Deleted " + Path.GetFileName(frame2));
hasEncounteredAnyDupes = true; hasEncounteredAnyDupes = true;
@@ -142,7 +130,7 @@ namespace Flowframes.Magick
if (sw.ElapsedMilliseconds >= 1000 || (i+1) == framePaths.Length) // Print every 1s (or when done) if (sw.ElapsedMilliseconds >= 1000 || (i+1) == framePaths.Length) // Print every 1s (or when done)
{ {
sw.Restart(); sw.Restart();
Logger.Log($"[Deduplication] Running de-duplication ({i}/{framePaths.Length}), deleted {statsFramesDeleted} duplicate frames so far...", false, true); Logger.Log($"[Deduplication] Running de-duplication ({i}/{framePaths.Length}), deleted {statsFramesDeleted} ({(((float)statsFramesDeleted / framePaths.Length) * 100f).ToString("0")}%) duplicate frames so far...", false, true);
Program.mainForm.SetProgress((int)Math.Round(((float)i / framePaths.Length) * 100f)); Program.mainForm.SetProgress((int)Math.Round(((float)i / framePaths.Length) * 100f));
if (imageCache.Count > bufferSize || (imageCache.Count > 50 && OSUtils.GetFreeRamMb() < 2500)) if (imageCache.Count > bufferSize || (imageCache.Count > 50 && OSUtils.GetFreeRamMb() < 2500))
ClearCache(); ClearCache();
@@ -157,7 +145,7 @@ namespace Flowframes.Magick
// i = 0; // i = 0;
// } // }
if(i % 5 == 0) if(i % 3 == 0)
await Task.Delay(1); await Task.Delay(1);
if (Interpolate.canceled) return; if (Interpolate.canceled) return;

View File

@@ -60,11 +60,6 @@ namespace Flowframes.Main
continue; continue;
} }
//IOUtils.ZeroPadDir(Directory.GetFiles(interpFramesFolder, $"*.{InterpolateUtils.GetOutExt()}").ToList(), Padding.interpFrames, encodedFrames);
//string[] interpFrames = IOUtils.GetFilesSorted(interpFramesFolder, $"*.{InterpolateUtils.GetOutExt()}");
//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(); unencodedFrameLines.Clear();
@@ -94,12 +89,11 @@ namespace Flowframes.Main
{ {
foreach (int frame in frameLinesToEncode) foreach (int frame in frameLinesToEncode)
{ {
// Make sure frames are no longer needed (e.g. for dupes) before deleting! if(!FrameIsStillNeeded(interpFramesLines[frame], frame)) // Make sure frames are no longer needed (e.g. for dupes) before deleting!
if(FrameIsStillNeeded(interpFramesLines[frame], frame)) {
continue; string framePath = Path.Combine(interpFramesPath, interpFramesLines[frame]);
File.WriteAllText(framePath, "THIS IS A DUMMY FILE - DO NOT DELETE ME"); // Overwrite to save space without breaking progress counter
string framePath = Path.Combine(interpFramesPath, interpFramesLines[frame]); }
File.WriteAllText(framePath, "THIS IS A DUMMY FILE - DO NOT DELETE ME"); // Overwrite to save space without breaking progress counter
} }
} }
@@ -116,19 +110,12 @@ namespace Flowframes.Main
if (Interpolate.canceled) return; if (Interpolate.canceled) return;
IOUtils.ReverseRenaming(AiProcess.filenameMap, true); // Get timestamps back IOUtils.ReverseRenaming(AiProcess.filenameMap, true); // Get timestamps back
await CreateVideo.ChunksToVideos(Interpolate.current.tempFolder, videoChunksFolder, Interpolate.current.outFilename); await CreateVideo.ChunksToVideos(Interpolate.current.tempFolder, videoChunksFolder, Interpolate.current.outFilename);
} }
static bool FrameIsStillNeeded (string frameName, int frameIndex) static bool FrameIsStillNeeded (string frameName, int frameIndex)
{ {
// for(int i = frameIndex + 1; i < interpFramesLines.Length; i++) if ((frameIndex + 1) < interpFramesLines.Length && interpFramesLines[frameIndex+1].Contains(frameName))
// {
// if (interpFramesLines[i].Contains(frameName))
// return true;
// }
if (interpFramesLines[frameIndex+1].Contains(frameName))
return true; return true;
return false; return false;
} }

View File

@@ -186,25 +186,19 @@ namespace Flowframes.Main
static async Task Loop(string outPath, int looptimes) static async Task Loop(string outPath, int looptimes)
{ {
Logger.Log($"Looping {looptimes} times to reach target length..."); Logger.Log($"Looping {looptimes} {(looptimes == 1 ? "time" : "times")} to reach target length of {Config.GetInt("minOutVidLength")}s...");
await FFmpegCommands.LoopVideo(outPath, looptimes, Config.GetInt("loopMode") == 0); await FFmpegCommands.LoopVideo(outPath, looptimes, Config.GetInt("loopMode") == 0);
} }
static int GetLoopTimes() static int GetLoopTimes()
{ {
//Logger.Log("Getting loop times for path " + framesOutPath);
int times = -1; int times = -1;
int minLength = Config.GetInt("minOutVidLength"); int minLength = Config.GetInt("minOutVidLength");
//Logger.Log("minLength: " + minLength);
int minFrameCount = (minLength * i.current.outFps).RoundToInt(); int minFrameCount = (minLength * i.current.outFps).RoundToInt();
//Logger.Log("minFrameCount: " + minFrameCount);
//int outFrames = new DirectoryInfo(framesOutPath).GetFiles($"*.{InterpolateUtils.GetExt()}", SearchOption.TopDirectoryOnly).Length;
int outFrames = i.currentInputFrameCount * i.current.interpFactor; int outFrames = i.currentInputFrameCount * i.current.interpFactor;
//Logger.Log("outFrames: " + outFrames);
if (outFrames / i.current.outFps < minLength) if (outFrames / i.current.outFps < minLength)
times = (int)Math.Ceiling((double)minFrameCount / (double)outFrames); times = (int)Math.Ceiling((double)minFrameCount / (double)outFrames);
//Logger.Log("times: " + times); times--; // Not counting the 1st play (0 loops)
times--; // Account for this calculation not counting the 1st play (0 loops)
if (times <= 0) return -1; // Never try to loop 0 times, idk what would happen, probably nothing if (times <= 0) return -1; // Never try to loop 0 times, idk what would happen, probably nothing
return times; return times;
} }
@@ -227,6 +221,7 @@ namespace Flowframes.Main
Logger.Log("No compatible audio stream found.", true); Logger.Log("No compatible audio stream found.", true);
return; return;
} }
await FFmpegCommands.MergeAudio(outVideo, IOUtils.GetAudioFile(audioFileBasePath)); // Merge from audioFile into outVideo await FFmpegCommands.MergeAudio(outVideo, IOUtils.GetAudioFile(audioFileBasePath)); // Merge from audioFile into outVideo
} }
catch (Exception e) catch (Exception e)

View File

@@ -134,9 +134,7 @@ namespace Flowframes.Main
public static int GetProgressWaitTime(int numFrames) public static int GetProgressWaitTime(int numFrames)
{ {
float hddMultiplier = 2f; float hddMultiplier = !Program.lastInputPathIsSsd ? 2f : 1f;
if (Program.lastInputPathIsSsd)
hddMultiplier = 1f;
int waitMs = 200; int waitMs = 200;
@@ -158,12 +156,16 @@ namespace Flowframes.Main
public static string GetTempFolderLoc (string inPath, string outPath) public static string GetTempFolderLoc (string inPath, string outPath)
{ {
string basePath = inPath.GetParentDir(); string basePath = inPath.GetParentDir();
if(Config.GetInt("tempFolderLoc") == 1) if(Config.GetInt("tempFolderLoc") == 1)
basePath = outPath.GetParentDir(); basePath = outPath.GetParentDir();
if (Config.GetInt("tempFolderLoc") == 2) if (Config.GetInt("tempFolderLoc") == 2)
basePath = outPath; basePath = outPath;
if (Config.GetInt("tempFolderLoc") == 3) if (Config.GetInt("tempFolderLoc") == 3)
basePath = IOUtils.GetExeDir(); basePath = IOUtils.GetExeDir();
if (Config.GetInt("tempFolderLoc") == 4) if (Config.GetInt("tempFolderLoc") == 4)
{ {
string custPath = Config.Get("tempDirCustom"); string custPath = Config.Get("tempDirCustom");

View File

@@ -51,7 +51,7 @@ namespace Flowframes
processTime.Stop(); processTime.Stop();
while (Interpolate.currentlyUsingAutoEnc && Program.busy) while (Interpolate.currentlyUsingAutoEnc && Program.busy)
{ {
if(AvProcess.lastProcess != null && !AvProcess.lastProcess.HasExited && AvProcess.lastTask == AvProcess.TaskType.Encode) if (AvProcess.lastProcess != null && !AvProcess.lastProcess.HasExited && AvProcess.lastTask == AvProcess.TaskType.Encode)
{ {
string lastLine = AvProcess.lastOutputFfmpeg.SplitIntoLines().Last(); string lastLine = AvProcess.lastOutputFfmpeg.SplitIntoLines().Last();
Logger.Log(lastLine.Trim().TrimWhitespaces(), false, Logger.GetLastLine().Contains("frame")); Logger.Log(lastLine.Trim().TrimWhitespaces(), false, Logger.GetLastLine().Contains("frame"));