Fixed JPEG support with new RIFE code and AutoEnc

This commit is contained in:
N00MKRAD
2020-12-10 16:37:33 +01:00
parent f08f396486
commit c14cacc7d0
9 changed files with 33 additions and 29 deletions

View File

@@ -234,7 +234,7 @@
<Compile Include="Main\CreateVideo.cs" />
<Compile Include="Main\InterpolateSteps.cs" />
<Compile Include="Main\InterpolateUtils.cs" />
<Compile Include="Main\VfrDedupe.cs" />
<Compile Include="Main\FrameTiming.cs" />
<Compile Include="OS\AiProcess.cs" />
<Compile Include="ExtensionMethods.cs" />
<Compile Include="AudioVideo\AvProcess.cs" />

View File

@@ -211,7 +211,7 @@ namespace Flowframes.Magick
if (currentMode == Mode.None)
return;
string ext = InterpolateUtils.lastExt;
string ext = InterpolateUtils.GetExt();
string dupeInfoFile = Path.Combine(Interpolate.currentTempDir, "dupes.ini");
if (!File.Exists(dupeInfoFile)) return;

View File

@@ -48,8 +48,8 @@ namespace Flowframes.Main
continue;
}
IOUtils.ZeroPadDir(Directory.GetFiles(interpFramesFolder, $"*.{InterpolateUtils.lastExt}").ToList(), Padding.interpFrames, encodedFrames);
string[] interpFrames = Directory.GetFiles(interpFramesFolder, $"*.{InterpolateUtils.lastExt}");
IOUtils.ZeroPadDir(Directory.GetFiles(interpFramesFolder, $"*.{InterpolateUtils.GetExt()}").ToList(), Padding.interpFrames, encodedFrames);
string[] interpFrames = Directory.GetFiles(interpFramesFolder, $"*.{InterpolateUtils.GetExt()}");
unencodedFrames = interpFrames.ToList().Except(encodedFrames).ToList();
Directory.CreateDirectory(videoChunksFolder);
@@ -114,7 +114,7 @@ namespace Flowframes.Main
static int GetInterpFramesAmount()
{
return IOUtils.GetAmountOfFiles(interpFramesFolder, false, $"*.{InterpolateUtils.lastExt}");
return IOUtils.GetAmountOfFiles(interpFramesFolder, false, $"*.{InterpolateUtils.GetExt()}");
}
}
}

View File

