fixing issue with videocrop being saved in parameters and not variables

This commit is contained in:
John Andrews
2022-02-17 10:12:20 +13:00
parent ade1f4a540
commit e704b7a2a6
4 changed files with 58 additions and 5 deletions

View File

@@ -428,6 +428,44 @@ return 1;
Assert.AreEqual(1, result);
Assert.AreEqual("movie h265", args.Variables["NewName"]);
}
[TestMethod]
public void Function_CropVariable()
{
Function pm = new Function();
var logger = new TestLogger();
var args = new FileFlows.Plugin.NodeParameters(@"D:\videos\unprocessed\movie h264.mkv", logger, false, string.Empty);
pm.Code = @"
let quality = Variables.VideoCrop ? 17 : 19;
Variables.VideoCodecParameters = `hevc_qsv -preset slow -tune film -global_quality ${quality} -look_ahead 1`;
Variables.VideoCodec = 'h265';
Variables.Extension = 'mkv';
return 1;
; ";
args.Variables["VideoCrop"] = "1920:1000:40:40";
var result = pm.Execute(args);
Assert.AreEqual(1, result);
Assert.AreEqual("hevc_qsv -preset slow -tune film -global_quality 17 -look_ahead 1", args.Variables["VideoCodecParameters"]);
}
[TestMethod]
public void Function_CropVariable_Missing()
{
Function pm = new Function();
var logger = new TestLogger();
var args = new FileFlows.Plugin.NodeParameters(@"D:\videos\unprocessed\movie h264.mkv", logger, false, string.Empty);
pm.Code = @"
let quality = Variables.VideoCrop ? 17 : 19;
Variables.VideoCodecParameters = `hevc_qsv -preset slow -tune film -global_quality ${quality} -look_ahead 1`;
Variables.VideoCodec = 'h265';
Variables.Extension = 'mkv';
return 1;
; ";
var result = pm.Execute(args);
Assert.AreEqual(1, result);
Assert.AreEqual("hevc_qsv -preset slow -tune film -global_quality 19 -look_ahead 1", args.Variables["VideoCodecParameters"]);
}
}
}

View File

@@ -16,9 +16,20 @@ namespace FileFlows.VideoNodes
internal const string CROP_KEY = "VideoCrop";
private Dictionary<string, object> _Variables;
public override Dictionary<string, object> Variables => _Variables;
[NumberInt(1)]
public int CroppingThreshold { get; set; }
public DetectBlackBars()
{
_Variables = new Dictionary<string, object>()
{
{ CROP_KEY, "1920:1000:0:40" }
};
}
public override int Execute(NodeParameters args)
{
string ffmpeg = GetFFMpegExe(args);
@@ -31,7 +42,7 @@ namespace FileFlows.VideoNodes
int vidWidth = videoInfo.VideoStreams[0].Width;
int vidHeight = videoInfo.VideoStreams[0].Height;
if(vidWidth < 1)
if (vidWidth < 1)
{
args.Logger?.ELog("Failed to find video width");
return -1;
@@ -47,7 +58,10 @@ namespace FileFlows.VideoNodes
return 2;
args.Logger?.ILog("Black bars detected, crop: " + crop);
args.Parameters.Add(CROP_KEY, crop);
args.UpdateVariables(new Dictionary<string, object>
{
{ CROP_KEY, crop }
});
return 1;
}

View File

@@ -30,18 +30,19 @@ namespace VideoNodes.Tests
int output = node.Execute(args);
string crop = args.Parameters[DetectBlackBars.CROP_KEY] as string;
string crop = args.Variables[DetectBlackBars.CROP_KEY] as string;
Assert.IsFalse(string.IsNullOrWhiteSpace(crop));
Assert.AreEqual(1, output);
}
[TestMethod]
public void DetectBlackBars_Test_02()
{
var crop = DetectBlackBars.TestAboveThreshold(1920, 1080, 1920, 1072, 20);
Assert.IsFalse(crop.crop);
}
}
}
}

View File

@@ -82,7 +82,7 @@ namespace FileFlows.VideoNodes
var videoTrack = videoIsRightCodec ?? videoInfo.VideoStreams[0];
args.Logger?.ILog("Video: ", videoTrack);
string crop = args.GetParameter<string>(DetectBlackBars.CROP_KEY) ?? "";
string crop = (args.Variables.ContainsKey(DetectBlackBars.CROP_KEY) ? args.Variables[DetectBlackBars.CROP_KEY] as string : string.Empty) ?? string.Empty;
if (crop != string.Empty)
crop = " -vf crop=" + crop;