From 597ec9b31d3b952032eef882205dd0a85997e6a6 Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Thu, 12 Nov 2020 14:31:25 +0100 Subject: [PATCH] FFmpeg / Gifski error handling, fixed unwrapped path for gifski --- Code/FFmpeg/FFmpeg.cs | 12 ++++++++++-- Code/IO/Installer.cs | 4 +++- Code/UI/VideoUpscaleUI.cs | 19 +++++++++++++------ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Code/FFmpeg/FFmpeg.cs b/Code/FFmpeg/FFmpeg.cs index 1c6c892..3a77733 100644 --- a/Code/FFmpeg/FFmpeg.cs +++ b/Code/FFmpeg/FFmpeg.cs @@ -26,7 +26,11 @@ public static async Task Run(string args) static void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine) { - Logger.Log("[FFmpeg] " + outLine.Data); + string line = outLine.Data; + if (outLine == null || line == null) return; + Logger.Log("[FFmpeg] " + line); + if (line.ToLower().Contains("error")) + Program.ShowMessage("FFmpeg Error:\n\n" + line); } public static async Task RunGifski (string args) @@ -47,7 +51,11 @@ public static async Task RunGifski (string args) static void OutputHandlerGifski (object sendingProcess, DataReceivedEventArgs outLine) { - Logger.Log("[gifski] " + outLine.Data); + string line = outLine.Data; + if (outLine == null || line == null) return; + Logger.Log("[gifski] " + line); + if (line.ToLower().Contains("error")) + Program.ShowMessage("Gifski Error:\n\n" + line); } public static string RunAndGetOutput (string args) diff --git a/Code/IO/Installer.cs b/Code/IO/Installer.cs index 0ccd2e7..20edf4a 100644 --- a/Code/IO/Installer.cs +++ b/Code/IO/Installer.cs @@ -179,6 +179,8 @@ public static bool Exists() public static void Uninstall (bool full) { + if (!Directory.Exists(IOUtils.GetAppDataDir())) + return; try { if (full) @@ -188,7 +190,7 @@ public static void Uninstall (bool full) } catch (Exception e) { - Logger.ErrorMessage("Failed to uninstall.\nClose Cupscale and try deleting %APPDATA%/Cupscale manually.", e); + Logger.ErrorMessage("Failed to uninstall.\nClose Cupscale and try deleting %APPDATA%/Cupscale manually.\n", e); } } } diff --git a/Code/UI/VideoUpscaleUI.cs b/Code/UI/VideoUpscaleUI.cs index 017cd71..5b5fd57 100644 --- a/Code/UI/VideoUpscaleUI.cs +++ b/Code/UI/VideoUpscaleUI.cs @@ -25,7 +25,7 @@ class VideoUpscaleUI static string currentInPath; static string currentParentDir; - static float currentFps; + static float fps; public static void Init(TextBox outDirBox, TextBox logTextbox, Label mainLabel, ComboBox outFormatBox) { @@ -97,8 +97,8 @@ public static async Task Run () static void LoadVideo () { IOUtils.ClearDir(Paths.framesOutPath); - currentFps = FFmpegCommands.GetFramerate(currentInPath); - Print("Detected frame rate of video as " + currentFps); + fps = FFmpegCommands.GetFramerate(currentInPath); + Print("Detected frame rate of video as " + fps); IOUtils.ClearDir(Paths.imgInPath); } @@ -144,7 +144,7 @@ static async Task CreateVideo () { DialogForm f = new DialogForm("Creating video from frames...", 300); await Task.Delay(10); - await FFmpegCommands.FramesToMp4(Paths.framesOutPath, Config.GetBool("h265"), Config.GetInt("crf"), currentFps, "", false); + await FFmpegCommands.FramesToMp4(Paths.framesOutPath, Config.GetBool("h265"), Config.GetInt("crf"), fps, "", false); f.Close(); } @@ -152,13 +152,20 @@ static async Task CreateVideo () { DialogForm f = new DialogForm("Creating GIF from frames...\nThis can take a while for high-resolution GIFs.", 600); await Task.Delay(10); - await FFmpeg.RunGifski($" -r {currentFps.RoundToInt()} -W 4096 -Q {Config.GetInt("gifskiQ")} -q -o {Path.Combine(IOUtils.GetAppDataDir(), "frames-out.mp4")} \"" + Paths.framesOutPath + "/\"*.\"png\""); + string outpath = Path.Combine(IOUtils.GetAppDataDir(), "frames-out.mp4").Wrap(); + await FFmpeg.RunGifski($" -r {fps.RoundToInt()} -W 4096 -Q {Config.GetInt("gifskiQ")} -q -o {outpath} \"{Paths.framesOutPath}/\"*.\"png\""); f.Close(); } } static void CopyBack (string path) { + if (!File.Exists(path)) + { + Print("No video file was created!"); + return; + } + string filename = Path.GetFileNameWithoutExtension(currentInPath); string ext = Path.GetExtension(path); string outPath = ""; @@ -178,7 +185,7 @@ static void CopyBack (string path) } catch (Exception e) { - Logger.ErrorMessage("Failed to move video file to output folder.\nMake sure no other programs are accessing files in that folder.", e); + Logger.ErrorMessage("Failed to move video file to output folder.\nMake sure no other programs are accessing files in that folder.\n", e); } }