diff --git a/FileFlows.Plugin.dll b/FileFlows.Plugin.dll index e7d8eff3..111075da 100644 Binary files a/FileFlows.Plugin.dll and b/FileFlows.Plugin.dll differ diff --git a/FileFlows.Plugin.pdb b/FileFlows.Plugin.pdb index b51b72b7..a8cbfced 100644 Binary files a/FileFlows.Plugin.pdb and b/FileFlows.Plugin.pdb differ diff --git a/VideoNodes/ResolutionHelper.cs b/VideoNodes/ResolutionHelper.cs new file mode 100644 index 00000000..14507293 --- /dev/null +++ b/VideoNodes/ResolutionHelper.cs @@ -0,0 +1,43 @@ +namespace FileFlows.VideoNodes +{ + internal class ResolutionHelper + { + public enum Resolution + { + Unknown, + r480p, + r720p, + r1080p, + r4k, + } + + public static Resolution GetResolution(VideoInfo videoInfo) + { + var video = videoInfo?.VideoStreams?.FirstOrDefault(); + if (video == null) + return Resolution.Unknown; + return GetResolution(video.Width, video.Height); + } + + public static Resolution GetResolution(int width, int height) + { + // so if the video is in portait mode, we test the height as if it were the width + int w = Math.Max(width, height); + int h = Math.Min(width, height); + + if (Between(w, 1860, 1980)) + return Resolution.r1080p; + else if (Between(w, 3780, 3900)) + return Resolution.r4k; + else if (Between(w, 1220, 1340)) + return Resolution.r720p; + else if (Between(w, 600, 700)) + return Resolution.r480p; + + return Resolution.Unknown; + } + + + private static bool Between(int value, int lower, int max) => value >= lower && value <= max; + } +} diff --git a/VideoNodes/Tests/VideoEncodeTests.cs b/VideoNodes/Tests/VideoEncodeTests.cs index addad7d0..a0b44b5b 100644 --- a/VideoNodes/Tests/VideoEncodeTests.cs +++ b/VideoNodes/Tests/VideoEncodeTests.cs @@ -26,15 +26,29 @@ namespace VideoNodes.Tests args.GetToolPathActual = (string tool) => @"C:\utils\ffmpeg\ffmpeg.exe"; args.TempPath = @"D:\videos\temp"; + + node.VideoCodec = "h265"; node.AudioCodec = "aac"; node.Language = "DE"; new VideoFile().Execute(args); + TestVideoInfo(args, "h264", "eac3"); + int output = node.Execute(args); Assert.AreEqual(1, output); + TestVideoInfo(args, "hevc", "aac"); + } + + private void TestVideoInfo(FileFlows.Plugin.NodeParameters parameters, string videoCodec, string audioCodec) + { + Assert.AreEqual(videoCodec, parameters.Variables["vi.Video.Codec"]); + Assert.AreEqual(audioCodec, parameters.Variables["vi.Audio.Codec"]); + var videoInfo = parameters.Variables["vi.VideoInfo"] as VideoInfo; + Assert.AreEqual(videoCodec, videoInfo.VideoStreams[0].Codec); + Assert.AreEqual(audioCodec, videoInfo.AudioStreams[0].Codec); } } diff --git a/VideoNodes/Tests/VideoScalerTests.cs b/VideoNodes/Tests/VideoScalerTests.cs index 13a8f334..3916b61a 100644 --- a/VideoNodes/Tests/VideoScalerTests.cs +++ b/VideoNodes/Tests/VideoScalerTests.cs @@ -125,6 +125,42 @@ namespace VideoNodes.Tests Assert.AreEqual(-1, output); } } + + + [TestMethod] + public void VideoScaler_VideoInfoUpdated_Test() + { + const string file = @"D:\videos\problemfile\sample fileflows.mkv"; + var vi = new VideoInfoHelper(@"C:\utils\ffmpeg\ffmpeg.exe", new TestLogger()); + var vii = vi.Read(file); + + VideoScaler node = new(); + var args = new FileFlows.Plugin.NodeParameters(file, new TestLogger(), false, string.Empty); + args.GetToolPathActual = (string tool) => @"C:\utils\ffmpeg\ffmpeg.exe"; + args.TempPath = @"D:\videos\temp"; + + node.VideoCodec = "h265"; + + + new VideoFile().Execute(args); + + TestVideoInfo(args, "h264", 1280, 720, "720p"); + + node.Resolution = "1920:-2"; + int output = node.Execute(args); + + Assert.AreEqual(1, output); + + TestVideoInfo(args, "hevc", 1920, 1080, "1080p"); + } + + private void TestVideoInfo(FileFlows.Plugin.NodeParameters parameters, string videoCodec, int width, int height, string resolution) + { + Assert.AreEqual(videoCodec, parameters.Variables["vi.Video.Codec"]); + Assert.AreEqual(resolution, parameters.Variables["vi.Resolution"]); + var videoInfo = parameters.Variables["vi.VideoInfo"] as VideoInfo; + Assert.AreEqual(videoCodec, videoInfo.VideoStreams[0].Codec); + } } } diff --git a/VideoNodes/VideoNodes.csproj b/VideoNodes/VideoNodes.csproj index eafdb0d3..bf2c4c15 100644 Binary files a/VideoNodes/VideoNodes.csproj and b/VideoNodes/VideoNodes.csproj differ diff --git a/VideoNodes/VideoNodes/EncodingNode.cs b/VideoNodes/VideoNodes/EncodingNode.cs index 503fbced..50951931 100644 --- a/VideoNodes/VideoNodes/EncodingNode.cs +++ b/VideoNodes/VideoNodes/EncodingNode.cs @@ -54,9 +54,7 @@ namespace FileFlows.VideoNodes // get the new video info var videoInfo = new VideoInfoHelper(ffmpegExe, args.Logger).Read(outputFile); - var newVariables = new Dictionary(); - SetVideoInfo(args, videoInfo, newVariables); - args.UpdateVariables(newVariables); + SetVideoInfo(args, videoInfo, this.Variables ?? new Dictionary()); } Encoder.AtTime -= AtTimeEvent; Encoder = null; diff --git a/VideoNodes/VideoNodes/VideoNode.cs b/VideoNodes/VideoNodes/VideoNode.cs index 2a937279..750af1f1 100644 --- a/VideoNodes/VideoNodes/VideoNode.cs +++ b/VideoNodes/VideoNodes/VideoNode.cs @@ -81,27 +81,25 @@ namespace FileFlows.VideoNodes variables.AddOrUpdate("vi.Video.Codec", videoInfo.VideoStreams[0].Codec); if (videoInfo.AudioStreams?.Any() == true) { - ; - if (string.IsNullOrEmpty(videoInfo.AudioStreams[0].Codec)) - Variables.AddOrUpdate("vi.Audio.Codec", videoInfo.AudioStreams[0].Codec); - if (string.IsNullOrEmpty(videoInfo.AudioStreams[0].Codec)) - Variables.AddOrUpdate("vi.Audio.Channels", videoInfo.AudioStreams[0].Channels); - if (string.IsNullOrEmpty(videoInfo.AudioStreams[0].Language)) - Variables.AddOrUpdate("vi.Audio.Language", videoInfo.AudioStreams[0].Language); - Variables.AddOrUpdate("vi.Audio.Codecs", string.Join(", ", videoInfo.AudioStreams.Select(x => x.Codec).Where(x => string.IsNullOrEmpty(x) == false))); - Variables.AddOrUpdate("vi.Audio.Languages", string.Join(", ", videoInfo.AudioStreams.Select(x => x.Language).Where(x => string.IsNullOrEmpty(x) == false))); + variables.AddOrUpdate("vi.Audio.Codec", videoInfo.AudioStreams[0].Codec?.EmptyAsNull()); + variables.AddOrUpdate("vi.Audio.Channels", videoInfo.AudioStreams[0].Channels > 0 ? (object)videoInfo.AudioStreams[0].Channels : null); + variables.AddOrUpdate("vi.Audio.Language", videoInfo.AudioStreams[0].Language?.EmptyAsNull()); + variables.AddOrUpdate("vi.Audio.Codecs", string.Join(", ", videoInfo.AudioStreams.Select(x => x.Codec).Where(x => string.IsNullOrEmpty(x) == false))); + variables.AddOrUpdate("vi.Audio.Languages", string.Join(", ", videoInfo.AudioStreams.Select(x => x.Language).Where(x => string.IsNullOrEmpty(x) == false))); } - - if (videoInfo.VideoStreams[0].Width == 1920) - Variables.AddOrUpdate("vi.Resolution", "1080"); - else if (videoInfo.VideoStreams[0].Width == 3840) - Variables.AddOrUpdate("vi.Resolution", "4l"); - else if (videoInfo.VideoStreams[0].Width == 1280) - Variables.AddOrUpdate("vi.Resolution", "720p"); - else if (videoInfo.VideoStreams[0].Width < 1280) - Variables.AddOrUpdate("vi.Resolution", "SD"); + var resolution = ResolutionHelper.GetResolution(videoInfo.VideoStreams[0].Width, videoInfo.VideoStreams[0].Height); + if(resolution == ResolutionHelper.Resolution.r1080p) + variables.AddOrUpdate("vi.Resolution", "1080p"); + else if (resolution == ResolutionHelper.Resolution.r4k) + variables.AddOrUpdate("vi.Resolution", "4K"); + else if (resolution == ResolutionHelper.Resolution.r720p) + variables.AddOrUpdate("vi.Resolution", "720p"); + else if (resolution == ResolutionHelper.Resolution.r480p) + variables.AddOrUpdate("vi.Resolution", "480p"); + else if (videoInfo.VideoStreams[0].Width < 900 && videoInfo.VideoStreams[0].Height < 800) + variables.AddOrUpdate("vi.Resolution", "SD"); else - Variables.AddOrUpdate("vi.Resolution", videoInfo.VideoStreams[0].Width + "x" + videoInfo.VideoStreams[0].Height); + variables.AddOrUpdate("vi.Resolution", videoInfo.VideoStreams[0].Width + "x" + videoInfo.VideoStreams[0].Height); args.UpdateVariables(variables); } diff --git a/VideoNodes/VideoNodes/VideoScaler.cs b/VideoNodes/VideoNodes/VideoScaler.cs index eedaff90..4c604fe6 100644 --- a/VideoNodes/VideoNodes/VideoScaler.cs +++ b/VideoNodes/VideoNodes/VideoScaler.cs @@ -101,13 +101,14 @@ namespace FileFlows.VideoNodes if (Force == false) { - if (Between(videoInfo.VideoStreams[0].Width, 1860, 1980) && Resolution.StartsWith("1920")) + var resolution = ResolutionHelper.GetResolution(videoInfo); + if(resolution == ResolutionHelper.Resolution.r1080p && Resolution.StartsWith("1920")) return 2; - else if (Between(videoInfo.VideoStreams[0].Width, 3780, 3900) && Resolution.StartsWith("3840")) + else if (resolution == ResolutionHelper.Resolution.r4k && Resolution.StartsWith("3840")) return 2; - else if (Between(videoInfo.VideoStreams[0].Width, 1220, 1340) && Resolution.StartsWith("1280")) + else if (resolution == ResolutionHelper.Resolution.r720p && Resolution.StartsWith("1280")) return 2; - else if (Between(videoInfo.VideoStreams[0].Width, 600, 700) && Resolution.StartsWith("640")) + else if (resolution == ResolutionHelper.Resolution.r480p && Resolution.StartsWith("640")) return 2; } @@ -143,7 +144,5 @@ namespace FileFlows.VideoNodes return -1; } } - - private bool Between(int value, int lower, int max) => value >= lower && value <= max; } } \ No newline at end of file diff --git a/build/utils/PluginInfoGenerator/FileFlows.Plugin.dll b/build/utils/PluginInfoGenerator/FileFlows.Plugin.dll index 3bd37484..c59b1137 100644 Binary files a/build/utils/PluginInfoGenerator/FileFlows.Plugin.dll and b/build/utils/PluginInfoGenerator/FileFlows.Plugin.dll differ diff --git a/build/utils/PluginInfoGenerator/FileFlows.Plugin.pdb b/build/utils/PluginInfoGenerator/FileFlows.Plugin.pdb index 95b51adc..4857400e 100644 Binary files a/build/utils/PluginInfoGenerator/FileFlows.Plugin.pdb and b/build/utils/PluginInfoGenerator/FileFlows.Plugin.pdb differ diff --git a/build/utils/PluginInfoGenerator/FileFlows.ServerShared.dll b/build/utils/PluginInfoGenerator/FileFlows.ServerShared.dll index acf78be3..9f5180ac 100644 Binary files a/build/utils/PluginInfoGenerator/FileFlows.ServerShared.dll and b/build/utils/PluginInfoGenerator/FileFlows.ServerShared.dll differ diff --git a/build/utils/PluginInfoGenerator/FileFlows.ServerShared.pdb b/build/utils/PluginInfoGenerator/FileFlows.ServerShared.pdb index de618d28..67138b71 100644 Binary files a/build/utils/PluginInfoGenerator/FileFlows.ServerShared.pdb and b/build/utils/PluginInfoGenerator/FileFlows.ServerShared.pdb differ diff --git a/build/utils/PluginInfoGenerator/FileFlows.Shared.dll b/build/utils/PluginInfoGenerator/FileFlows.Shared.dll index f1488384..6c451020 100644 Binary files a/build/utils/PluginInfoGenerator/FileFlows.Shared.dll and b/build/utils/PluginInfoGenerator/FileFlows.Shared.dll differ diff --git a/build/utils/PluginInfoGenerator/FileFlows.Shared.pdb b/build/utils/PluginInfoGenerator/FileFlows.Shared.pdb index 1dd43ee8..9c3bb71e 100644 Binary files a/build/utils/PluginInfoGenerator/FileFlows.Shared.pdb and b/build/utils/PluginInfoGenerator/FileFlows.Shared.pdb differ diff --git a/build/utils/PluginInfoGenerator/FileFlows.Shared.xml b/build/utils/PluginInfoGenerator/FileFlows.Shared.xml index 98c67aa0..160d3562 100644 --- a/build/utils/PluginInfoGenerator/FileFlows.Shared.xml +++ b/build/utils/PluginInfoGenerator/FileFlows.Shared.xml @@ -19,6 +19,11 @@ Gets or sets if this library will use fingerprinting to determine if a file already is known + + + Gets or sets if hidden files and folders should be excluded from the library + + When the library was last scanned diff --git a/build/utils/PluginInfoGenerator/PluginInfoGenerator.dll b/build/utils/PluginInfoGenerator/PluginInfoGenerator.dll index f72b461c..6a545092 100644 Binary files a/build/utils/PluginInfoGenerator/PluginInfoGenerator.dll and b/build/utils/PluginInfoGenerator/PluginInfoGenerator.dll differ diff --git a/build/utils/PluginInfoGenerator/PluginInfoGenerator.pdb b/build/utils/PluginInfoGenerator/PluginInfoGenerator.pdb index 9b73e179..a0420b17 100644 Binary files a/build/utils/PluginInfoGenerator/PluginInfoGenerator.pdb and b/build/utils/PluginInfoGenerator/PluginInfoGenerator.pdb differ diff --git a/ref/FileFlows.Plugin.dll b/ref/FileFlows.Plugin.dll index 651e6b1b..68e74035 100644 Binary files a/ref/FileFlows.Plugin.dll and b/ref/FileFlows.Plugin.dll differ