mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
parent
385e50bcee
commit
e264c93f67
3 changed files with 29 additions and 19 deletions
|
@ -12,7 +12,7 @@ public class FFProbeAnalysis
|
|||
public Format Format { get; set; } = null!;
|
||||
}
|
||||
|
||||
public class FFProbeStream
|
||||
public class FFProbeStream : ITagsContainer
|
||||
{
|
||||
[JsonPropertyName("index")]
|
||||
public int Index { get; set; }
|
||||
|
@ -66,21 +66,9 @@ public class FFProbeStream
|
|||
public string SampleRate { get; set; } = null!;
|
||||
|
||||
[JsonPropertyName("tags")]
|
||||
public Tags Tags { get; set; } = null!;
|
||||
public Dictionary<string, string> Tags { get; set; } = null!;
|
||||
}
|
||||
|
||||
public class Tags
|
||||
{
|
||||
[JsonPropertyName("DURATION")]
|
||||
public string Duration { get; set; } = null!;
|
||||
|
||||
[JsonPropertyName("language")]
|
||||
public string Language { get; set; } = null!;
|
||||
|
||||
[JsonPropertyName("encoder")]
|
||||
public string Encoder { get; set; } = null!;
|
||||
}
|
||||
public class Format
|
||||
public class Format : ITagsContainer
|
||||
{
|
||||
[JsonPropertyName("filename")]
|
||||
public string Filename { get; set; } = null!;
|
||||
|
@ -113,6 +101,26 @@ public class Format
|
|||
public int ProbeScore { get; set; }
|
||||
|
||||
[JsonPropertyName("tags")]
|
||||
public Tags Tags { get; set; } = null!;
|
||||
public Dictionary<string, string> Tags { get; set; } = null!;
|
||||
}
|
||||
|
||||
public interface ITagsContainer
|
||||
{
|
||||
Dictionary<string, string> Tags { get; set; }
|
||||
}
|
||||
public static class TagExtensions
|
||||
{
|
||||
private static string? TryGetTagValue(ITagsContainer tagsContainer, string key)
|
||||
{
|
||||
if (tagsContainer.Tags != null && tagsContainer.Tags.TryGetValue(key, out var tagValue))
|
||||
return tagValue;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string? GetLanguage(this ITagsContainer tagsContainer) => TryGetTagValue(tagsContainer, "language");
|
||||
public static string? GetRotate(this ITagsContainer tagsContainer) => TryGetTagValue(tagsContainer, "rotate");
|
||||
public static string? GetDuration(this ITagsContainer tagsContainer) => TryGetTagValue(tagsContainer, "duration");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,8 @@ private VideoStream ParseVideoStream(FFProbeStream stream)
|
|||
Width = stream.Width ?? 0,
|
||||
Profile = stream.Profile,
|
||||
PixelFormat = stream.PixelFormat,
|
||||
Language = stream.Tags?.Language
|
||||
Rotation = (int)float.Parse(stream.GetRotate() ?? "0"),
|
||||
Language = stream.GetLanguage()
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -74,7 +75,7 @@ private static TimeSpan ParseDuration(FFProbeStream ffProbeStream)
|
|||
{
|
||||
return !string.IsNullOrEmpty(ffProbeStream.Duration)
|
||||
? TimeSpan.Parse(ffProbeStream.Duration)
|
||||
: TimeSpan.Parse(TrimTimeSpan(ffProbeStream.Tags?.Duration) ?? "0");
|
||||
: TimeSpan.Parse(TrimTimeSpan(ffProbeStream.GetDuration()) ?? "0");
|
||||
}
|
||||
private static string? TrimTimeSpan(string? durationTag)
|
||||
{
|
||||
|
@ -95,7 +96,7 @@ private AudioStream ParseAudioStream(FFProbeStream stream)
|
|||
Duration = ParseDuration(stream),
|
||||
SampleRateHz = !string.IsNullOrEmpty(stream.SampleRate) ? ParseIntInvariant(stream.SampleRate) : default,
|
||||
Profile = stream.Profile,
|
||||
Language = stream.Tags?.Language
|
||||
Language = stream.GetLanguage()
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ public class VideoStream : MediaStream
|
|||
public int Height { get; internal set; }
|
||||
public double FrameRate { get; internal set; }
|
||||
public string PixelFormat { get; internal set; } = null!;
|
||||
public int Rotation { get; set; }
|
||||
|
||||
public PixelFormat GetPixelFormatInfo() => FFMpeg.GetPixelFormat(PixelFormat);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue