diff --git a/FFMpegCore/FFMpeg/Enums/FFMpegLogLevel.cs b/FFMpegCore/FFMpeg/Enums/FFMpegLogLevel.cs new file mode 100644 index 00000000..aa2ca23a --- /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 43ace4d9..5026ea5d 100644 --- a/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs +++ b/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs @@ -5,6 +5,7 @@ using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; +using FFMpegCore.Enums; using FFMpegCore.Exceptions; using FFMpegCore.Helpers; using Instances; @@ -21,6 +22,7 @@ public class FFMpegArgumentProcessor private Action? _onOutput; private Action? _onError; private TimeSpan? _totalTimespan; + private FFMpegLogLevel? _logLevel; internal FFMpegArgumentProcessor(FFMpegArguments ffMpegArguments) { @@ -83,12 +85,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 { @@ -107,7 +120,7 @@ public async Task ProcessAsynchronously(bool throwOnError = true, FFOption { var options = GetConfiguredOptions(ffMpegOptions); var processArguments = PrepareProcessArguments(options, out var cancellationTokenSource); - + IProcessResult? processResult = null; try { @@ -118,7 +131,7 @@ public async Task ProcessAsynchronously(bool throwOnError = true, FFOption if (throwOnError) throw; } - + return HandleCompletion(throwOnError, processResult?.ExitCode ?? -1, processResult?.ErrorData ?? Array.Empty()); } @@ -193,10 +206,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 @@ -206,7 +234,7 @@ private ProcessArguments PrepareProcessArguments(FFOptions ffOptions, if (_onOutput != null || _onTimeProgress != null || (_onPercentageProgress != null && _totalTimespan != null)) processArguments.OutputDataReceived += OutputData; - + if (_onError != null) processArguments.ErrorDataReceived += ErrorData; diff --git a/FFMpegCore/FFOptions.cs b/FFMpegCore/FFOptions.cs index a34bca2c..5e80c1e3 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; } + /// /// ///