Browse Source

more consistent and improved logging

Michael Hoskins 5 years ago
parent
commit
fd9192e1a7
2 changed files with 10 additions and 4 deletions
  1. 5 3
      MovieBarcodeGenerator/BarcodeGenerator.cs
  2. 5 1
      MovieBarcodeGenerator/SharpFF.cs

+ 5 - 3
MovieBarcodeGenerator/BarcodeGenerator.cs

@@ -5,6 +5,7 @@ using System.Diagnostics;
 using System.IO;
 using System.Linq;
 using System.Text;
+using System.Threading;
 using System.Threading.Tasks;
 
 namespace MovieBarcodeGenerator {
@@ -26,7 +27,7 @@ namespace MovieBarcodeGenerator {
         }
 
         public static void Generate(string inputFile, string outputFile, int height, int barWidth, int iterations) {
-            log.Debug("Generate()");
+            log.InfoFormat("Beginning barcode generation for {0} slices.", iterations);
             if (File.Exists(outputFile)) {
                 log.InfoFormat("Output file '{0}' exists. Deleting file.", outputFile);
                 File.Delete(outputFile);
@@ -39,12 +40,13 @@ namespace MovieBarcodeGenerator {
 
             // run these in parallel to save time
             // TODO: do all this work in a temp folder, then move the finished file to the destination
+            log.Debug("Generating image slices.");
             Parallel.For(0, iterations, i => {
                 string timecodeAt = SharpFF.SecondsToTimecode(i * (videoLength / iterations));
                 SharpFF.ExecuteCommand(string.Format("-hide_banner -loglevel panic -nostats -y -ss {1} -i \"{0}\" -vframes 1 -an -f rawvideo -vcodec png -vf scale={4}:{5} \"{2}\\out_{3:000}.png\"", inputFile, timecodeAt, Path.GetDirectoryName(outputFile), i, barWidth, height));
             });
 
-            log.Debug("Scrunching PNGs together.");
+            log.Debug("Appending image files.");
             // use ImageMagick to crush the generated PNGs together
             using (MagickImageCollection images = new MagickImageCollection()) {
                 foreach (var file in Directory.GetFiles(Path.GetDirectoryName(outputFile), "out_???.png")) {
@@ -57,7 +59,7 @@ namespace MovieBarcodeGenerator {
                 }
             }
 
-            log.Debug("Deleting temporary work files.");
+            log.Info("Cleaning up temporary files.");
             // clean up the work files
             string[] files = Directory.GetFiles(Path.GetDirectoryName(outputFile), "out_???.png");
             foreach (string file in files) {

+ 5 - 1
MovieBarcodeGenerator/SharpFF.cs

@@ -17,6 +17,7 @@ namespace MovieBarcodeGenerator {
                 log.FatalFormat("FFmpeg was not found at '{0}'.", ffmpegPath);
                 throw new Exception("Path to ffmpeg not specified. Set ffmpeg path (excluding exe) before attempting to use SharpFF.");
             }
+            log.DebugFormat("Calling ffmpeg at {0} with parameters {1}", ffmpegPath, parameters);
             Process p = new Process();
             p.StartInfo.FileName = Path.Combine(ffmpegPath, "ffmpeg");
             p.StartInfo.Arguments = parameters;
@@ -28,13 +29,16 @@ namespace MovieBarcodeGenerator {
         }
 
         public static decimal GetDuration(string videoPath) {
+            string parameters = String.Format("-hide_banner -i \"{0}\"", videoPath);
+
             if (String.IsNullOrEmpty(ffmpegPath) || !File.Exists(Path.Combine(ffmpegPath, "ffmpeg.exe"))) {
                 log.FatalFormat("FFmpeg was not found at '{0}'.", ffmpegPath);
                 throw new Exception("Path to ffmpeg not specified. Set ffmpeg path (excluding exe) before attempting to use SharpFF.");
             }
+            log.DebugFormat("Calling ffmpeg at {0} with parameters {1}", ffmpegPath, parameters);
             Process p = new Process();
             p.StartInfo.FileName = Path.Combine(ffmpegPath, "ffmpeg");
-            p.StartInfo.Arguments = String.Format("-hide_banner -i \"{0}\"", videoPath);
+            p.StartInfo.Arguments = parameters;
             p.StartInfo.RedirectStandardError = true;
             p.StartInfo.UseShellExecute = false;
             p.Start();