mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-12-14 01:55:45 +00:00
Merge 89d4235f7a into cc75e03ec9
This commit is contained in:
commit
076f754267
3 changed files with 42 additions and 11 deletions
|
|
@ -12,6 +12,11 @@ namespace FFMpegCore;
|
|||
public static class FFProbe
|
||||
{
|
||||
public static IMediaAnalysis Analyse(string filePath, FFOptions? ffOptions = null, string? customArguments = null)
|
||||
{
|
||||
return new MediaAnalysis(GetAnalysis(filePath, ffOptions, customArguments));
|
||||
}
|
||||
|
||||
public static FFProbeAnalysis GetAnalysis(string filePath, FFOptions? ffOptions = null, string? customArguments = null)
|
||||
{
|
||||
ThrowIfInputFileDoesNotExist(filePath);
|
||||
|
||||
|
|
@ -19,7 +24,7 @@ public static class FFProbe
|
|||
var result = processArguments.StartAndWaitForExit();
|
||||
ThrowIfExitCodeNotZero(result);
|
||||
|
||||
return ParseOutput(result);
|
||||
return DeserializeOutput(result);
|
||||
}
|
||||
|
||||
public static FFProbeFrames GetFrames(string filePath, FFOptions? ffOptions = null, string? customArguments = null)
|
||||
|
|
@ -45,15 +50,25 @@ public static class FFProbe
|
|||
}
|
||||
|
||||
public static IMediaAnalysis Analyse(Uri uri, FFOptions? ffOptions = null, string? customArguments = null)
|
||||
{
|
||||
return new MediaAnalysis(GetAnalysis(uri, ffOptions, customArguments));
|
||||
}
|
||||
|
||||
public static FFProbeAnalysis GetAnalysis(Uri uri, FFOptions? ffOptions = null, string? customArguments = null)
|
||||
{
|
||||
var instance = PrepareStreamAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current, customArguments);
|
||||
var result = instance.StartAndWaitForExit();
|
||||
ThrowIfExitCodeNotZero(result);
|
||||
|
||||
return ParseOutput(result);
|
||||
return DeserializeOutput(result);
|
||||
}
|
||||
|
||||
public static IMediaAnalysis Analyse(Stream stream, FFOptions? ffOptions = null, string? customArguments = null)
|
||||
{
|
||||
return new MediaAnalysis(GetAnalysis(stream, ffOptions, customArguments));
|
||||
}
|
||||
|
||||
public static FFProbeAnalysis GetAnalysis(Stream stream, FFOptions? ffOptions = null, string? customArguments = null)
|
||||
{
|
||||
var streamPipeSource = new StreamPipeSource(stream);
|
||||
var pipeArgument = new InputPipeArgument(streamPipeSource);
|
||||
|
|
@ -74,11 +89,17 @@ public static class FFProbe
|
|||
var result = task.ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
ThrowIfExitCodeNotZero(result);
|
||||
|
||||
return ParseOutput(result);
|
||||
return DeserializeOutput(result);
|
||||
}
|
||||
|
||||
public static async Task<IMediaAnalysis> AnalyseAsync(string filePath, FFOptions? ffOptions = null, CancellationToken cancellationToken = default,
|
||||
string? customArguments = null)
|
||||
{
|
||||
return new MediaAnalysis(await GetAnalysisAsync(filePath, ffOptions, cancellationToken, customArguments));
|
||||
}
|
||||
|
||||
public static async Task<FFProbeAnalysis> GetAnalysisAsync(string filePath, FFOptions? ffOptions = null, CancellationToken cancellationToken = default,
|
||||
string? customArguments = null)
|
||||
{
|
||||
ThrowIfInputFileDoesNotExist(filePath);
|
||||
|
||||
|
|
@ -87,7 +108,7 @@ public static class FFProbe
|
|||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfExitCodeNotZero(result);
|
||||
|
||||
return ParseOutput(result);
|
||||
return DeserializeOutput(result);
|
||||
}
|
||||
|
||||
public static FFProbeFrames GetFrames(Uri uri, FFOptions? ffOptions = null, string? customArguments = null)
|
||||
|
|
@ -121,17 +142,27 @@ public static class FFProbe
|
|||
|
||||
public static async Task<IMediaAnalysis> AnalyseAsync(Uri uri, FFOptions? ffOptions = null, CancellationToken cancellationToken = default,
|
||||
string? customArguments = null)
|
||||
{
|
||||
return new MediaAnalysis(await GetAnalysisAsync(uri, ffOptions, cancellationToken, customArguments));
|
||||
}
|
||||
public static async Task<FFProbeAnalysis> GetAnalysisAsync(Uri uri, FFOptions? ffOptions = null, CancellationToken cancellationToken = default,
|
||||
string? customArguments = null)
|
||||
{
|
||||
var instance = PrepareStreamAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current, customArguments);
|
||||
var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfExitCodeNotZero(result);
|
||||
|
||||
return ParseOutput(result);
|
||||
return DeserializeOutput(result);
|
||||
}
|
||||
|
||||
public static async Task<IMediaAnalysis> AnalyseAsync(Stream stream, FFOptions? ffOptions = null, CancellationToken cancellationToken = default,
|
||||
string? customArguments = null)
|
||||
{
|
||||
return new MediaAnalysis(await GetAnalysisAsync(stream, ffOptions, cancellationToken, customArguments));
|
||||
}
|
||||
public static async Task<FFProbeAnalysis> GetAnalysisAsync(Stream stream, FFOptions? ffOptions = null, CancellationToken cancellationToken = default,
|
||||
string? customArguments = null)
|
||||
{
|
||||
var streamPipeSource = new StreamPipeSource(stream);
|
||||
var pipeArgument = new InputPipeArgument(streamPipeSource);
|
||||
|
|
@ -156,7 +187,7 @@ public static class FFProbe
|
|||
ThrowIfExitCodeNotZero(result);
|
||||
|
||||
pipeArgument.Post();
|
||||
return ParseOutput(result);
|
||||
return DeserializeOutput(result);
|
||||
}
|
||||
|
||||
public static async Task<FFProbeFrames> GetFramesAsync(Uri uri, FFOptions? ffOptions = null, CancellationToken cancellationToken = default,
|
||||
|
|
@ -167,7 +198,7 @@ public static class FFProbe
|
|||
return ParseFramesOutput(result);
|
||||
}
|
||||
|
||||
private static IMediaAnalysis ParseOutput(IProcessResult instance)
|
||||
private static FFProbeAnalysis DeserializeOutput(IProcessResult instance)
|
||||
{
|
||||
var json = string.Join(string.Empty, instance.OutputData);
|
||||
var ffprobeAnalysis = JsonSerializer.Deserialize<FFProbeAnalysis>(json, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
|
|
@ -178,7 +209,7 @@ public static class FFProbe
|
|||
}
|
||||
|
||||
ffprobeAnalysis.ErrorData = instance.ErrorData;
|
||||
return new MediaAnalysis(ffprobeAnalysis);
|
||||
return ffprobeAnalysis;
|
||||
}
|
||||
|
||||
private static FFProbeFrames ParseFramesOutput(IProcessResult instance)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ public class FFProbeAnalysis
|
|||
|
||||
[JsonPropertyName("chapters")] public List<Chapter> Chapters { get; set; } = null!;
|
||||
|
||||
[JsonIgnore] public IReadOnlyList<string> ErrorData { get; set; } = new List<string>();
|
||||
public IReadOnlyList<string> ErrorData { get; set; } = new List<string>();
|
||||
}
|
||||
|
||||
public class FFProbeStream : ITagsContainer, IDispositionContainer
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ using FFMpegCore.Builders.MetaData;
|
|||
|
||||
namespace FFMpegCore;
|
||||
|
||||
internal class MediaAnalysis : IMediaAnalysis
|
||||
public class MediaAnalysis : IMediaAnalysis
|
||||
{
|
||||
internal MediaAnalysis(FFProbeAnalysis analysis)
|
||||
public MediaAnalysis(FFProbeAnalysis analysis)
|
||||
{
|
||||
Format = ParseFormat(analysis.Format);
|
||||
Chapters = analysis.Chapters.Select(c => ParseChapter(c)).ToList();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue