From ee787cac0d4ff4022726c50f32fd57e4f6d73cc6 Mon Sep 17 00:00:00 2001 From: N00MKRAD <61149547+n00mkrad@users.noreply.github.com> Date: Tue, 16 Jan 2024 19:14:26 +0100 Subject: [PATCH] Image sequence input fixes, allow TIFF and EXR inputs, EXR half option --- Code/Data/Enums.cs | 1 + Code/Data/Filetypes.cs | 10 ++----- Code/Media/AvProcess.cs | 6 +++-- Code/Media/FfmpegExtract.cs | 51 ++++++++++++++++++----------------- Code/Media/FfmpegUtils.cs | 5 ++++ Code/MiscUtils/FormatUtils.cs | 7 +++++ Code/MiscUtils/OutputUtils.cs | 4 ++- 7 files changed, 49 insertions(+), 35 deletions(-) diff --git a/Code/Data/Enums.cs b/Code/Data/Enums.cs index f7eb7c5..e614d9f 100644 --- a/Code/Data/Enums.cs +++ b/Code/Data/Enums.cs @@ -26,6 +26,7 @@ public enum JpegWebm { ImgMax, ImgHigh, ImgMed, ImgLow, ImgLowest } public enum ProResProfile { Proxy, Lt, Standard, Hq, Quad4, Quad4Xq } public enum GifColors { Max256, High128, Medium64, Low32, VeryLow16 } + public enum ExrPrecision { Float, Half } } } } diff --git a/Code/Data/Filetypes.cs b/Code/Data/Filetypes.cs index 6584e08..e94d33f 100644 --- a/Code/Data/Filetypes.cs +++ b/Code/Data/Filetypes.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Flowframes.Data +namespace Flowframes.Data { class Filetypes { public static readonly string[] imagesOpenCv = new string[] { ".png", ".jpg", ".jpeg", ".webp", ".bmp", ".tif", ".tiff" }; - public static readonly string[] imagesInterpCompat = new string[] { ".png", ".jpg", ".jpeg", ".webp", ".bmp" }; + public static readonly string[] imagesInterpCompat = new string[] { ".png", ".jpg", ".jpeg", ".webp", ".bmp", ".tif", ".tiff", ".exr" }; } } diff --git a/Code/Media/AvProcess.cs b/Code/Media/AvProcess.cs index ca11bd8..8e6dbd3 100644 --- a/Code/Media/AvProcess.cs +++ b/Code/Media/AvProcess.cs @@ -150,10 +150,12 @@ namespace Flowframes Process ffprobe = OsUtils.NewProcess(!show); NmkdStopwatch timeSinceLastOutput = new NmkdStopwatch(); - ffprobe.StartInfo.Arguments = $"{GetCmdArg()} cd /D {GetAvDir().Wrap()} & ffprobe -v {settings.LogLevel} {settings.Args}"; + bool concat = settings.Args.Split(" \"").Last().Remove("\"").Trim().EndsWith(".concat"); + string args = $"-v {settings.LogLevel} {(concat ? "-f concat -safe 0 " : "")}{settings.Args}"; + ffprobe.StartInfo.Arguments = $"{GetCmdArg()} cd /D {GetAvDir().Wrap()} & ffprobe {args}"; if (settings.LoggingMode != LogMode.Hidden) Logger.Log("Running FFprobe...", false); - Logger.Log($"ffprobe -v {settings.LogLevel} {settings.Args}", true, false, "ffmpeg"); + Logger.Log($"ffprobe {args}", true, false, "ffmpeg"); if (!asyncOutput) return await Task.Run(() => OsUtils.GetProcStdOut(ffprobe)); diff --git a/Code/Media/FfmpegExtract.cs b/Code/Media/FfmpegExtract.cs index 6ab67f5..8b51d36 100644 --- a/Code/Media/FfmpegExtract.cs +++ b/Code/Media/FfmpegExtract.cs @@ -202,37 +202,40 @@ namespace Flowframes.Media int sampleCount = Config.GetInt(Config.Key.imgSeqSampleCount, 10); Image[] randomSamples = files.OrderBy(arg => Guid.NewGuid()).Take(sampleCount).Select(x => IoUtils.GetImage(x.FullName)).ToArray(); - bool allSameSize = randomSamples.All(i => i.Size == randomSamples.First().Size); - - if (!allSameSize) + if(files.All(f => f != null)) { - Logger.Log($"Sequence not compatible: Not all images have the same dimensions.", true); - return false; - } + bool allSameSize = randomSamples.All(i => i.Size == randomSamples.First().Size); - int div = GetModulo(); - bool allDivBy2 = randomSamples.All(i => (i.Width % div == 0) && (i.Height % div == 0)); + if (!allSameSize) + { + Logger.Log($"Sequence not compatible: Not all images have the same dimensions.", true); + return false; + } - if (!allDivBy2) - { - Logger.Log($"Sequence not compatible: Not all image dimensions are divisible by {div}.", true); - return false; - } + int div = GetModulo(); + bool allDivBy2 = randomSamples.All(i => (i.Width % div == 0) && (i.Height % div == 0)); - bool allSmallEnough = randomSamples.All(i => (i.Height <= maxHeight)); + if (!allDivBy2) + { + Logger.Log($"Sequence not compatible: Not all image dimensions are divisible by {div}.", true); + return false; + } - if (!allSmallEnough) - { - Logger.Log($"Sequence not compatible: Image dimensions above max size.", true); - return false; - } + bool allSmallEnough = randomSamples.All(i => (i.Height <= maxHeight)); - bool all24Bit = randomSamples.All(i => (i.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb)); + if (!allSmallEnough) + { + Logger.Log($"Sequence not compatible: Image dimensions above max size.", true); + return false; + } - if (!all24Bit) - { - Logger.Log($"Sequence not compatible: Some images are not 24-bit (8bpp).", true); - return false; + // bool all24Bit = randomSamples.All(i => (i.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb)); + // + // if (!all24Bit) + // { + // Logger.Log($"Sequence not compatible: Some images are not 24-bit (8bpp).", true); + // return false; + // } } Interpolate.currentSettings.framesExt = files.First().Extension; diff --git a/Code/Media/FfmpegUtils.cs b/Code/Media/FfmpegUtils.cs index 8295736..04f19f3 100644 --- a/Code/Media/FfmpegUtils.cs +++ b/Code/Media/FfmpegUtils.cs @@ -358,6 +358,11 @@ namespace Flowframes.Media args.Add($"-q:v {OutputUtils.WebpQuality[qualityLevel]}"); } + if (enc == Encoder.Exr) + { + args.Add($"-format {settings.Quality.Lower()}"); + } + if (pixFmt != (PixelFormat)(-1)) args.Add($"-pix_fmt {pixFmt.ToString().Lower()}"); diff --git a/Code/MiscUtils/FormatUtils.cs b/Code/MiscUtils/FormatUtils.cs index 1397dba..1f4e687 100644 --- a/Code/MiscUtils/FormatUtils.cs +++ b/Code/MiscUtils/FormatUtils.cs @@ -87,7 +87,14 @@ namespace Flowframes.MiscUtils { try { + if (timestamp.IsEmpty() || timestamp == "N/A") + return 0; + string[] values = timestamp.Split(':'); + + if (values.Length < 3) + return 0; + int hours = int.Parse(values[0]); int minutes = int.Parse(values[1]); int seconds = int.Parse(values[2].Split('.')[0]); diff --git a/Code/MiscUtils/OutputUtils.cs b/Code/MiscUtils/OutputUtils.cs index e3aa771..30f9552 100644 --- a/Code/MiscUtils/OutputUtils.cs +++ b/Code/MiscUtils/OutputUtils.cs @@ -291,7 +291,9 @@ namespace Flowframes.MiscUtils Codec = Codec.Exr, PixelFormats = new List() { PixFmt.Gbrpf32Le, PixFmt.Gbrapf32Le }, PixelFormatDefault = PixFmt.Gbrpf32Le, - Lossless = true, + QualityLevels = ParseUtils.GetEnumStrings(), + QualityDefault = (int)Quality.ExrPrecision.Half, + Lossless = false, IsImageSequence = true, OverideExtension = "exr", };