mirror of
https://github.com/n00mkrad/flowframes.git
synced 2025-12-16 00:17:44 +01:00
Better py error handling, fixed input frames that are not divisible by 2
This commit is contained in:
@@ -10,6 +10,8 @@ namespace Flowframes
|
||||
class FFmpegCommands
|
||||
{
|
||||
static string videoEncArgs = "-pix_fmt yuv420p -movflags +faststart -vf \"crop = trunc(iw / 2) * 2:trunc(ih / 2) * 2\"";
|
||||
static string divisionFilter = "\"crop = trunc(iw / 2) * 2:trunc(ih / 2) * 2\"";
|
||||
static string pngComprArg = "-compression_level 3";
|
||||
|
||||
public static async Task VideoToFrames(string inputFile, string frameFolderPath, bool deDupe, bool delSrc)
|
||||
{
|
||||
@@ -22,8 +24,8 @@ namespace Flowframes
|
||||
if (size.Width > 1 && size.Height > 1) sizeStr = $"-s {size.Width}x{size.Height}";
|
||||
if (!Directory.Exists(frameFolderPath))
|
||||
Directory.CreateDirectory(frameFolderPath);
|
||||
string args = $"-i {inputFile.Wrap()} -compression_level 3 -vsync 0 -pix_fmt rgb24 {sizeStr} \"{frameFolderPath}/%08d.png\"";
|
||||
if(deDupe) args = $"-i {inputFile.Wrap()} -copyts -r 1000 -compression_level 3 -vsync 0 -frame_pts true -vf mpdecimate {sizeStr} \"{frameFolderPath}/%08d.png\"";
|
||||
string args = $"-i {inputFile.Wrap()} {pngComprArg} -vsync 0 -pix_fmt rgb24 -vf {divisionFilter} {sizeStr} \"{frameFolderPath}/%08d.png\"";
|
||||
if(deDupe) args = $"-i {inputFile.Wrap()} -copyts -r 1000 {pngComprArg} -vsync 0 -frame_pts true -vf mpdecimate,{divisionFilter} {sizeStr} \"{frameFolderPath}/%08d.png\"";
|
||||
await AvProcess.RunFfmpeg(args, AvProcess.LogMode.OnlyLastLine);
|
||||
await Task.Delay(1);
|
||||
if (delSrc)
|
||||
|
||||
@@ -128,9 +128,13 @@ namespace Flowframes
|
||||
outputTbox.Text = inputTbox.Text.Trim().GetParentDir();
|
||||
string path = inputTbox.Text.Trim();
|
||||
Program.lastInputPath = path;
|
||||
string fpsStr = "Not Found.";
|
||||
float fps = IOUtils.GetFpsFolderOrVideo(path);
|
||||
string fpsStr = fps.ToString();
|
||||
fpsInTbox.Text = fpsStr;
|
||||
if(fps > 0)
|
||||
{
|
||||
fpsStr = fps.ToString();
|
||||
fpsInTbox.Text = fpsStr;
|
||||
}
|
||||
Interpolate.SetFps(fps);
|
||||
Program.lastInputPathIsSsd = OSUtils.DriveIsSSD(path);
|
||||
if (!Program.lastInputPathIsSsd)
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Flowframes.Main
|
||||
return;
|
||||
if (IOUtils.GetAmountOfFiles(path, false, $"*.{InterpolateUtils.lastExt}") <= 1)
|
||||
{
|
||||
i.Cancel("Output folder does not contain frames - An error must have occured during interpolation!");
|
||||
i.Cancel("Output folder does not contain frames - An error must have occured during interpolation!", AiProcess.hasShownError);
|
||||
return;
|
||||
}
|
||||
await Task.Delay(10);
|
||||
|
||||
@@ -164,7 +164,7 @@ namespace Flowframes
|
||||
Program.mainForm.SetProgress(-1);
|
||||
}
|
||||
|
||||
public static void Cancel(string reason = "")
|
||||
public static void Cancel(string reason = "", bool noMsgBox = false)
|
||||
{
|
||||
if (AiProcess.currentAiProcess != null && !AiProcess.currentAiProcess.HasExited)
|
||||
OSUtils.KillProcessTree(AiProcess.currentAiProcess.Id);
|
||||
@@ -176,8 +176,9 @@ namespace Flowframes
|
||||
if(!Config.GetBool("keepTempFolder"))
|
||||
IOUtils.TryDeleteIfExists(currentTempDir);
|
||||
Program.mainForm.SetWorking(false);
|
||||
Program.mainForm.mainTabControl.SelectedIndex = 0;
|
||||
Logger.Log("Cancelled interpolation.");
|
||||
if (!string.IsNullOrWhiteSpace(reason))
|
||||
if (!string.IsNullOrWhiteSpace(reason) && !noMsgBox)
|
||||
Utils.ShowMessage($"Cancelled:\n\n{reason}");
|
||||
}
|
||||
|
||||
|
||||
@@ -22,22 +22,21 @@ namespace Flowframes.Main
|
||||
{
|
||||
string filename1 = frameFiles[i].Name;
|
||||
string filename2 = frameFiles[i + 1].Name;
|
||||
//Logger.Log("durationTotal = " + Path.GetFileNameWithoutExtension(filename2).GetInt() + " - " + Path.GetFileNameWithoutExtension(filename1).GetInt());
|
||||
int durationTotal = Path.GetFileNameWithoutExtension(filename2).GetInt() - Path.GetFileNameWithoutExtension(filename1).GetInt();
|
||||
lastFrameDuration = durationTotal;
|
||||
float durationPerInterpFrame = (float)durationTotal / interpFactor;
|
||||
//Logger.Log("durationPerInterpFrame = " + durationPerInterpFrame);
|
||||
int interpolatedFrameCount = interpFactor;
|
||||
|
||||
// If loop is enabled, account for the extra frame added to the end for loop continuity
|
||||
if (loopEnabled && i == (frameFiles.Length - 2))
|
||||
interpolatedFrameCount = interpolatedFrameCount * 2;
|
||||
|
||||
//Logger.Log("Frame " + i);
|
||||
|
||||
// Generate frames file lines
|
||||
for (int frm = 0; frm < interpolatedFrameCount; frm++)
|
||||
{
|
||||
//Logger.Log("Writing info for interp frame " + frm);
|
||||
string durationStr = (durationPerInterpFrame / 1000f).ToString("0.0000").Replace(",", ".");
|
||||
string durationStr = (durationPerInterpFrame / 1000f).ToString("0.00000").Replace(",", ".");
|
||||
File.AppendAllText(vfrFile, $"{totalFileCount.ToString().PadLeft(8, '0')}.png\nduration {durationStr}\n");
|
||||
totalFileCount++;
|
||||
}
|
||||
|
||||
@@ -15,14 +15,22 @@ namespace Flowframes
|
||||
{
|
||||
class AiProcess
|
||||
{
|
||||
public static bool hasShownError;
|
||||
|
||||
public static Process currentAiProcess;
|
||||
public static Stopwatch processTime = new Stopwatch();
|
||||
|
||||
static void Init (Process proc, string ext = "png")
|
||||
{
|
||||
InterpolateUtils.lastExt = ext;
|
||||
if (Config.GetBool("jpegInterps")) InterpolateUtils.lastExt = "jpg";
|
||||
processTime.Restart();
|
||||
currentAiProcess = proc;
|
||||
hasShownError = false;
|
||||
}
|
||||
|
||||
public static async Task RunDainNcnn(string framesPath, string outPath, int targetFrames, int tilesize)
|
||||
{
|
||||
InterpolateUtils.lastExt = "png";
|
||||
if (Config.GetBool("jpegInterps")) InterpolateUtils.lastExt = "jpg";
|
||||
|
||||
string args = $" -v -i {framesPath.Wrap()} -o {outPath.Wrap()} -n {targetFrames} -t {tilesize} -g {Config.Get("ncnnGpus")}";
|
||||
|
||||
string dainDir = Path.Combine(Paths.GetPkgPath(), Path.GetFileNameWithoutExtension(Packages.dainNcnn.fileName));
|
||||
@@ -35,8 +43,7 @@ namespace Flowframes
|
||||
dain.OutputDataReceived += (sender, outLine) => { LogOutput(outLine.Data, "dain-ncnn-log.txt"); };
|
||||
dain.ErrorDataReceived += (sender, outLine) => { LogOutput("[E] " + outLine.Data, "dain-ncnn-log.txt"); };
|
||||
}
|
||||
processTime.Restart();
|
||||
currentAiProcess = dain;
|
||||
Init(dain);
|
||||
dain.Start();
|
||||
if (!OSUtils.ShowHiddenCmd())
|
||||
{
|
||||
@@ -51,9 +58,6 @@ namespace Flowframes
|
||||
|
||||
public static async Task RunCainNcnnMulti (string framesPath, string outPath, int tilesize, int times)
|
||||
{
|
||||
InterpolateUtils.lastExt = "png";
|
||||
if (Config.GetBool("jpegInterps")) InterpolateUtils.lastExt = "jpg";
|
||||
|
||||
Logger.Log("Running CAIN...", false);
|
||||
|
||||
string args = $" -v -i {framesPath.Wrap()} -o {outPath.Wrap()} -t {tilesize} -g {Config.Get("ncnnGpus")}";
|
||||
@@ -99,8 +103,7 @@ namespace Flowframes
|
||||
cain.OutputDataReceived += (sender, outLine) => { LogOutput(outLine.Data, "cain-ncnn-log.txt"); };
|
||||
cain.ErrorDataReceived += (sender, outLine) => { LogOutput("[E] " + outLine.Data, "cain-ncnn-log.txt"); };
|
||||
}
|
||||
processTime.Restart();
|
||||
currentAiProcess = cain;
|
||||
Init(cain);
|
||||
cain.Start();
|
||||
if (!OSUtils.ShowHiddenCmd())
|
||||
{
|
||||
@@ -113,9 +116,6 @@ namespace Flowframes
|
||||
|
||||
public static async Task RunRifeCuda(string framesPath, int interpFactor)
|
||||
{
|
||||
InterpolateUtils.lastExt = "png";
|
||||
if (Config.GetBool("jpegInterps")) InterpolateUtils.lastExt = "jpg";
|
||||
|
||||
string script = "interp-parallel.py";
|
||||
if(Config.GetInt("rifeMode") == 0 || IOUtils.GetAmountOfFiles(framesPath, false) < 30)
|
||||
script = "interp-basic.py";
|
||||
@@ -132,8 +132,7 @@ namespace Flowframes
|
||||
rifePy.OutputDataReceived += (sender, outLine) => { LogOutput(outLine.Data, "rife-cuda-log.txt"); };
|
||||
rifePy.ErrorDataReceived += (sender, outLine) => { LogOutput("[E] " + outLine.Data, "rife-cuda-log.txt"); };
|
||||
}
|
||||
processTime.Restart();
|
||||
currentAiProcess = rifePy;
|
||||
Init(rifePy);
|
||||
rifePy.Start();
|
||||
if (!OSUtils.ShowHiddenCmd())
|
||||
{
|
||||
@@ -153,14 +152,32 @@ namespace Flowframes
|
||||
|
||||
Logger.LogToFile(line, false, logFilename);
|
||||
|
||||
if (line.ToLower().Contains("modulenotfounderror"))
|
||||
InterpolateUtils.ShowMessage($"A python module is missing. Check {logFilename} for details.\n\n{line}", "Error");
|
||||
if (!hasShownError && line.ToLower().Contains("out of memory"))
|
||||
{
|
||||
hasShownError = true;
|
||||
InterpolateUtils.ShowMessage($"Your GPU ran out of VRAM! Please try a video with a lower resolution or use the Max Video Size option in the settings.\n\n{line}", "Error");
|
||||
}
|
||||
|
||||
if (line.ToLower().Contains("ff:nocuda-cpu"))
|
||||
if (!hasShownError && line.ToLower().Contains("modulenotfounderror"))
|
||||
{
|
||||
hasShownError = true;
|
||||
InterpolateUtils.ShowMessage($"A python module is missing. Check {logFilename} for details.\n\n{line}", "Error");
|
||||
}
|
||||
|
||||
if (!hasShownError && line.ToLower().Contains("ff:nocuda-cpu"))
|
||||
Logger.Log($"WARNING: CUDA-capable GPU device is not available, running on CPU instead!");
|
||||
|
||||
if (line.ToLower().Contains("no longer supports this gpu"))
|
||||
if (!hasShownError && line.ToLower().Contains("no longer supports this gpu"))
|
||||
{
|
||||
hasShownError = true;
|
||||
InterpolateUtils.ShowMessage("Your GPU seems to be outdated and is not supported!\n\n{line}", "Error");
|
||||
}
|
||||
|
||||
if (!hasShownError && line.Contains("RuntimeError"))
|
||||
{
|
||||
hasShownError = true;
|
||||
InterpolateUtils.ShowMessage($"An error occured during interpolation!\n\n{line}", "Error");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user