updated VideoScaler and now supports Conditions on properties

This commit is contained in:
John Andrews
2022-03-30 21:12:10 +13:00
parent a83890fffc
commit a4165a2213
15 changed files with 185 additions and 17 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ namespace FileFlows.BasicNodes
public class Plugin : FileFlows.Plugin.IPlugin
{
public string Name => "Basic Nodes";
public string MinimumVersion => "0.4.2.657";
public string MinimumVersion => "0.4.3.660";
public void Init() { }
}
+1 -1
View File
@@ -3,7 +3,7 @@ namespace ChecksumNodes
public class Plugin : IPlugin
{
public string Name => "Checksum Nodes";
public string MinimumVersion => "0.4.2.657";
public string MinimumVersion => "0.4.3.660";
public void Init()
{
+1 -1
View File
@@ -6,7 +6,7 @@ namespace CollectionNodes
public class Plugin : IPlugin
{
public string Name => "Collection Nodes";
public string MinimumVersion => "0.4.2.657";
public string MinimumVersion => "0.4.3.660";
[Folder(1)]
[Required]
+1 -1
View File
@@ -3,7 +3,7 @@
public class Plugin : IPlugin
{
public string Name => "Email Nodes";
public string MinimumVersion => "0.4.2.657";
public string MinimumVersion => "0.4.3.660";
public void Init()
{
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -5,7 +5,7 @@ namespace MetaNodes
public class Plugin : FileFlows.Plugin.IPlugin
{
public string Name => "Meta Nodes";
public string MinimumVersion => "0.4.2.657";
public string MinimumVersion => "0.4.3.660";
public void Init() { }
}
+1 -1
View File
@@ -6,7 +6,7 @@ namespace FileFlows.MusicNodes
public class Plugin : FileFlows.Plugin.IPlugin
{
public string Name => "Music Nodes";
public string MinimumVersion => "0.4.2.657";
public string MinimumVersion => "0.4.3.660";
public void Init()
{
+1 -1
View File
@@ -6,7 +6,7 @@ namespace FileFlows.VideoNodes
public class Plugin : FileFlows.Plugin.IPlugin
{
public string Name => "Video Nodes";
public string MinimumVersion => "0.4.2.657";
public string MinimumVersion => "0.4.3.660";
public void Init()
{
+132
View File
@@ -0,0 +1,132 @@
#if(DEBUG)
namespace VideoNodes.Tests
{
using FileFlows.VideoNodes;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
[TestClass]
public class VideoScalerTests
{
[TestMethod]
public void VideoScaler_Resolution_Tests()
{
const string file = @"D:\videos\problemfile\sample fileflows.mkv";
VideoScaler node = new();
foreach (var test in new[]
{
// 480p
(600, 640, 2),
(640, 640, 2),
(700, 640, 2),
(599, 640, -1),
(701, 640, -1),
// 720p
(1280, 1280, 2),
(1220, 1280, 2),
(1340, 1280, 2),
(1219, 1280, -1),
(1341, 1280, -1),
// 1080p
(1860, 1920, 2),
(1920, 1920, 2),
(1980, 1920, 2),
(1859, 1920, -1),
(1981, 1920, -1),
// 4k
(3780, 3840, 2),
(3840, 3840, 2),
(3900, 3840, 2),
(3779, 3840, -1),
(3901, 3840, -1),
})
{
node.Resolution = test.Item2 + ":-2";
var args = new FileFlows.Plugin.NodeParameters(file, new TestLogger(), false, string.Empty);
args.Parameters.Add("VideoInfo", new VideoInfo
{
VideoStreams = new List<VideoStream>
{
new VideoStream
{
Width = test.Item1
}
}
});
int output = node.Execute(args);
Assert.AreEqual(test.Item3, output);
}
}
[TestMethod]
public void VideoScaler_Force_Tests()
{
const string file = @"D:\videos\problemfile\sample fileflows.mkv";
VideoScaler node = new();
foreach (var test in new[]
{
// 480p
(600, 640, 2),
(640, 640, 2),
(700, 640, 2),
(599, 640, -1),
(701, 640, -1),
// 720p
(1280, 1280, 2),
(1220, 1280, 2),
(1340, 1280, 2),
(1219, 1280, -1),
(1341, 1280, -1),
// 1080p
(1860, 1920, 2),
(1920, 1920, 2),
(1980, 1920, 2),
(1859, 1920, -1),
(1981, 1920, -1),
// 4k
(3780, 3840, 2),
(3840, 3840, 2),
(3900, 3840, 2),
(3779, 3840, -1),
(3901, 3840, -1),
})
{
node.Resolution = test.Item2 + ":-2";
node.Force = true;
var args = new FileFlows.Plugin.NodeParameters(file, new TestLogger(), false, string.Empty);
args.Parameters.Add("VideoInfo", new VideoInfo
{
VideoStreams = new List<VideoStream>
{
new VideoStream
{
Width = test.Item1
}
}
});
int output = node.Execute(args);
Assert.AreEqual(-1, output);
}
}
}
}
#endif
+7 -2
View File
@@ -266,14 +266,19 @@
"VideoScaler": {
"Description": "This allows you to scale a video to the specified dimensions. It will retain the aspect ratio of the video so if the video was 1920x1000 it would scale to 1280x668 if you select 720P.",
"Outputs": {
"1": "Video rescaled to temporary file"
"1": "Video rescaled to temporary file",
"2": "Video was already in/near the scaled resolution"
},
"Fields": {
"VideoCodec": "Video Codec",
"Language-Help": "The video codec to encode the scaled video in",
"Extension": "Extension",
"Extension-Help": "The file extension to use on the newly created file",
"Resolution": "Resolution"
"Force": "Force",
"Force-Help": "When checked the video will be force scaled even if the working file is already in this resolution (or near this resolution).",
"Resolution": "Resolution",
"VideoCodecParameters": "Video Codec Parameters",
"VideoCodecParameters-Help": "The parameters to use to encode the video, eg. \"hevc_nvenc -preset hq -crf 23\" to encode into hevc using the HQ preset a constant rate factor of 23 and using NVIDIA hardware acceleration."
}
}
}
+1 -1
View File
@@ -1,6 +1,7 @@
namespace FileFlows.VideoNodes
{
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Text.RegularExpressions;
using FileFlows.Plugin;
@@ -13,7 +14,6 @@ namespace FileFlows.VideoNodes
[TextVariable(1)]
public string VideoCodec { get; set; }
[DefaultValue("hevc_nvenc -preset hq -crf 23")]
[TextVariable(2)]
public string VideoCodecParameters { get; set; }
+37 -6
View File
@@ -1,6 +1,7 @@
namespace FileFlows.VideoNodes
{
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Text.RegularExpressions;
using FileFlows.Plugin;
@@ -9,11 +10,16 @@ namespace FileFlows.VideoNodes
public class VideoScaler: EncodingNode
{
public override string Icon => "fas fa-search-plus";
public override int Outputs => 1; // this node always re-encodes
public override int Outputs => 2; // this node always re-encodes
[Select(nameof(CodecOptions), 1)]
public string VideoCodec { get; set; }
[Required]
[TextVariable(2)]
[ConditionEquals(nameof(VideoCodec), "Custom")]
public string VideoCodecParameters { get; set; }
private static List<ListOption> _CodecOptions;
public static List<ListOption> CodecOptions
{
@@ -37,7 +43,10 @@ namespace FileFlows.VideoNodes
new ListOption { Label = "Intel Hardware Encoding", Value = "###GROUP###"},
new ListOption { Value = "h264_qsv", Label = "H264 (Intel)"},
new ListOption { Value = "hevc_qsv", Label = "H265 (Intel)"}
new ListOption { Value = "hevc_qsv", Label = "H265 (Intel)"},
new ListOption { Label = "Custom", Value = "###GROUP###"},
new ListOption { Value = "Custom", Label = "Custom"},
};
}
return _CodecOptions;
@@ -46,12 +55,17 @@ namespace FileFlows.VideoNodes
[DefaultValue("mkv")]
[TextVariable(3)]
[TextVariable(4)]
public string Extension { get; set; }
[Select(nameof(ResolutionOptions), 2)]
[Boolean(5)]
public bool Force { get; set; }
[Select(nameof(ResolutionOptions), 3)]
public string Resolution { get; set; }
private static List<ListOption> _ResolutionOptions;
public static List<ListOption> ResolutionOptions
{
@@ -84,18 +98,33 @@ namespace FileFlows.VideoNodes
if (videoInfo == null)
return -1;
if (Force == false)
{
if (Between(videoInfo.VideoStreams[0].Width, 1860, 1980) && Resolution.StartsWith("1920"))
return 2;
else if (Between(videoInfo.VideoStreams[0].Width, 3780, 3900) && Resolution.StartsWith("3840"))
return 2;
else if (Between(videoInfo.VideoStreams[0].Width, 1220, 1340) && Resolution.StartsWith("1280"))
return 2;
else if (Between(videoInfo.VideoStreams[0].Width, 600, 700) && Resolution.StartsWith("640"))
return 2;
}
string ffmpegExe = GetFFMpegExe(args);
if (string.IsNullOrEmpty(ffmpegExe))
return -1;
List<string> ffArgs = new List<string>()
{
"-vf", $"scale={Resolution}:flags=lanczos",
"-c:v"
};
string codec = CheckVideoCodec(ffmpegExe, VideoCodec);
string codec = VideoCodec == "Custom" && string.IsNullOrWhiteSpace(VideoCodecParameters) == false ?
VideoCodecParameters : CheckVideoCodec(ffmpegExe, VideoCodec);
foreach (string c in codec.Split(" "))
{
if (string.IsNullOrWhiteSpace(c.Trim()))
@@ -114,5 +143,7 @@ namespace FileFlows.VideoNodes
return -1;
}
}
private bool Between(int value, int lower, int max) => value >= lower && value <= max;
}
}
+1 -1
View File
@@ -19,7 +19,7 @@ $output = $output | Resolve-Path
Remove-Item Builds -Recurse -ErrorAction SilentlyContinue
$revision = (git rev-list --count --first-parent HEAD) -join "`n"
$version = "0.1.0.$revision"
$version = "0.4.3.$revision"
$json = "[`n"
Binary file not shown.