Skip to content

Commit c0bf6ab

Browse files
committed
Better mkvmerge logging
1 parent f4aba33 commit c0bf6ab

File tree

8 files changed

+25
-12
lines changed

8 files changed

+25
-12
lines changed

ff-utils-winforms/IO/Logger.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class Logger
1919
public const string defaultLogName = "sessionlog";
2020
public static long id;
2121

22+
public static string LastLine { get { return GetLastLine(); } }
23+
2224
public struct LogEntry
2325
{
2426
public string logMessage;
@@ -147,11 +149,13 @@ public static void ClearLogBox()
147149
textbox.Text = "";
148150
}
149151

150-
public static string GetLastLine()
152+
private static string GetLastLine()
151153
{
152154
string[] lines = textbox.Text.SplitIntoLines();
155+
153156
if (lines.Length < 1)
154157
return "";
158+
155159
return lines.Last();
156160
}
157161

ff-utils-winforms/Media/Av1anOutputHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static async Task ParseProgressLoop()
9797

9898
string etaStr = encodedChunks > workers ? $" ETA: <{FormatUtils.Time(new TimeSpan(0, 0, etaSecs), false)}" : "";
9999

100-
Logger.Log($"AV1AN is running - Encoded {encodedChunks}/{currentQueueSize} chunks ({ratio}%).{etaStr}", false, Logger.GetLastLine().Contains("Encoded"));
100+
Logger.Log($"AV1AN is running - Encoded {encodedChunks}/{currentQueueSize} chunks ({ratio}%).{etaStr}", false, Logger.LastLine.Contains("Encoded"));
101101

