From 3b552a3c7a1b3e64351dfbce6f9e9a8e58142f3e Mon Sep 17 00:00:00 2001 From: reven Date: Wed, 22 Dec 2021 10:30:52 +1300 Subject: [PATCH] fixed issue with black bar detection not working --- BasicNodes/BasicNodes.csproj | Bin 2164 -> 2164 bytes MetaNodes/MetaNodes.csproj | Bin 2208 -> 2208 bytes VideoNodes/LogicalNodes/DetectBlackBars.cs | 18 +++++++++++++++--- VideoNodes/Tests/VideoInfoHelperTests.cs | 2 +- VideoNodes/VideoNodes.csproj | Bin 2274 -> 2274 bytes VideoNodes/VideoNodes/EncodingNode.cs | 2 +- 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/BasicNodes/BasicNodes.csproj b/BasicNodes/BasicNodes.csproj index f333d63ad526c1e668277e544d920daa1d5c1d8c..3ff9b45cccfc1daf78b076d38ecb83c083a58ffe 100644 GIT binary patch delta 20 ccmew&@I_$5D@I1s$*&p18BI4kGa0f009scE6#xJL delta 20 ccmew&@I_$5D@I0>$*&p18BI1jGa0f009r){6951J diff --git a/MetaNodes/MetaNodes.csproj b/MetaNodes/MetaNodes.csproj index 28117d51c7a293ad34c8fb9df4fa18b75525a5f6..c1fe9c75fde8fed0f2bf3bcf14dd2bb1776df16e 100644 GIT binary patch delta 20 ccmZ1=xIl2j97aad$#WUQ8BI5TWn9e$07@PP{r~^~ delta 20 ccmZ1=xIl2j97aZy$#WUQ8BI2SWn9e$07?u7`~Uy| diff --git a/VideoNodes/LogicalNodes/DetectBlackBars.cs b/VideoNodes/LogicalNodes/DetectBlackBars.cs index 7a0c03bb..2b3882c8 100644 --- a/VideoNodes/LogicalNodes/DetectBlackBars.cs +++ b/VideoNodes/LogicalNodes/DetectBlackBars.cs @@ -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; } diff --git a/VideoNodes/Tests/VideoInfoHelperTests.cs b/VideoNodes/Tests/VideoInfoHelperTests.cs index 763d38d1..c7120adf 100644 --- a/VideoNodes/Tests/VideoInfoHelperTests.cs +++ b/VideoNodes/Tests/VideoInfoHelperTests.cs @@ -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"); diff --git a/VideoNodes/VideoNodes.csproj b/VideoNodes/VideoNodes.csproj index 6c3c502f2a566421bb2b2473d92bcf332b30dbf6..c3102d87f183d7b2387be84a2e7557fb14899fcd 100644 GIT binary patch delta 20 ccmaDP_(*WW113h($q$*r8BI4^GOuI>09UpLPXGV_ delta 20 ccmaDP_(*WW113h3$q$*r8BI1@GOuI>09T|3O#lD@ diff --git a/VideoNodes/VideoNodes/EncodingNode.cs b/VideoNodes/VideoNodes/EncodingNode.cs index 674c439d..ba75757b 100644 --- a/VideoNodes/VideoNodes/EncodingNode.cs +++ b/VideoNodes/VideoNodes/EncodingNode.cs @@ -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) {