mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
Return null when no format detected during analysis
This commit is contained in:
parent
8d2251c136
commit
66cdb302ef
1 changed files with 8 additions and 7 deletions
|
@ -12,7 +12,7 @@ namespace FFMpegCore
|
|||
{
|
||||
public static class FFProbe
|
||||
{
|
||||
public static IMediaAnalysis Analyse(string filePath, int outputCapacity = int.MaxValue)
|
||||
public static IMediaAnalysis? Analyse(string filePath, int outputCapacity = int.MaxValue)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
throw new FFMpegException(FFMpegExceptionType.File, $"No file found at '{filePath}'");
|
||||
|
@ -21,13 +21,13 @@ public static IMediaAnalysis Analyse(string filePath, int outputCapacity = int.M
|
|||
instance.BlockUntilFinished();
|
||||
return ParseOutput(filePath, instance);
|
||||
}
|
||||
public static IMediaAnalysis Analyse(Uri uri, int outputCapacity = int.MaxValue)
|
||||
public static IMediaAnalysis? Analyse(Uri uri, int outputCapacity = int.MaxValue)
|
||||
{
|
||||
using var instance = PrepareInstance(uri.AbsoluteUri, outputCapacity);
|
||||
instance.BlockUntilFinished();
|
||||
return ParseOutput(uri.AbsoluteUri, instance);
|
||||
}
|
||||
public static IMediaAnalysis Analyse(Stream stream, int outputCapacity = int.MaxValue)
|
||||
public static IMediaAnalysis? Analyse(Stream stream, int outputCapacity = int.MaxValue)
|
||||
{
|
||||
var streamPipeSource = new StreamPipeSource(stream);
|
||||
var pipeArgument = new InputPipeArgument(streamPipeSource);
|
||||
|
@ -50,7 +50,7 @@ public static IMediaAnalysis Analyse(Stream stream, int outputCapacity = int.Max
|
|||
|
||||
return ParseOutput(pipeArgument.PipePath, instance);
|
||||
}
|
||||
public static async Task<IMediaAnalysis> AnalyseAsync(string filePath, int outputCapacity = int.MaxValue)
|
||||
public static async Task<IMediaAnalysis?> AnalyseAsync(string filePath, int outputCapacity = int.MaxValue)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
throw new FFMpegException(FFMpegExceptionType.File, $"No file found at '{filePath}'");
|
||||
|
@ -59,13 +59,13 @@ public static async Task<IMediaAnalysis> AnalyseAsync(string filePath, int outpu
|
|||
await instance.FinishedRunning();
|
||||
return ParseOutput(filePath, instance);
|
||||
}
|
||||
public static async Task<IMediaAnalysis> AnalyseAsync(Uri uri, int outputCapacity = int.MaxValue)
|
||||
public static async Task<IMediaAnalysis?> AnalyseAsync(Uri uri, int outputCapacity = int.MaxValue)
|
||||
{
|
||||
using var instance = PrepareInstance(uri.AbsoluteUri, outputCapacity);
|
||||
await instance.FinishedRunning();
|
||||
return ParseOutput(uri.AbsoluteUri, instance);
|
||||
}
|
||||
public static async Task<IMediaAnalysis> AnalyseAsync(Stream stream, int outputCapacity = int.MaxValue)
|
||||
public static async Task<IMediaAnalysis?> AnalyseAsync(Stream stream, int outputCapacity = int.MaxValue)
|
||||
{
|
||||
var streamPipeSource = new StreamPipeSource(stream);
|
||||
var pipeArgument = new InputPipeArgument(streamPipeSource);
|
||||
|
@ -92,13 +92,14 @@ public static async Task<IMediaAnalysis> AnalyseAsync(Stream stream, int outputC
|
|||
return ParseOutput(pipeArgument.PipePath, instance);
|
||||
}
|
||||
|
||||
private static IMediaAnalysis ParseOutput(string filePath, Instance instance)
|
||||
private static IMediaAnalysis? ParseOutput(string filePath, Instance instance)
|
||||
{
|
||||
var json = string.Join(string.Empty, instance.OutputData);
|
||||
var ffprobeAnalysis = JsonSerializer.Deserialize<FFProbeAnalysis>(json, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
})!;
|
||||
if (ffprobeAnalysis?.Format == null) return null;
|
||||
return new MediaAnalysis(filePath, ffprobeAnalysis);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue