From f042d78f2c727301eaef1ae04b2e86870b0d4b59 Mon Sep 17 00:00:00 2001 From: Thodoris Koskinopoulos Date: Sun, 27 Nov 2022 05:54:29 +0200 Subject: [PATCH 1/3] Added blackdetect and blackframe arguments Former-commit-id: 7f72625eacd3efb6e53605e9b3471402edc77850 --- 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) { From f40526924456438de84e86f624a9e9b2afad4c7c Mon Sep 17 00:00:00 2001 From: Thodoris Koskinopoulos Date: Sun, 27 Nov 2022 05:55:00 +0200 Subject: [PATCH 2/3] Added log levels Former-commit-id: 6e4e8fbba1ac6c3bddd5de2da8b6fe0284af8d1d --- FFMpegCore/FFMpeg/Enums/FFMpegLogLevel.cs | 15 ++++++++++ FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs | 31 ++++++++++++++++++-- FFMpegCore/FFOptions.cs | 12 +++++++- 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 FFMpegCore/FFMpeg/Enums/FFMpegLogLevel.cs diff --git a/FFMpegCore/FFMpeg/Enums/FFMpegLogLevel.cs b/FFMpegCore/FFMpeg/Enums/FFMpegLogLevel.cs new file mode 100644 index 0000000..aa2ca23 --- /dev/null +++ b/FFMpegCore/FFMpeg/Enums/FFMpegLogLevel.cs @@ -0,0 +1,15 @@ +namespace FFMpegCore.Enums +{ + public enum FFMpegLogLevel + { + Quiet = 0, + Panic = 1, + Fatal = 2, + Error = 3, + Warning = 4, + Info = 5, + Verbose = 6, + Debug = 7, + Trace = 8 + } +} diff --git a/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs b/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs index dd2a5e9..ac704f8 100644 --- a/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs +++ b/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs @@ -21,6 +21,7 @@ public class FFMpegArgumentProcessor private Action? _onOutput; private Action? _onError; private TimeSpan? _totalTimespan; + private FFMpegLogLevel? _logLevel; internal FFMpegArgumentProcessor(FFMpegArguments ffMpegArguments) { @@ -83,12 +84,23 @@ public FFMpegArgumentProcessor Configure(Action configureOptions) _configurations.Add(configureOptions); return this; } + + /// + /// Sets the log level of this process. Overides the + /// that is set in the for this specific process. + /// + /// The log level of the ffmpeg execution. + public FFMpegArgumentProcessor WithLogLevel(FFMpegLogLevel logLevel) + { + _logLevel = logLevel; + return this; + } + public bool ProcessSynchronously(bool throwOnError = true, FFOptions? ffMpegOptions = null) { var options = GetConfiguredOptions(ffMpegOptions); var processArguments = PrepareProcessArguments(options, out var cancellationTokenSource); - IProcessResult? processResult = null; try { @@ -193,10 +205,25 @@ private ProcessArguments PrepareProcessArguments(FFOptions ffOptions, { FFMpegHelper.RootExceptionCheck(); FFMpegHelper.VerifyFFMpegExists(ffOptions); + + string? arguments = _ffMpegArguments.Text; + + //If local loglevel is null, set the global. + if (_logLevel == null) + _logLevel = ffOptions.LogLevel; + + //If neither local nor global loglevel is null, set the argument. + if (_logLevel != null) + { + string normalizedLogLevel = _logLevel.ToString() + .ToLower(); + arguments += $" -v {normalizedLogLevel}"; + } + var startInfo = new ProcessStartInfo { FileName = GlobalFFOptions.GetFFMpegBinaryPath(ffOptions), - Arguments = _ffMpegArguments.Text, + Arguments = arguments, StandardOutputEncoding = ffOptions.Encoding, StandardErrorEncoding = ffOptions.Encoding, WorkingDirectory = ffOptions.WorkingDirectory diff --git a/FFMpegCore/FFOptions.cs b/FFMpegCore/FFOptions.cs index a34bca2..5e80c1e 100644 --- a/FFMpegCore/FFOptions.cs +++ b/FFMpegCore/FFOptions.cs @@ -1,4 +1,5 @@ -using System; +using FFMpegCore.Enums; +using System; using System.Collections.Generic; using System.IO; using System.Text; @@ -27,6 +28,15 @@ public class FFOptions : ICloneable /// public Encoding Encoding { get; set; } = Encoding.Default; + /// + /// The log level to use when calling of the ffmpeg executable. + /// + /// This option can be overridden before an execution of a Process command + /// to set the log level for that command. + /// + /// + public FFMpegLogLevel? LogLevel { get; set; } + /// /// /// From d5974f55854d078eab5d530cc61c69771561c2a2 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Tue, 31 Jan 2023 20:15:59 +0100 Subject: [PATCH 3/3] Add missing using directive after rebase Former-commit-id: 8fca6c403596dde5836806012d080e9b56ea2af9 --- FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs b/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs index ac704f8..423f881 100644 --- a/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs +++ b/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs @@ -8,6 +8,7 @@ using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; +using FFMpegCore.Enums; namespace FFMpegCore {