Allow UpdateLastFrameFromInterpOutput to fail

This commit is contained in:
N00MKRAD
2021-02-12 00:44:37 +01:00
parent 3e676807a9
commit 2db104f5f1
2 changed files with 27 additions and 23 deletions

View File

@@ -14,7 +14,7 @@ using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using i = Flowframes.Interpolate;
using I = Flowframes.Interpolate;
using Padding = Flowframes.Data.Padding;
namespace Flowframes.Main
@@ -29,20 +29,20 @@ namespace Flowframes.Main
try
{
lastFrameNum--; // We have to do this as extracted frames start at 0, not 1
bool frameFolderInput = IOUtils.IsPathDirectory(i.current.inPath);
string targetPath = Path.Combine(i.current.framesFolder, lastFrameNum.ToString().PadLeft(Padding.inputFrames, '0') + ".png");
bool frameFolderInput = IOUtils.IsPathDirectory(I.current.inPath);
string targetPath = Path.Combine(I.current.framesFolder, lastFrameNum.ToString().PadLeft(Padding.inputFrames, '0') + ".png");
if (File.Exists(targetPath)) return;
Size res = IOUtils.GetImage(IOUtils.GetFilesSorted(i.current.framesFolder, false).First()).Size;
Size res = IOUtils.GetImage(IOUtils.GetFilesSorted(I.current.framesFolder, false).First()).Size;
if (frameFolderInput)
{
string lastFramePath = IOUtils.GetFilesSorted(i.current.inPath, false).Last();
string lastFramePath = IOUtils.GetFilesSorted(I.current.inPath, false).Last();
await FfmpegExtract.ExtractLastFrame(lastFramePath, targetPath, res);
}
else
{
await FfmpegExtract.ExtractLastFrame(i.current.inPath, targetPath, res);
await FfmpegExtract.ExtractLastFrame(I.current.inPath, targetPath, res);
}
}
catch (Exception e)
@@ -97,24 +97,28 @@ namespace Flowframes.Main
await Task.Delay(100);
}
progCheckRunning = false;
if (i.canceled)
if (I.canceled)
Program.mainForm.SetProgress(0);
}
public static void UpdateLastFrameFromInterpOutput(string output)
{
string ncnnStr = Interpolate.current.ai.aiName.Contains("NCNN") ? " done" : "";
Regex frameRegex = new Regex($@"(?<=.)\d*(?=.{GetOutExt()}{ncnnStr})");
if (!frameRegex.IsMatch(output)) return;
lastFrame = Math.Max(int.Parse(frameRegex.Match(output).Value), lastFrame);
try
{
string ncnnStr = I.current.ai.aiName.Contains("NCNN") ? " done" : "";
Regex frameRegex = new Regex($@"(?<=.)\d*(?=.{GetOutExt()}{ncnnStr})");
if (!frameRegex.IsMatch(output)) return;
lastFrame = Math.Max(int.Parse(frameRegex.Match(output).Value), lastFrame);
}
catch { }
}
public static int interpolatedInputFramesCount;
public static void UpdateInterpProgress(int frames, int target, string latestFramePath = "")
{
if (i.canceled) return;
interpolatedInputFramesCount = ((frames / i.current.interpFactor).RoundToInt() - 1);
if (I.canceled) return;
interpolatedInputFramesCount = ((frames / I.current.interpFactor).RoundToInt() - 1);
ResumeUtils.Save();
frames = frames.Clamp(0, target);
int percent = (int)Math.Round(((float)frames / target) * 100f);
@@ -152,7 +156,7 @@ namespace Flowframes.Main
public static async Task DeleteInterpolatedInputFrames()
{
interpolatedInputFramesCount = 0;
string[] inputFrames = IOUtils.GetFilesSorted(i.current.framesFolder);
string[] inputFrames = IOUtils.GetFilesSorted(I.current.framesFolder);
for (int i = 0; i < inputFrames.Length; i++)
{
@@ -277,7 +281,7 @@ namespace Flowframes.Main
ShowMessage("Interpolation factor is not valid!");
passes = false;
}
if (passes && outMode == i.OutMode.VidGif && fpsOut > 50 && Config.GetFloat("maxFps") != 0 && Config.GetFloat("maxFps") > 50)
if (passes && outMode == I.OutMode.VidGif && fpsOut > 50 && Config.GetFloat("maxFps") != 0 && Config.GetFloat("maxFps") > 50)
{
ShowMessage("Invalid output frame rate!\nGIF does not properly support frame rates above 50 FPS.\nPlease use MP4, WEBM or another video format.");
passes = false;
@@ -288,7 +292,7 @@ namespace Flowframes.Main
passes = false;
}
if (!passes)
i.Cancel("Invalid settings detected.", true);
I.Cancel("Invalid settings detected.", true);
return passes;
}
@@ -310,7 +314,7 @@ namespace Flowframes.Main
if (targetFrameCount > maxGifFrames)
{
ShowMessage($"You can't use GIF with more than {maxGifFrames} output frames!\nPlease use MP4 for this.", "Error");
i.Cancel($"Can't use GIF encoding with more than {maxGifFrames} frames!");
I.Cancel($"Can't use GIF encoding with more than {maxGifFrames} frames!");
}
}
@@ -319,7 +323,7 @@ namespace Flowframes.Main
if (!PkgUtils.IsAiAvailable(ai))
{
ShowMessage("The selected AI is not installed!\nYou can download it from the Package Installer.", "Error");
i.Cancel("Selected AI not available.", true);
I.Cancel("Selected AI not available.", true);
return false;
}
return true;
@@ -327,10 +331,10 @@ namespace Flowframes.Main
public static bool CheckDeleteOldTempFolder ()
{
if (!IOUtils.TryDeleteIfExists(i.current.tempFolder))
if (!IOUtils.TryDeleteIfExists(I.current.tempFolder))
{
ShowMessage("Failed to remove an existing temp folder of this video!\nMake sure you didn't open any frames in an editor.", "Error");
i.Cancel();
I.Cancel();
return false;
}
return true;
@@ -343,7 +347,7 @@ namespace Flowframes.Main
if (!IOUtils.IsDirValid(path))
{
ShowMessage("Input directory is not valid.");
i.Cancel();
I.Cancel();
return false;
}
}
@@ -447,7 +451,7 @@ namespace Flowframes.Main
public static async Task<bool> UseUHD ()
{
return (await GetOutputResolution(i.current.inPath, false)).Height >= Config.GetInt("uhdThresh");
return (await GetOutputResolution(I.current.inPath, false)).Height >= Config.GetInt("uhdThresh");
}
public static void FixConsecutiveSceneFrames (string sceneFramesPath, string sourceFramesPath)

View File

@@ -111,7 +111,7 @@ namespace Flowframes
frames = await ReadFrameCountFfprobeAsync(inputFile, Config.GetBool("ffprobeCountFrames")); // Try reading frame count with ffprobe
if (frames > 0) return frames;
Logger.Log($"Failed to get frame count using ffprobe (frames = {frames}). Trying to calculate with duration * fps.", true, false, "ffmpeg");
Logger.Log($"Failed to get frame count using ffprobe (frames = {frames}). Trying to read with ffmpeg.", true, false, "ffmpeg");
frames = await ReadFrameCountFfmpegAsync(inputFile); // Try reading frame count with ffmpeg
if (frames > 0) return frames;