102102
for (int i = 100; i > 0; i--)
103103
{

ff-utils-winforms/Media/AvProcess.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,17 @@ public static async Task<string> RunMkvMerge(string args, bool log = false)
274274

275275
Logger.Log($"mkvmerge {args}", true, false, "mkvmerge");
276276

277-
mkvm.OutputDataReceived += (sender, outLine) => { processOutput += Environment.NewLine + outLine.Data; Logger.Log($"[mkvmerge] {outLine.Data}", !log, false, "mkvmerge"); };
278-
mkvm.ErrorDataReceived += (sender, outLine) => { processOutput += Environment.NewLine + outLine.Data; };
277+
mkvm.OutputDataReceived += (sender, outLine) => {
278+
string s = (outLine != null && outLine.Data != null) ? outLine.Data : "";
279+
processOutput += Environment.NewLine + s;
280+
Logger.Log($"[mkvmerge] {s}", !log || s.Trim().Length < 1, Logger.LastLine.Trim().EndsWith("%"), "mkvmerge");
281+
};
282+
283+
mkvm.ErrorDataReceived += (sender, outLine) => {
284+
string s = (outLine != null && outLine.Data != null) ? outLine.Data : "";
285+
processOutput += Environment.NewLine + s;
286+
Logger.Log($"[mkvmerge] [E] {s}", !log || s.Trim().Length < 1, false, "mkvmerge");
287+
};
279288

280289
mkvm.Start();
281290
mkvm.PriorityClass = ProcessPriorityClass.BelowNormal;

ff-utils-winforms/Media/FfmpegCommands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static async Task ConcatVideos(string concatFile, string outPath, int loo
3939
Logger.Log($"ConcatVideos('{Path.GetFileName(concatFile)}', '{outPath}', {looptimes})", true, false, "ffmpeg");
4040

4141
if(showLog)
42-
Logger.Log($"Merging videos...", false, Logger.GetLastLine().Contains("frame"));
42+
Logger.Log($"Merging videos...", false, Logger.LastLine.Contains("frame"));
4343

4444
IoUtils.RenameExistingFile(outPath);
4545
string loopStr = (looptimes > 0) ? $"-stream_loop {looptimes}" : "";

ff-utils-winforms/Media/FfmpegUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public static async Task<string> GetCurrentAutoCrop(string path, bool quiet)
203203
string chosen = commonCertainty > 85 ? mostCommon : largest; // Use most common if it's >85% common, otherwise use largest to be safe (thanks Nolan)
204204
Logger.Log($"GetCurrentAutoCrop - Largest: {largest} - Smallest: {detectedCrops.Last()} - Most Common: {mostCommon} ({commonCertainty}%) - Chosen: {chosen} [T = {sw}]", true);
205205
string[] cropVals = chosen.Split(':');
206-
bool repl = Logger.GetLastLine().Contains(msg);
206+
bool repl = Logger.LastLine.Contains(msg);
207207
Logger.Log($"Automatically detected crop: {cropVals[0]}x{cropVals[1]} (X = {cropVals[2]}, Y = {cropVals[3]})", quiet, !quiet && repl);
208208

209209
return $"crop={chosen}";

ff-utils-winforms/Media/OcrProcess.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public static void LogOutput(string line, bool hidden, bool trackProg, string ar
9696

9797
if (!hidden)
9898
{
99-
Logger.Log($"Running Optical Character Recognition: {percent}%", false, Logger.GetLastLine().EndsWith("%"));
99+
Logger.Log($"Running Optical Character Recognition: {percent}%", false, Logger.LastLine.EndsWith("%"));
100100
Program.mainForm.SetProgress(percent);
101101
}
102102

ff-utils-winforms/Media/OcrUtils.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static async Task<bool> RunOcrOnStreams(string inPath, List<SubtitleStrea
5252
int progSum = progressTracker.Select(x => x.Value).Sum();
5353
int avgProg = ((float)progSum / progressTracker.Count).RoundToInt();
5454
int running = progressTracker.Where(x => x.Value < 100).Count();
55-
Logger.Log($"Running {running} OCR Instances - Average Progress: {avgProg}%", false, Logger.GetLastLine().EndsWith("%"));
55+
Logger.Log($"Running {running} OCR Instances - Average Progress: {avgProg}%", false, Logger.LastLine.EndsWith("%"));
5656
Program.mainForm.SetProgress(avgProg);
5757

5858
if (RunTask.canceled)
@@ -62,7 +62,7 @@ public static async Task<bool> RunOcrOnStreams(string inPath, List<SubtitleStrea
6262
await Task.Delay(100);
6363
}
6464

65-
Logger.Log($"All OCR processes have finished.", false, Logger.GetLastLine().EndsWith("%"));
65+
Logger.Log($"All OCR processes have finished.", false, Logger.LastLine.EndsWith("%"));
6666

6767
return true;
6868
}
@@ -169,7 +169,7 @@ static void PostprocessAndMove(FileInfo file, int subIndex, SubtitleStream ss, s
169169
// int progSum = progressTracker.Select(x => x.Value).Sum();
170170
// int avgProg = ((float)progSum / progressTracker.Count).RoundToInt();
171171
// int running = progressTracker.Where(x => x.Value < 100).Count();
172-
// Logger.Log($"Running {running} OCR Instances - Progress: {avgProg}%", false, Logger.GetLastLine().EndsWith("%"));
172+
// Logger.Log($"Running {running} OCR Instances - Progress: {avgProg}%", false, Logger.LastLine.EndsWith("%"));
173173
// Program.mainForm.SetProgress(avgProg);
174174
//
175175
// if (RunTask.canceled || progressTracker.All(x => x.Value == 100))
@@ -180,7 +180,7 @@ static void PostprocessAndMove(FileInfo file, int subIndex, SubtitleStream ss, s
180180
// }
181181
//
182182
// double speed = ((double)mediaFile.DurationMs / sw.ElapsedMs);
183-
// Logger.Log($"Finished OCR conversion in {sw} ({speed.ToString("0.0")}x Realtime).", false, Logger.GetLastLine().EndsWith("%"));
183+
// Logger.Log($"Finished OCR conversion in {sw} ({speed.ToString("0.0")}x Realtime).", false, Logger.LastLine.EndsWith("%"));
184184
//
185185
// if (RunTask.canceled)
186186
// return false;

ff-utils-winforms/UI/Tasks/UtilGetMetrics.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public static async Task Run(bool fixRate = true)
116116

117117
static bool ReplaceLastLine ()
118118
{
119-
return (new[] { "...", FfmpegOutputHandler.prefix }).Any(c => Logger.GetLastLine().Contains(c));
119+
return (new[] { "...", FfmpegOutputHandler.prefix }).Any(c => Logger.LastLine.Contains(c));
120120
}
121121

122122
private static async Task<string> GetAlignFilters ()

0 commit comments

Comments
 (0)