From 7f72625eacd3efb6e53605e9b3471402edc77850 Mon Sep 17 00:00:00 2001 From: Thodoris Koskinopoulos Date: Sun, 27 Nov 2022 05:54:29 +0200 Subject: [PATCH] Added blackdetect and blackframe arguments --- FFMpegCore/FFMpeg/Arguments/BlackDetectArgument.cs | 14 ++++++++++++++ FFMpegCore/FFMpeg/Arguments/BlackFrameArgument.cs | 14 ++++++++++++++ .../FFMpeg/Arguments/VideoFiltersArgument.cs | 2 ++ 3 files changed, 30 insertions(+) create mode 100644 FFMpegCore/FFMpeg/Arguments/BlackDetectArgument.cs create mode 100644 FFMpegCore/FFMpeg/Arguments/BlackFrameArgument.cs diff --git a/FFMpegCore/FFMpeg/Arguments/BlackDetectArgument.cs b/FFMpegCore/FFMpeg/Arguments/BlackDetectArgument.cs new file mode 100644 index 0000000..ee088be --- /dev/null +++ b/FFMpegCore/FFMpeg/Arguments/BlackDetectArgument.cs @@ -0,0 +1,14 @@ +namespace FFMpegCore.Arguments +{ + public class BlackDetectArgument : IVideoFilterArgument + { + public string Key => "blackdetect"; + + public string Value { get; } + + public BlackDetectArgument(double minimumDuration = 2.0, double pictureBlackRatioThreshold = 0.98, double pixelBlackThreshold = 0.1) + { + Value = $"d={minimumDuration}:pic_th={pictureBlackRatioThreshold}:pix_th={pixelBlackThreshold}"; + } + } +} diff --git a/FFMpegCore/FFMpeg/Arguments/BlackFrameArgument.cs b/FFMpegCore/FFMpeg/Arguments/BlackFrameArgument.cs new file mode 100644 index 0000000..9d5bad6 --- /dev/null +++ b/FFMpegCore/FFMpeg/Arguments/BlackFrameArgument.cs @@ -0,0 +1,14 @@ +namespace FFMpegCore.Arguments +{ + internal class BlackFrameArgument : IVideoFilterArgument + { + public string Key => "blackframe"; + + public string Value { get; } + + public BlackFrameArgument(int amount = 98, int threshold = 32) + { + Value = $"amount={amount}:threshold={threshold}"; + } + } +} diff --git a/FFMpegCore/FFMpeg/Arguments/VideoFiltersArgument.cs b/FFMpegCore/FFMpeg/Arguments/VideoFiltersArgument.cs index 4d0dfde..c49803f 100644 --- a/FFMpegCore/FFMpeg/Arguments/VideoFiltersArgument.cs +++ b/FFMpegCore/FFMpeg/Arguments/VideoFiltersArgument.cs @@ -51,6 +51,8 @@ public class VideoFilterOptions public VideoFilterOptions Mirror(Mirroring mirroring) => WithArgument(new SetMirroringArgument(mirroring)); public VideoFilterOptions DrawText(DrawTextOptions drawTextOptions) => WithArgument(new DrawTextArgument(drawTextOptions)); public VideoFilterOptions HardBurnSubtitle(SubtitleHardBurnOptions subtitleHardBurnOptions) => WithArgument(new SubtitleHardBurnArgument(subtitleHardBurnOptions)); + public VideoFilterOptions BlackDetect(double minimumDuration = 2.0, double pictureBlackRatioThreshold = 0.98, double pixelBlackThreshold = 0.1) => WithArgument(new BlackDetectArgument(minimumDuration, pictureBlackRatioThreshold, pixelBlackThreshold)); + public VideoFilterOptions BlackFrame(int amount = 98, int threshold = 32) => WithArgument(new BlackFrameArgument(amount, threshold)); private VideoFilterOptions WithArgument(IVideoFilterArgument argument) {