Skip to content

Commit dfde17a

Browse files
committed
Show message box for all ffmpeg errors
1 parent d47fd6b commit dfde17a

File tree

3 files changed

+39
-24
lines changed

3 files changed

+39
-24
lines changed

ff-utils-winforms/Main/RunTask.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ public static void Cancel(string reason = "", bool noMsgBox = false)
4242
Logger.LogIfLastLineDoesNotContainMsg("Canceled.");
4343

4444
if (!string.IsNullOrWhiteSpace(reason) && !noMsgBox)
45-
MessageBox.Show($"Canceled:\n\n{reason}", "Message");
45+
System.Windows.Forms.MessageBox.Show($"Canceled:\n\n{reason}", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.ServiceNotification);
4646
}
4747

48-
public static async Task Start (TaskType batchTask = TaskType.Null)
48+
public static async Task Start(TaskType batchTask = TaskType.Null)
4949
{
5050
if (batchTask == TaskType.Null)
5151
runningBatch = false;
@@ -69,7 +69,7 @@ public static async Task Start (TaskType batchTask = TaskType.Null)
6969

7070
if (taskType == TaskType.None)
7171
{
72-
if(!RunInstantly())
72+
if (!RunInstantly())
7373
MessageBox.Show("No task selected! Please select an option (Quick Encode or one of the actions in Utilities).", "Error");
7474

7575
return;
@@ -93,7 +93,7 @@ public static async Task Start (TaskType batchTask = TaskType.Null)
9393
Program.mainForm.SetWorking(false);
9494
}
9595

96-
public static async Task StartBatch ()
96+
public static async Task StartBatch()
9797
{
9898
TaskType batchTask = Program.mainForm.GetCurrentTaskType();
9999

@@ -125,7 +125,7 @@ public static async Task StartBatch ()
125125
Logger.Log($"Queue: Completed {taskItems.Length} tasks.");
126126
}
127127

128-
public static bool RunInstantly ()
128+
public static bool RunInstantly()
129129
{
130130
return Config.GetInt("taskMode") == 1;
131131
}

ff-utils-winforms/Media/AvProcess.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ public static async Task<string> RunFfmpeg(string args, string workingDir, LogMo
8383

8484
if (!show)
8585
{
86-
ffmpeg.OutputDataReceived += (sender, outLine) => { FfmpegOutputHandler.LogOutput(outLine.Data, ref processOutput, "ffmpeg", logMode, progressBar); timeSinceLastOutput.sw.Restart(); };
87-
ffmpeg.ErrorDataReceived += (sender, outLine) => { FfmpegOutputHandler.LogOutput(outLine.Data, ref processOutput, "ffmpeg", logMode, progressBar); timeSinceLastOutput.sw.Restart(); };
86+
string[] ignore = GetIgnoreStringsFromFfmpegCmd(args);
87+
ffmpeg.OutputDataReceived += (sender, outLine) => { FfmpegOutputHandler.LogOutput(outLine.Data, ignore, ref processOutput, "ffmpeg", logMode, progressBar); timeSinceLastOutput.sw.Restart(); };
88+
ffmpeg.ErrorDataReceived += (sender, outLine) => { FfmpegOutputHandler.LogOutput(outLine.Data, ignore, ref processOutput, "ffmpeg", logMode, progressBar); timeSinceLastOutput.sw.Restart(); };
8889
}
8990

9091
ffmpeg.Start();
@@ -105,6 +106,15 @@ public static async Task<string> RunFfmpeg(string args, string workingDir, LogMo
105106
return processOutput;
106107
}
107108

109+
private static string[] GetIgnoreStringsFromFfmpegCmd (string cmd)
110+
{
111+
string inputPath = cmd.Split(" -i ")[1].Split("\"")[1].Trim();
112+
string[] splitByQuotes = cmd.Split("\"");
113+
string outPath = splitByQuotes[splitByQuotes.Length - 2];
114+
Logger.Log($"Filtering out input path ({inputPath}) and output path ({outPath})");
115+
return new string[] { inputPath, outPath };
116+
}
117+
108118
public static async Task<string> GetFfmpegOutputAsync(string args, bool setBusy = false, bool progressBar = false)
109119
{
110120
if (setBusy) Program.mainForm.SetWorking(true);
@@ -131,8 +141,9 @@ public static async Task<string> RunFfprobe(string args, LogMode logMode = LogMo
131141

132142
if (!show)
133143
{
134-
ffprobe.OutputDataReceived += (sender, outLine) => { FfmpegOutputHandler.LogOutput(outLine.Data, ref processOutput, "ffmpeg", logMode, false); timeSinceLastOutput.sw.Restart(); };
135-
ffprobe.ErrorDataReceived += (sender, outLine) => { FfmpegOutputHandler.LogOutput(outLine.Data, ref processOutput, "ffmpeg", logMode, false); timeSinceLastOutput.sw.Restart(); };
144+
string[] ignore = new string[0];
145+
ffprobe.OutputDataReceived += (sender, outLine) => { FfmpegOutputHandler.LogOutput(outLine.Data, ignore, ref processOutput, "ffmpeg", logMode, false); timeSinceLastOutput.sw.Restart(); };
146+
ffprobe.ErrorDataReceived += (sender, outLine) => { FfmpegOutputHandler.LogOutput(outLine.Data, ignore, ref processOutput, "ffmpeg", logMode, false); timeSinceLastOutput.sw.Restart(); };
136147
}
137148

138149
ffprobe.Start();

ff-utils-winforms/Media/FfmpegOutputHandler.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Nmkoder.UI;
55
using Nmkoder.Utils;
66
using System;
7+
using System.Collections.Generic;
78
using System.Linq;
89
using System.Text.RegularExpressions;
910
using System.Threading.Tasks;
@@ -16,7 +17,7 @@ class FfmpegOutputHandler
1617
public static readonly string prefix = "[ffmpeg]";
1718
public static long overrideTargetDurationMs = -1;
1819

19-
public static void LogOutput(string line, ref string appendStr, string logFilename, LogMode logMode, bool showProgressBar)
20+
public static void LogOutput(string line, string[] ignoreStrings, ref string appendStr, string logFilename, LogMode logMode, bool showProgressBar)
2021
{
2122
if (RunTask.canceled || string.IsNullOrWhiteSpace(line) || line.Trim().Length < 1)
2223
return;
@@ -40,62 +41,65 @@ public static void LogOutput(string line, ref string appendStr, string logFilena
4041
UpdateFfmpegProgress(timeRegex.Match(line).Value);
4142
}
4243

44+
string lineWithoutPath = RemoveStringsFromLine(line, ignoreStrings);
4345

44-
if (line.Contains("Unable to"))
46+
if (lineWithoutPath.Contains("Error ") || lineWithoutPath.Contains("Unable to ") || lineWithoutPath.Contains("Could not open file"))
4547
{
4648
RunTask.Cancel($"Error: {line}");
4749
return;
4850
}
4951

50-
if (line.Contains("Could not open file"))
51-
{
52-
RunTask.Cancel($"Error: {line}");
53-
return;
54-
}
55-
56-
if (line.Contains("No NVENC capable devices found") || line.MatchesWildcard("*nvcuda.dll*"))
52+
if (lineWithoutPath.Contains("No NVENC capable devices found") || lineWithoutPath.MatchesWildcard("*nvcuda.dll*"))
5753
{
5854
RunTask.Cancel($"Error: {line}\n\nMake sure you have an NVENC-capable Nvidia GPU.");
5955
return;
6056
}
6157

62-
if (line.Contains("not currently supported in container") || line.Contains("Unsupported codec id"))
58+
if (lineWithoutPath.Contains("not currently supported in container") || lineWithoutPath.Contains("Unsupported codec id"))
6359
{
6460
RunTask.Cancel($"Error: {line}\n\nIt looks like you are trying to copy a stream into a container that doesn't support this codec.");
6561
return;
6662
}
6763

68-
if (line.Contains("Subtitle encoding currently only possible from text to text or bitmap to bitmap"))
64+
if (lineWithoutPath.Contains("Subtitle encoding currently only possible from text to text or bitmap to bitmap"))
6965
{
7066
RunTask.Cancel($"Error: {line}\n\nYou cannot encode image-based subtitles into text-based subtitles. Please use the Copy Subtitles option instead, with a compatible container.");
7167
return;
7268
}
7369

74-
if (line.Contains("Only VP8 or VP9 or AV1 video and Vorbis or Opus audio and WebVTT subtitles are supported for WebM"))
70+
if (lineWithoutPath.Contains("Only VP8 or VP9 or AV1 video and Vorbis or Opus audio and WebVTT subtitles are supported for WebM"))
7571
{
7672
RunTask.Cancel($"Error: {line}\n\nIt looks like you are trying to copy an unsupported stream into WEBM!");
7773
return;
7874
}
7975

80-
if (line.MatchesWildcard("*codec*not supported*"))
76+
if (lineWithoutPath.MatchesWildcard("*codec*not supported*"))
8177
{
8278
RunTask.Cancel($"Error: {line}\n\nTry using a different codec.");
8379
return;
8480
}
8581

86-
if (line.Contains("GIF muxer supports only a single video GIF stream"))
82+
if (lineWithoutPath.Contains("GIF muxer supports only a single video GIF stream"))
8783
{
8884
RunTask.Cancel($"Error: {line}\n\nYou tried to mux a non-GIF stream into a GIF file.");
8985
return;
9086
}
9187

92-
if (line.Contains("Width and height of input videos must be same"))
88+
if (lineWithoutPath.Contains("Width and height of input videos must be same"))
9389
{
9490
RunTask.Cancel($"Error: {line}");
9591
return;
9692
}
9793
}
9894

95+
private static string RemoveStringsFromLine (string s, string[] ignoreStrings)
96+
{
97+
foreach(string ign in ignoreStrings)
98+
s = s.Replace(ign, "");
99+
100+
return s;
101+
}
102+
99103
static void UpdateFfmpegProgress(string ffmpegTime)
100104
{
101105
try

0 commit comments

Comments
 (0)