mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2026-01-06 06:39:48 -06:00
fixing issue with videocrop being saved in parameters and not variables
This commit is contained in:
@@ -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"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user