mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2026-01-06 07:29:31 -06:00
FF-169 - detect black bars now handles any length video
This commit is contained in:
@@ -48,10 +48,29 @@ public class FfmpegBuilderCropBlackBars : FfmpegBuilderNode
|
||||
args.Logger?.ELog("Failed to find video height");
|
||||
return string.Empty;
|
||||
}
|
||||
return Execute(ffmpeg, args.WorkingFile, args, vidWidth, vidHeight, threshold);
|
||||
return Execute(ffmpeg, args.WorkingFile, args, vidWidth, vidHeight, threshold, (int)videoInfo.VideoStreams[0].Duration.TotalSeconds);
|
||||
}
|
||||
|
||||
string Execute(string ffplay, string file, NodeParameters args, int vidWidth, int vidHeight, int threshold)
|
||||
private int[] GetTimeIntervals(int seconds)
|
||||
{
|
||||
if (seconds < 2)
|
||||
return new int[] { };
|
||||
if (seconds < 10)
|
||||
return new int[] { 1 };
|
||||
if (seconds > 360)
|
||||
return new int[] { 60, 120, 240, 360 };
|
||||
|
||||
int increment = seconds / 5;
|
||||
return new int[]
|
||||
{
|
||||
increment,
|
||||
increment + increment,
|
||||
increment + increment + increment,
|
||||
increment + increment + increment + increment,
|
||||
};
|
||||
}
|
||||
|
||||
string Execute(string ffplay, string file, NodeParameters args, int vidWidth, int vidHeight, int threshold, int seconds)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -59,7 +78,10 @@ public class FfmpegBuilderCropBlackBars : FfmpegBuilderNode
|
||||
int y = int.MaxValue;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
foreach (int ss in new int[] { 60, 120, 240, 360 }) // check at multiple times
|
||||
var intervals = GetTimeIntervals(seconds);
|
||||
if (intervals.Length == 0)
|
||||
return string.Empty;
|
||||
foreach (int ss in intervals) // check at multiple times
|
||||
{
|
||||
using (var process = new Process())
|
||||
{
|
||||
@@ -99,12 +121,12 @@ public class FfmpegBuilderCropBlackBars : FfmpegBuilderNode
|
||||
if (width == 0 || height == 0)
|
||||
{
|
||||
args.Logger?.WLog("Width/Height not detected: " + width + "x" + height);
|
||||
return String.Empty;
|
||||
return string.Empty;
|
||||
}
|
||||
if (x == 0 && y == 0)
|
||||
{
|
||||
// nothing to do
|
||||
return String.Empty;
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
if (x == int.MaxValue)
|
||||
|
||||
@@ -1219,6 +1219,98 @@ public class FfmpegBuilder_BasicTests
|
||||
string log = logger.ToString();
|
||||
Assert.AreEqual(1, result);
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void FfmpegBuilder_BlackBars_Short()
|
||||
{
|
||||
const string file = @"D:\videos\testfiles\tag.mp4";
|
||||
var logger = new TestLogger();
|
||||
const string ffmpeg = @"C:\utils\ffmpeg\ffmpeg.exe";
|
||||
var vi = new VideoInfoHelper(ffmpeg, logger);
|
||||
var vii = vi.Read(file);
|
||||
var args = new NodeParameters(file, logger, false, string.Empty);
|
||||
args.GetToolPathActual = (string tool) => ffmpeg;
|
||||
args.TempPath = @"D:\videos\temp";
|
||||
args.Parameters.Add("VideoInfo", vii);
|
||||
|
||||
|
||||
FfmpegBuilderStart ffStart = new();
|
||||
ffStart.PreExecute(args);
|
||||
Assert.AreEqual(1, ffStart.Execute(args));
|
||||
|
||||
FfmpegBuilderCropBlackBars ffCropBlackBars = new();
|
||||
ffCropBlackBars.CroppingThreshold = 10;
|
||||
ffCropBlackBars.PreExecute(args);
|
||||
ffCropBlackBars.Execute(args);
|
||||
|
||||
string log = logger.ToString();
|
||||
Assert.IsTrue(log.Contains($"-ss 2 -i \"{file}\" -hide_banner -vframes 25 -vf cropdetect -f null -"));
|
||||
Assert.IsTrue(log.Contains($"-ss 4 -i \"{file}\" -hide_banner -vframes 25 -vf cropdetect -f null -"));
|
||||
Assert.IsTrue(log.Contains($"-ss 6 -i \"{file}\" -hide_banner -vframes 25 -vf cropdetect -f null -"));
|
||||
Assert.IsTrue(log.Contains($"-ss 8 -i \"{file}\" -hide_banner -vframes 25 -vf cropdetect -f null -"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FfmpegBuilder_BlackBars_30sec()
|
||||
{
|
||||
const string file = @"D:\videos\testfiles\50-mbps-hd-h264.mkv";
|
||||
var logger = new TestLogger();
|
||||
const string ffmpeg = @"C:\utils\ffmpeg\ffmpeg.exe";
|
||||
var vi = new VideoInfoHelper(ffmpeg, logger);
|
||||
var vii = vi.Read(file);
|
||||
var args = new NodeParameters(file, logger, false, string.Empty);
|
||||
args.GetToolPathActual = (string tool) => ffmpeg;
|
||||
args.TempPath = @"D:\videos\temp";
|
||||
args.Parameters.Add("VideoInfo", vii);
|
||||
|
||||
|
||||
FfmpegBuilderStart ffStart = new();
|
||||
ffStart.PreExecute(args);
|
||||
Assert.AreEqual(1, ffStart.Execute(args));
|
||||
|
||||
FfmpegBuilderCropBlackBars ffCropBlackBars = new();
|
||||
ffCropBlackBars.CroppingThreshold = 10;
|
||||
ffCropBlackBars.PreExecute(args);
|
||||
ffCropBlackBars.Execute(args);
|
||||
|
||||
string log = logger.ToString();
|
||||
Assert.IsTrue(log.Contains($"-ss 6 -i \"{file}\" -hide_banner -vframes 25 -vf cropdetect -f null -"));
|
||||
Assert.IsTrue(log.Contains($"-ss 12 -i \"{file}\" -hide_banner -vframes 25 -vf cropdetect -f null -"));
|
||||
Assert.IsTrue(log.Contains($"-ss 18 -i \"{file}\" -hide_banner -vframes 25 -vf cropdetect -f null -"));
|
||||
Assert.IsTrue(log.Contains($"-ss 24 -i \"{file}\" -hide_banner -vframes 25 -vf cropdetect -f null -"));
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void FfmpegBuilder_BlackBars_LongVideo()
|
||||
{
|
||||
const string file = @"D:\videos\testfiles\sitcom.mkv";
|
||||
var logger = new TestLogger();
|
||||
const string ffmpeg = @"C:\utils\ffmpeg\ffmpeg.exe";
|
||||
var vi = new VideoInfoHelper(ffmpeg, logger);
|
||||
var vii = vi.Read(file);
|
||||
var args = new NodeParameters(file, logger, false, string.Empty);
|
||||
args.GetToolPathActual = (string tool) => ffmpeg;
|
||||
args.TempPath = @"D:\videos\temp";
|
||||
args.Parameters.Add("VideoInfo", vii);
|
||||
|
||||
|
||||
FfmpegBuilderStart ffStart = new();
|
||||
ffStart.PreExecute(args);
|
||||
Assert.AreEqual(1, ffStart.Execute(args));
|
||||
|
||||
FfmpegBuilderCropBlackBars ffCropBlackBars = new();
|
||||
ffCropBlackBars.CroppingThreshold = 10;
|
||||
ffCropBlackBars.PreExecute(args);
|
||||
ffCropBlackBars.Execute(args);
|
||||
|
||||
string log = logger.ToString();
|
||||
Assert.IsTrue(log.Contains($"-ss 60 -i \"{file}\" -hide_banner -vframes 25 -vf cropdetect -f null -"));
|
||||
Assert.IsTrue(log.Contains($"-ss 120 -i \"{file}\" -hide_banner -vframes 25 -vf cropdetect -f null -"));
|
||||
Assert.IsTrue(log.Contains($"-ss 240 -i \"{file}\" -hide_banner -vframes 25 -vf cropdetect -f null -"));
|
||||
Assert.IsTrue(log.Contains($"-ss 360 -i \"{file}\" -hide_banner -vframes 25 -vf cropdetect -f null -"));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user