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