Added log levels

Former-commit-id: 6e4e8fbba1
This commit is contained in:
Thodoris Koskinopoulos 2022-11-27 05:55:00 +02:00 committed by Malte Rosenbjerg
parent f042d78f2c
commit f405269244
3 changed files with 55 additions and 3 deletions

View file

@ -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
}
}

View file

@ -21,6 +21,7 @@ public class FFMpegArgumentProcessor
private Action<string>? _onOutput; private Action<string>? _onOutput;
private Action<string>? _onError; private Action<string>? _onError;
private TimeSpan? _totalTimespan; private TimeSpan? _totalTimespan;
private FFMpegLogLevel? _logLevel;
internal FFMpegArgumentProcessor(FFMpegArguments ffMpegArguments) internal FFMpegArgumentProcessor(FFMpegArguments ffMpegArguments)
{ {
@ -83,12 +84,23 @@ public FFMpegArgumentProcessor Configure(Action<FFOptions> configureOptions)
_configurations.Add(configureOptions); _configurations.Add(configureOptions);
return this; return this;
} }
/// <summary>
/// Sets the log level of this process. Overides the <see cref="FFMpegLogLevel"/>
/// that is set in the <see cref="FFOptions"/> for this specific process.
/// </summary>
/// <param name="logLevel">The log level of the ffmpeg execution.</param>
public FFMpegArgumentProcessor WithLogLevel(FFMpegLogLevel logLevel)
{
_logLevel = logLevel;
return this;
}
public bool ProcessSynchronously(bool throwOnError = true, FFOptions? ffMpegOptions = null) public bool ProcessSynchronously(bool throwOnError = true, FFOptions? ffMpegOptions = null)
{ {
var options = GetConfiguredOptions(ffMpegOptions); var options = GetConfiguredOptions(ffMpegOptions);
var processArguments = PrepareProcessArguments(options, out var cancellationTokenSource); var processArguments = PrepareProcessArguments(options, out var cancellationTokenSource);
IProcessResult? processResult = null; IProcessResult? processResult = null;
try try
{ {
@ -193,10 +205,25 @@ private ProcessArguments PrepareProcessArguments(FFOptions ffOptions,
{ {
FFMpegHelper.RootExceptionCheck(); FFMpegHelper.RootExceptionCheck();
FFMpegHelper.VerifyFFMpegExists(ffOptions); 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 var startInfo = new ProcessStartInfo
{ {
FileName = GlobalFFOptions.GetFFMpegBinaryPath(ffOptions), FileName = GlobalFFOptions.GetFFMpegBinaryPath(ffOptions),
Arguments = _ffMpegArguments.Text, Arguments = arguments,
StandardOutputEncoding = ffOptions.Encoding, StandardOutputEncoding = ffOptions.Encoding,
StandardErrorEncoding = ffOptions.Encoding, StandardErrorEncoding = ffOptions.Encoding,
WorkingDirectory = ffOptions.WorkingDirectory WorkingDirectory = ffOptions.WorkingDirectory

View file

@ -1,4 +1,5 @@
using System; using FFMpegCore.Enums;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text; using System.Text;
@ -27,6 +28,15 @@ public class FFOptions : ICloneable
/// </summary> /// </summary>
public Encoding Encoding { get; set; } = Encoding.Default; public Encoding Encoding { get; set; } = Encoding.Default;
/// <summary>
/// The log level to use when calling of the ffmpeg executable.
/// <para>
/// This option can be overridden before an execution of a Process command
/// to set the log level for that command.
/// </para>
/// </summary>
public FFMpegLogLevel? LogLevel { get; set; }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>