@@ -38,9 +38,9 @@ namespace Flowframes.Main
}
//Logger.Log("zero-padding " + path);
//IOUtils.ZeroPadDir(path, $"*.{InterpolateUtils.lastExt}", Padding.interpFrames);
//IOUtils.ZeroPadDir(path, $"*.{InterpolateUtils.GetExt()}", Padding.interpFrames);
if (IOUtils.GetAmountOfFiles(path, false, $"*.{InterpolateUtils.lastExt}") <= 1)
if (IOUtils.GetAmountOfFiles(path, false, $"*.{InterpolateUtils.GetExt()}") <= 1)
{
i.Cancel("Output folder does not contain frames - An error must have occured during interpolation!", AiProcess.hasShownError);
return;
@@ -181,7 +181,7 @@ namespace Flowframes.Main
//Logger.Log("minLength: " + minLength);
int minFrameCount = (minLength * i.currentOutFps).RoundToInt();
//Logger.Log("minFrameCount: " + minFrameCount);
//int outFrames = new DirectoryInfo(framesOutPath).GetFiles($"*.{InterpolateUtils.lastExt}", SearchOption.TopDirectoryOnly).Length;
//int outFrames = new DirectoryInfo(framesOutPath).GetFiles($"*.{InterpolateUtils.GetExt()}", SearchOption.TopDirectoryOnly).Length;
int outFrames = i.currentInputFrameCount * i.lastInterpFactor;
//Logger.Log("outFrames: " + outFrames);
if (outFrames / i.currentOutFps < minLength)

View File

@@ -30,8 +30,9 @@ namespace Flowframes.Main
Logger.Log("Timestamps are disabled, using static frame rate.");
bool sceneDetection = true;
string ext = InterpolateUtils.GetExt();
FileInfo[] frameFiles = new DirectoryInfo(framesPath).GetFiles("*.png");
FileInfo[] frameFiles = new DirectoryInfo(framesPath).GetFiles($"*.png");
string vfrFile = Path.Combine(framesPath.GetParentDir(), $"vfr-{interpFactor}x.ini");
string fileContent = "";
@@ -83,14 +84,14 @@ namespace Flowframes.Main
int lastNum = totalFileCount;
// Logger.Log($"Writing frame {totalFileCount} [Discarding Next]", true);
fileContent += $"file '{interpPath}/{totalFileCount.ToString().PadLeft(Padding.interpFrames, '0')}.png'\nduration {durationStr}\n";
fileContent += $"file '{interpPath}/{totalFileCount.ToString().PadLeft(Padding.interpFrames, '0')}.{ext}'\nduration {durationStr}\n";
totalFileCount++;
// 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}");
fileContent += $"file '{interpPath}/{lastNum.ToString().PadLeft(Padding.interpFrames, '0')}.png'\nduration {durationStr}\n";
fileContent += $"file '{interpPath}/{lastNum.ToString().PadLeft(Padding.interpFrames, '0')}.{ext}'\nduration {durationStr}\n";
totalFileCount++;
}
@@ -99,7 +100,7 @@ namespace Flowframes.Main
else
{
//Logger.Log($"Writing frame {totalFileCount}", true, false);
fileContent += $"file '{interpPath}/{totalFileCount.ToString().PadLeft(Padding.interpFrames, '0')}.png'\nduration {durationStr}\n";
fileContent += $"file '{interpPath}/{totalFileCount.ToString().PadLeft(Padding.interpFrames, '0')}.{ext}'\nduration {durationStr}\n";
totalFileCount++;
}
}
@@ -110,7 +111,7 @@ namespace Flowframes.Main
//Logger.Log($"Writing last frame: {totalFileCount}", true, false);
string durationStrLast = ((100f / interpFactor / 1000f) * 1).ToString("0.00000", CultureInfo.InvariantCulture);
fileContent += $"file '{interpPath}/{totalFileCount.ToString().PadLeft(Padding.interpFrames, '0')}.png'\nduration {durationStrLast}\n";
fileContent += $"file '{interpPath}/{totalFileCount.ToString().PadLeft(Padding.interpFrames, '0')}.{ext}'\nduration {durationStrLast}\n";
totalFileCount++;
File.WriteAllText(vfrFile, fileContent);
@@ -121,7 +122,7 @@ namespace Flowframes.Main
{
int lastFileNumber = frameFiles.Last().Name.GetInt();
lastFileNumber += lastFrameDuration;
string loopFrameTargetPath = Path.Combine(frameFiles.First().FullName.GetParentDir(), lastFileNumber.ToString().PadLeft(Padding.inputFrames, '0') + ".png");
string loopFrameTargetPath = Path.Combine(frameFiles.First().FullName.GetParentDir(), lastFileNumber.ToString().PadLeft(Padding.inputFrames, '0') + ".{ext}");
if (File.Exists(loopFrameTargetPath))
return;
File.Copy(frameFiles.First().FullName, loopFrameTargetPath);

View File

@@ -213,7 +213,7 @@ namespace Flowframes
if (firstProgUpd && Program.mainForm.IsInFocus())
Program.mainForm.SetTab("preview");
firstProgUpd = false;
string[] frames = Directory.GetFiles(outdir, $"*.{Utils.lastExt}");
string[] frames = Directory.GetFiles(outdir, $"*.{Utils.GetExt()}");
if (frames.Length > 1)
Utils.UpdateInterpProgress(frames.Length, target, frames[frames.Length - 1]);
await Task.Delay(Utils.GetProgressWaitTime(frames.Length));

View File

@@ -173,7 +173,7 @@ namespace Flowframes.Main
public static async Task CreateOutputVid()
{
string[] outFrames = Directory.GetFiles(currentInterpFramesDir, $"*.{InterpolateUtils.lastExt}");
string[] outFrames = Directory.GetFiles(currentInterpFramesDir, $"*.{InterpolateUtils.GetExt()}");
if (outFrames.Length > 0 && !IOUtils.CheckImageValid(outFrames[0]))
{
InterpolateUtils.ShowMessage("Invalid frame files detected!\n\nIf you used Auto-Encode, this is normal, and you don't need to run " +

View File

@@ -19,7 +19,12 @@ namespace Flowframes.Main
public static PictureBox preview;
public static BigPreviewForm bigPreviewForm;
public static string lastExt = "png";
public static string GetExt ()
{
if (Config.GetBool("jpegInterps"))
return "jpg";
return "png";
}
public static void UpdateInterpProgress(int frames, int target, string latestFramePath = "")
{

View File

@@ -26,11 +26,9 @@ namespace Flowframes
public static Dictionary<string, string> filenameMap = new Dictionary<string, string>(); // TODO: Store on disk instead for crashes?
static void AiStarted (Process proc, int startupTimeMs, string defaultExt = "png")
static void AiStarted (Process proc, int startupTimeMs)
{
lastStartupTimeMs = startupTimeMs;
InterpolateUtils.lastExt = defaultExt;
if (Config.GetBool("jpegInterps")) InterpolateUtils.lastExt = "jpg";
processTime.Restart();
currentAiProcess = proc;
hasShownError = false;
@@ -53,7 +51,7 @@ namespace Flowframes
string dainDir = Path.Combine(Paths.GetPkgPath(), Path.GetFileNameWithoutExtension(Packages.dainNcnn.fileName));
Process dain = OSUtils.NewProcess(!OSUtils.ShowHiddenCmd());
AiStarted(dain, 1500);
dain.StartInfo.Arguments = $"{OSUtils.GetCmdArg()} cd /D {dainDir.Wrap()} & dain-ncnn-vulkan.exe {args} -f {InterpolateUtils.lastExt} -j {GetNcnnThreads()}";
dain.StartInfo.Arguments = $"{OSUtils.GetCmdArg()} cd /D {dainDir.Wrap()} & dain-ncnn-vulkan.exe {args} -f {InterpolateUtils.GetExt()} -j {GetNcnnThreads()}";
Logger.Log("Running DAIN...", false);
Logger.Log("cmd.exe " + dain.StartInfo.Arguments, true);
if (!OSUtils.ShowHiddenCmd())
@@ -73,7 +71,7 @@ namespace Flowframes
if (Interpolate.canceled) return;
if (!Interpolate.currentlyUsingAutoEnc)
IOUtils.ZeroPadDir(outPath, InterpolateUtils.lastExt, Padding.interpFrames);
IOUtils.ZeroPadDir(outPath, InterpolateUtils.GetExt(), Padding.interpFrames);
AiFinished("DAIN");
}
@@ -115,7 +113,7 @@ namespace Flowframes
if (Interpolate.canceled) return;
if (!Interpolate.currentlyUsingAutoEnc)
IOUtils.ZeroPadDir(outPath, InterpolateUtils.lastExt, Padding.interpFrames);
IOUtils.ZeroPadDir(outPath, InterpolateUtils.GetExt(), Padding.interpFrames);
AiFinished("CAIN");
}
@@ -126,7 +124,7 @@ namespace Flowframes
string cainExe = "cain-ncnn-vulkan.exe";
Process cain = OSUtils.NewProcess(!OSUtils.ShowHiddenCmd());
AiStarted(cain, 1500);
cain.StartInfo.Arguments = $"{OSUtils.GetCmdArg()} cd /D {cainDir.Wrap()} & {cainExe} {args} -f {InterpolateUtils.lastExt} -j {GetNcnnThreads()}";
cain.StartInfo.Arguments = $"{OSUtils.GetCmdArg()} cd /D {cainDir.Wrap()} & {cainExe} {args} -f {InterpolateUtils.GetExt()} -j {GetNcnnThreads()}";
Logger.Log("cmd.exe " + cain.StartInfo.Arguments, true);
if (!OSUtils.ShowHiddenCmd())
{
@@ -159,9 +157,9 @@ namespace Flowframes
}
Process rifePy = OSUtils.NewProcess(!OSUtils.ShowHiddenCmd());
AiStarted(rifePy, 3500, "png");
AiStarted(rifePy, 3500);
rifePy.StartInfo.Arguments = $"{OSUtils.GetCmdArg()} cd /D {PkgUtils.GetPkgFolder(Packages.rifeCuda).Wrap()} & " +
$"set CUDA_VISIBLE_DEVICES={Config.Get("torchGpus")} & {Pytorch.GetPyCmd()} {script} {args} --imgformat {InterpolateUtils.lastExt} --output {Paths.interpDir}";
$"set CUDA_VISIBLE_DEVICES={Config.Get("torchGpus")} & {Pytorch.GetPyCmd()} {script} {args} --imgformat {InterpolateUtils.GetExt()} --output {Paths.interpDir}";
Logger.Log($"Running RIFE ({script})...", false);
Logger.Log("cmd.exe " + rifePy.StartInfo.Arguments, true);
if (!OSUtils.ShowHiddenCmd())
@@ -225,8 +223,8 @@ namespace Flowframes
if (!Interpolate.currentlyUsingAutoEnc)
{
Logger.Log($"zero padding {outPath} with ext \"{InterpolateUtils.lastExt}\" to length {Padding.interpFrames}");
IOUtils.ZeroPadDir(outPath, InterpolateUtils.lastExt, Padding.interpFrames);
Logger.Log($"zero padding {outPath} with ext \"{InterpolateUtils.GetExt()}\" to length {Padding.interpFrames}");
IOUtils.ZeroPadDir(outPath, InterpolateUtils.GetExt(), Padding.interpFrames);
}
AiFinished("RIFE");
@@ -236,7 +234,7 @@ namespace Flowframes
{
Process rifeNcnn = OSUtils.NewProcess(!OSUtils.ShowHiddenCmd());
AiStarted(rifeNcnn, 1500);
rifeNcnn.StartInfo.Arguments = $"{OSUtils.GetCmdArg()} cd /D {PkgUtils.GetPkgFolder(Packages.rifeNcnn).Wrap()} & rife-ncnn-vulkan.exe {args} -g {Config.Get("ncnnGpus")} -f {InterpolateUtils.lastExt} -j {GetNcnnThreads()}";
rifeNcnn.StartInfo.Arguments = $"{OSUtils.GetCmdArg()} cd /D {PkgUtils.GetPkgFolder(Packages.rifeNcnn).Wrap()} & rife-ncnn-vulkan.exe {args} -g {Config.Get("ncnnGpus")} -f {InterpolateUtils.GetExt()} -j {GetNcnnThreads()}";
Logger.Log("cmd.exe " + rifeNcnn.StartInfo.Arguments, true);
if (!OSUtils.ShowHiddenCmd())
{