mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
Merge pull request #250 from alex6dj/feature/get-default-and-force-value
Get extra disposition data in MediaStream
This commit is contained in:
commit
e901009774
4 changed files with 64 additions and 4 deletions
|
@ -114,5 +114,15 @@ 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.IsNotNull(info.PrimaryAudioStream.Disposition);
|
||||||
|
Assert.AreEqual(true, info.PrimaryAudioStream.Disposition["default"]);
|
||||||
|
Assert.AreEqual(false, info.PrimaryAudioStream.Disposition["forced"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 = MediaAnalysisUtils.FormatDisposition(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 = MediaAnalysisUtils.FormatDisposition(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 = MediaAnalysisUtils.FormatDisposition(stream.Disposition),
|
||||||
Tags = stream.Tags,
|
Tags = stream.Tags,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -169,5 +172,30 @@ public static TimeSpan ParseDuration(FFProbeStream ffProbeStream)
|
||||||
{
|
{
|
||||||
return ParseDuration(ffProbeStream.Duration);
|
return ParseDuration(ffProbeStream.Duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Dictionary<string, bool>? FormatDisposition(Dictionary<string, int>? disposition)
|
||||||
|
{
|
||||||
|
if (disposition == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = new Dictionary<string, bool>(disposition.Count);
|
||||||
|
|
||||||
|
foreach (var pair in disposition)
|
||||||
|
{
|
||||||
|
result.Add(pair.Key, ToBool(pair.Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ToBool(int value) => value switch
|
||||||
|
{
|
||||||
|
0 => false,
|
||||||
|
1 => true,
|
||||||
|
_ => throw new ArgumentOutOfRangeException(nameof(value),
|
||||||
|
$"Not expected disposition state value: {value}")
|
||||||
|
};
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -15,6 +15,7 @@ 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, bool>? 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);
|
||||||
|
|
Loading…
Reference in a new issue