Skip to content

Commit

Permalink
FFmpeg / Gifski error handling, fixed unwrapped path for gifski
Browse files Browse the repository at this point in the history
  • Loading branch information
N00MKRAD committed Nov 12, 2020
1 parent 4479257 commit 597ec9b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
12 changes: 10 additions & 2 deletions Code/FFmpeg/FFmpeg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion Code/IO/Installer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ public static bool Exists()

public static void Uninstall (bool full)
{
if (!Directory.Exists(IOUtils.GetAppDataDir()))
return;
try
{
if (full)
Expand All @@ -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);
}
}
}
Expand Down
19 changes: 13 additions & 6 deletions Code/UI/VideoUpscaleUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -144,21 +144,28 @@ 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();
}

if (outputFormat == Upscale.VidExportMode.GIF)
{
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 = "";
Expand All @@ -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);
}
}

Expand Down

0 comments on commit 597ec9b

Please sign in to comment.