Skip to content

Commit 116aa12

Browse files
committed
Concat Util: Progress bar for superchunk writing, cleaner prints
1 parent 533f2d9 commit 116aa12

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

ff-utils-winforms/Utils/ConcatUtils.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ namespace Nmkoder.Utils
1313
{
1414
class ConcatUtils
1515
{
16-
public static async Task ConcatFfmpeg ()
16+
public static async Task ConcatFfmpeg()
1717
{
1818

1919
}
2020

21-
public static async Task ConcatMkvMerge(List<string> paths, string outPath)
21+
public static async Task ConcatMkvMerge(List<string> paths, string outPath, bool print = true)
2222
{
2323
List<string> commands = new List<string>();
2424
List<string> superChunkPaths = new List<string>();
@@ -47,7 +47,7 @@ public static async Task ConcatMkvMerge(List<string> paths, string outPath)
4747
currList.Add(paths[i]);
4848
lists[superChunkIndex] = currList;
4949

50-
if(i + 1 == paths.Count) // if this is the last iteration
50+
if (i + 1 == paths.Count) // if this is the last iteration
5151
{
5252
superChunkPaths.Add(Path.Combine(superChunkBasePath, $"{(superChunkIndex.ToString().PadLeft(3, '0'))}.mkv"));
5353
commands.Add(currentCmd);
@@ -56,13 +56,19 @@ public static async Task ConcatMkvMerge(List<string> paths, string outPath)
5656
Logger.Log($"Concat: Added chunk #{i} to superchunk {superChunkIndex} - Command length is {currentCmd.Length}", true);
5757
}
5858

59-
for(int i = 0; i < commands.Count; i++)
59+
for (int i = 0; i < commands.Count; i++)
6060
{
61-
Logger.Log($"Writing chunk {i+1}/{commands.Count}...");
61+
if (print)
62+
{
63+
Logger.Log($"Writing chunk {i + 1}/{commands.Count}...", false, Logger.LastLine.Contains("Writing chunk"));
64+
int percent = (((float)(i + 1) / commands.Count) * 100f).RoundToInt();
65+
Program.mainForm.SetProgress(percent);
66+
}
67+
6268
await AvProcess.RunMkvMerge(commands[i], false);
6369
}
6470

65-
await ConcatMkvMergeSingle(superChunkPaths, outPath);
71+
await ConcatMkvMergeSingle(superChunkPaths, outPath, print);
6672
superChunkPaths.ForEach(x => IoUtils.TryDeleteIfExists(x));
6773
}
6874

@@ -71,20 +77,22 @@ private static string GetBaseCmd(string superChunkBasePath, int superChunkIndex)
7177
return $" -o {Path.Combine(superChunkBasePath, $"{(superChunkIndex.ToString().PadLeft(3, '0'))}.mkv").Wrap()}";
7278
}
7379

74-
private static async Task ConcatMkvMergeSingle(List<string> paths, string outPath)
80+
private static async Task ConcatMkvMergeSingle(List<string> paths, string outPath, bool print)
7581
{
7682
string args = $" -o {outPath.Wrap()}";
7783

7884
for (int i = 0; i < paths.Count; i++)
7985
args += $" {(i == 0 ? "" : "+")}{paths[i].Wrap()}";
8086

81-
if(args.Length > 8000)
87+
if (args.Length > 8000)
8288
{
8389
Logger.Log($"Error: Merge command is too long! Try moving Nmkoder to a directory with a shorter path.");
8490
return;
8591
}
8692

87-
Logger.Log($"Merging...");
93+
if (print)
94+
Logger.Log($"Merging...");
95+
8896
await AvProcess.RunMkvMerge(args, false);
8997

9098
if (!File.Exists(outPath))

0 commit comments

Comments
 (0)