mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
Improve ffprobe exceptions
This commit is contained in:
parent
d3193827ac
commit
27fb37700c
5 changed files with 39 additions and 5 deletions
11
FFMpegCore/FFProbe/Exceptions/FFProbeException.cs
Normal file
11
FFMpegCore/FFProbe/Exceptions/FFProbeException.cs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace FFMpegCore.Exceptions
|
||||||
|
{
|
||||||
|
public class FFProbeException : Exception
|
||||||
|
{
|
||||||
|
public FFProbeException(string message, Exception? inner = null) : base(message, inner)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
FFMpegCore/FFProbe/Exceptions/FFProbeProcessException.cs
Normal file
15
FFMpegCore/FFProbe/Exceptions/FFProbeProcessException.cs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace FFMpegCore.Exceptions
|
||||||
|
{
|
||||||
|
public class FFProbeProcessException : FFProbeException
|
||||||
|
{
|
||||||
|
public IReadOnlyCollection<string> ProcessErrors { get; }
|
||||||
|
|
||||||
|
public FFProbeProcessException(string message, IReadOnlyCollection<string> processErrors, Exception? inner = null) : base(message, inner)
|
||||||
|
{
|
||||||
|
ProcessErrors = processErrors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
FFMpegCore/FFProbe/Exceptions/FormatNullException.cs
Normal file
9
FFMpegCore/FFProbe/Exceptions/FormatNullException.cs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
namespace FFMpegCore.Exceptions
|
||||||
|
{
|
||||||
|
public class FormatNullException : FFProbeException
|
||||||
|
{
|
||||||
|
public FormatNullException() : base("Format not specified")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -93,7 +93,7 @@ public static async Task<IMediaAnalysis> AnalyseAsync(Stream stream, int outputC
|
||||||
}
|
}
|
||||||
var exitCode = await task.ConfigureAwait(false);
|
var exitCode = await task.ConfigureAwait(false);
|
||||||
if (exitCode != 0)
|
if (exitCode != 0)
|
||||||
throw new FFMpegException(FFMpegExceptionType.Process, $"FFProbe process returned exit status {exitCode}", null, string.Join("\n", instance.ErrorData));
|
throw new FFProbeProcessException($"ffprobe exited with non-zero exit-code ({exitCode} - {string.Join("\n", instance.ErrorData)})", instance.ErrorData);
|
||||||
|
|
||||||
pipeArgument.Post();
|
pipeArgument.Post();
|
||||||
return ParseOutput(instance);
|
return ParseOutput(instance);
|
||||||
|
@ -108,7 +108,7 @@ private static IMediaAnalysis ParseOutput(Instance instance)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (ffprobeAnalysis?.Format == null)
|
if (ffprobeAnalysis?.Format == null)
|
||||||
throw new Exception();
|
throw new FormatNullException();
|
||||||
|
|
||||||
return new MediaAnalysis(ffprobeAnalysis);
|
return new MediaAnalysis(ffprobeAnalysis);
|
||||||
}
|
}
|
||||||
|
@ -123,8 +123,7 @@ private static Instance PrepareInstance(string filePath, int outputCapacity, FFO
|
||||||
StandardOutputEncoding = ffOptions.Encoding,
|
StandardOutputEncoding = ffOptions.Encoding,
|
||||||
StandardErrorEncoding = ffOptions.Encoding
|
StandardErrorEncoding = ffOptions.Encoding
|
||||||
};
|
};
|
||||||
var instance = new Instance(startInfo)
|
var instance = new Instance(startInfo) { DataBufferCapacity = outputCapacity };
|
||||||
{ DataBufferCapacity = outputCapacity };
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public static void VerifyFFProbeExists(FFOptions ffMpegOptions)
|
||||||
var (exitCode, _) = Instance.Finish(GlobalFFOptions.GetFFProbeBinaryPath(ffMpegOptions), "-version");
|
var (exitCode, _) = Instance.Finish(GlobalFFOptions.GetFFProbeBinaryPath(ffMpegOptions), "-version");
|
||||||
_ffprobeVerified = exitCode == 0;
|
_ffprobeVerified = exitCode == 0;
|
||||||
if (!_ffprobeVerified)
|
if (!_ffprobeVerified)
|
||||||
throw new FFMpegException(FFMpegExceptionType.Operation, "ffprobe was not found on your system");
|
throw new FFProbeException("ffprobe was not found on your system");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue