From 759d13623ac4f2033513e0210401698966df30bf Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Fri, 14 May 2021 21:12:23 +0200 Subject: [PATCH] AreImagesCompatible is async, benchmarked, has more logging --- Code/IO/IOUtils.cs | 1 - Code/Media/FfmpegExtract.cs | 20 ++++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Code/IO/IOUtils.cs b/Code/IO/IOUtils.cs index 352184f..02e21bd 100644 --- a/Code/IO/IOUtils.cs +++ b/Code/IO/IOUtils.cs @@ -14,7 +14,6 @@ using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -using Microsoft.VisualBasic.Logging; namespace Flowframes.IO { diff --git a/Code/Media/FfmpegExtract.cs b/Code/Media/FfmpegExtract.cs index 33f1e53..f97a737 100644 --- a/Code/Media/FfmpegExtract.cs +++ b/Code/Media/FfmpegExtract.cs @@ -94,7 +94,9 @@ namespace Flowframes.Media public static async Task ImportImagesCheckCompat(string inpath, string outpath, bool alpha, Size size, bool showLog, string format) { - if (!alpha && AreImagesCompatible(inpath, Config.GetInt("maxVidHeight"))) + bool compatible = await Task.Run(async () => { return AreImagesCompatible(inpath, Config.GetInt("maxVidHeight")); }); + + if (!alpha && compatible) { if (showLog) Logger.Log($"Copying images from {new DirectoryInfo(inpath).Name}..."); Directory.CreateDirectory(outpath); @@ -118,6 +120,7 @@ namespace Flowframes.Media static bool AreImagesCompatible (string inpath, int maxHeight) { + NmkdStopwatch sw = new NmkdStopwatch(); string[] validExtensions = new string[] { ".jpg", ".jpeg", ".png" }; FileInfo[] files = IOUtils.GetFileInfosSorted(inpath); @@ -131,7 +134,7 @@ namespace Flowframes.Media if (!allSameExtension) { - Logger.Log("[AreImagesCompatible] Sequence not compatible: Not all files have the same extension.", true); + Logger.Log("Sequence not compatible: Not all files have the same extension [{sw.GetElapsedStr()}].", true); return false; } @@ -139,17 +142,17 @@ namespace Flowframes.Media if (!allValidExtension) { - Logger.Log($"[AreImagesCompatible] Sequence not compatible: Not all files have a valid extension ({string.Join(", ", validExtensions)}).", true); + Logger.Log($"Sequence not compatible: Not all files have a valid extension ({string.Join(", ", validExtensions)}) [{sw.GetElapsedStr()}].", true); return false; } - Image[] randomSamples = files.OrderBy(arg => Guid.NewGuid()).Take(5).Select(x => IOUtils.GetImage(x.FullName)).ToArray(); + Image[] randomSamples = files.OrderBy(arg => Guid.NewGuid()).Take(10).Select(x => IOUtils.GetImage(x.FullName)).ToArray(); bool allSameSize = randomSamples.All(i => i.Size == randomSamples.First().Size); if (!allSameSize) { - Logger.Log("[AreImagesCompatible] Sequence not compatible: Not all images have the same dimensions.", true); + Logger.Log("Sequence not compatible: Not all images have the same dimensions [{sw.GetElapsedStr()}].", true); return false; } @@ -158,7 +161,7 @@ namespace Flowframes.Media if (!allDivBy2) { - Logger.Log($"[AreImagesCompatible] Sequence not compatible: Not all image dimensions are divisible by {div}.", true); + Logger.Log($"Sequence not compatible: Not all image dimensions are divisible by {div} [{sw.GetElapsedStr()}].", true); return false; } @@ -166,7 +169,7 @@ namespace Flowframes.Media if (!allSmallEnough) { - Logger.Log($"[AreImagesCompatible] Sequence not compatible: Image dimensions above max size.", true); + Logger.Log($"Sequence not compatible: Image dimensions above max size [{sw.GetElapsedStr()}].", true); return false; } @@ -174,11 +177,12 @@ namespace Flowframes.Media if (!all24Bit) { - Logger.Log($"[AreImagesCompatible] Sequence not compatible: Some images are not 24-bit (8bpp).", true); + Logger.Log($"Sequence not compatible: Some images are not 24-bit (8bpp) [{sw.GetElapsedStr()}].", true); return false; } Interpolate.current.framesExt = files.First().Extension; + Logger.Log($"Sequence compatible! [{sw.GetElapsedStr()}]", true); return true; }