fixed issue with black bar detection not working

This commit is contained in:
reven
2021-12-22 10:30:52 +13:00
parent e9a65eec98
commit 3b552a3c7a
6 changed files with 17 additions and 5 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -48,13 +48,23 @@ namespace FileFlows.VideoNodes
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.Arguments = $"-i \"{file}\" -hide_banner -t 10 -ss 60 -vf cropdetect=24:16:0 {tempFile}";
process.StartInfo.Arguments = $"-i \"{file}\" -hide_banner -t 10 -ss 60 -vf cropdetect {tempFile}";
args.Logger?.DLog("Exectuing ffmpeg " + process.StartInfo.Arguments);
process.Start();
string output = process.StandardError.ReadToEnd();
Console.WriteLine(output);
string error = process.StandardError.ReadToEnd();
process.WaitForExit();
var dimMatch = Regex.Match(output, @"Stream #[\d]+:[\d]+: Video:(.*?)([\d]+)x([\d]+)", RegexOptions.Multiline);
if (dimMatch.Success == false)
return String.Empty; // cant find dimensions
int vidWidth = int.Parse(dimMatch.Groups[2].Value);
int vidHeight = int.Parse(dimMatch.Groups[3].Value);
args.Logger?.DLog($"Video dimensions: {vidWidth}x{vidHeight}");
var matches = Regex.Matches(output, @"(?<=(crop=))([\d]+:){3}[\d]+");
int x = int.MaxValue;
int y = int.MaxValue;
@@ -77,8 +87,10 @@ namespace FileFlows.VideoNodes
if(CroppingThreshold < 0)
CroppingThreshold = 0;
bool willCrop = (x + y) > CroppingThreshold;
args.Logger?.ILog($"Crop detection, x:{x}, y:{y}, total:{x + y}, threshold:{CroppingThreshold}, above threshold: {willCrop}");
int diff = x + y + (vidWidth - width) + (vidHeight - height);
bool willCrop = diff > CroppingThreshold;
args.Logger?.ILog($"Crop detection, x:{x}, y:{y}, width: {width}, height: {height}, total:{diff}, threshold:{CroppingThreshold}, above threshold: {willCrop}");
return willCrop ? $"{width}:{height}:{x}:{y}" : string.Empty;
}

View File

@@ -48,7 +48,7 @@ namespace VideoNodes.Tests
[TestMethod]
public void VideoInfoTest_DetectBlackBars()
{
const string file = @"D:\videos\unprocessed\Bourne.mkv";
const string file = @"D:\videos\unprocessed\The Witcher - S02E05 - Turn Your Back.mkv";
var vi = new VideoInfoHelper(@"C:\utils\ffmpeg\ffmpeg.exe", new TestLogger());
vi.Read(@"D:\videos\unprocessed\Bourne.mkv");

Binary file not shown.

View File

@@ -30,7 +30,7 @@ namespace FileFlows.VideoNodes
if (string.IsNullOrEmpty(outputFile))
outputFile = Path.Combine(args.TempPath, Guid.NewGuid().ToString() + "." + extension);
bool success = Encoder.Encode(args.WorkingFile, outputFile, ffmpegParameters);
bool success = Encoder.Encode(args.WorkingFile, outputFile, ffmpegParameters);
args.Logger.ILog("Encoding succesful: " + success);
if (success)
{