Get extra disposition data in MediaStream

This commit is contained in:
alex6dj 2021-09-06 23:08:36 -04:00
parent a76ec851c8
commit 41ec1a10dd
4 changed files with 38 additions and 4 deletions

View file

@ -114,5 +114,14 @@ public async Task Probe_Success_Subtitle_Async()
Assert.AreEqual(0, info.AudioStreams.Count); Assert.AreEqual(0, info.AudioStreams.Count);
Assert.AreEqual(0, info.VideoStreams.Count); Assert.AreEqual(0, info.VideoStreams.Count);
} }
[TestMethod, Timeout(10000)]
public async Task Probe_Success_Disposition_Async()
{
var info = await FFProbe.AnalyseAsync(TestResources.Mp4Video);
Assert.IsNotNull(info.PrimaryAudioStream);
Assert.AreEqual(1, info.PrimaryAudioStream.Disposition["default"]);
Assert.AreEqual(0, info.PrimaryAudioStream.Disposition["forced"]);
}
} }
} }

View file

@ -12,7 +12,7 @@ public class FFProbeAnalysis
public Format Format { get; set; } = null!; public Format Format { get; set; } = null!;
} }
public class FFProbeStream : ITagsContainer public class FFProbeStream : ITagsContainer, IDispositionContainer
{ {
[JsonPropertyName("index")] [JsonPropertyName("index")]
public int Index { get; set; } public int Index { get; set; }
@ -71,9 +71,13 @@ public class FFProbeStream : ITagsContainer
[JsonPropertyName("sample_rate")] [JsonPropertyName("sample_rate")]
public string SampleRate { get; set; } = null!; public string SampleRate { get; set; } = null!;
[JsonPropertyName("disposition")]
public Dictionary<string, int> Disposition { get; set; } = null!;
[JsonPropertyName("tags")] [JsonPropertyName("tags")]
public Dictionary<string, string> Tags { get; set; } = null!; public Dictionary<string, string> Tags { get; set; } = null!;
} }
public class Format : ITagsContainer public class Format : ITagsContainer
{ {
[JsonPropertyName("filename")] [JsonPropertyName("filename")]
@ -110,10 +114,16 @@ public class Format : ITagsContainer
public Dictionary<string, string> Tags { get; set; } = null!; public Dictionary<string, string> Tags { get; set; } = null!;
} }
public interface IDispositionContainer
{
Dictionary<string, int> Disposition { get; set; }
}
public interface ITagsContainer public interface ITagsContainer
{ {
Dictionary<string, string> Tags { get; set; } Dictionary<string, string> Tags { get; set; }
} }
public static class TagExtensions public static class TagExtensions
{ {
private static string? TryGetTagValue(ITagsContainer tagsContainer, string key) private static string? TryGetTagValue(ITagsContainer tagsContainer, string key)
@ -127,7 +137,18 @@ public static class TagExtensions
public static string? GetCreationTime(this ITagsContainer tagsContainer) => TryGetTagValue(tagsContainer, "creation_time "); public static string? GetCreationTime(this ITagsContainer tagsContainer) => TryGetTagValue(tagsContainer, "creation_time ");
public static string? GetRotate(this ITagsContainer tagsContainer) => TryGetTagValue(tagsContainer, "rotate"); public static string? GetRotate(this ITagsContainer tagsContainer) => TryGetTagValue(tagsContainer, "rotate");
public static string? GetDuration(this ITagsContainer tagsContainer) => TryGetTagValue(tagsContainer, "duration"); public static string? GetDuration(this ITagsContainer tagsContainer) => TryGetTagValue(tagsContainer, "duration");
}
public static class DispositionExtensions
{
private static int? TryGetDispositionValue(IDispositionContainer dispositionContainer, string key)
{
if (dispositionContainer.Disposition != null && dispositionContainer.Disposition.TryGetValue(key, out var dispositionValue))
return dispositionValue;
return null;
}
public static int? GetDefault(this IDispositionContainer tagsContainer) => TryGetDispositionValue(tagsContainer, "default");
public static int? GetForced(this IDispositionContainer tagsContainer) => TryGetDispositionValue(tagsContainer, "forced");
} }
} }

View file

@ -67,6 +67,7 @@ private VideoStream ParseVideoStream(FFProbeStream stream)
PixelFormat = stream.PixelFormat, PixelFormat = stream.PixelFormat,
Rotation = (int)float.Parse(stream.GetRotate() ?? "0"), Rotation = (int)float.Parse(stream.GetRotate() ?? "0"),
Language = stream.GetLanguage(), Language = stream.GetLanguage(),
Disposition = stream.Disposition,
Tags = stream.Tags, Tags = stream.Tags,
}; };
} }
@ -87,6 +88,7 @@ private AudioStream ParseAudioStream(FFProbeStream stream)
SampleRateHz = !string.IsNullOrEmpty(stream.SampleRate) ? MediaAnalysisUtils.ParseIntInvariant(stream.SampleRate) : default, SampleRateHz = !string.IsNullOrEmpty(stream.SampleRate) ? MediaAnalysisUtils.ParseIntInvariant(stream.SampleRate) : default,
Profile = stream.Profile, Profile = stream.Profile,
Language = stream.GetLanguage(), Language = stream.GetLanguage(),
Disposition = stream.Disposition,
Tags = stream.Tags, Tags = stream.Tags,
}; };
} }
@ -101,6 +103,7 @@ private SubtitleStream ParseSubtitleStream(FFProbeStream stream)
CodecLongName = stream.CodecLongName, CodecLongName = stream.CodecLongName,
Duration = MediaAnalysisUtils.ParseDuration(stream), Duration = MediaAnalysisUtils.ParseDuration(stream),
Language = stream.GetLanguage(), Language = stream.GetLanguage(),
Disposition = stream.Disposition,
Tags = stream.Tags, Tags = stream.Tags,
}; };
} }

View file

@ -15,8 +15,9 @@ public class MediaStream
public int BitRate { get; internal set; } public int BitRate { get; internal set; }
public TimeSpan Duration { get; internal set; } public TimeSpan Duration { get; internal set; }
public string? Language { get; internal set; } public string? Language { get; internal set; }
public Dictionary<string, int>? Disposition { get; internal set; }
public Dictionary<string, string>? Tags { get; internal set; } public Dictionary<string, string>? Tags { get; internal set; }
public Codec GetCodecInfo() => FFMpeg.GetCodec(CodecName); public Codec GetCodecInfo() => FFMpeg.GetCodec(CodecName);
} }
} }