fix: Switch source for rotation property from 'tags/rotate' to 'side_data_list/rotation' (incl. test case) (#388)

This commit is contained in:
pklaes 2023-02-04 22:17:39 +01:00 committed by GitHub
parent f9f7161686
commit d051cd06d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 2 deletions

View file

@ -42,6 +42,9 @@
<None Update="Resources\input_3sec.webm"> <None Update="Resources\input_3sec.webm">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Update="Resources\input_3sec_rotation_90deg.mp4">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\input_audio_only_10sec.mp4"> <None Update="Resources\input_audio_only_10sec.mp4">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>

View file

@ -134,6 +134,16 @@ public void Probe_Success()
Assert.AreEqual("0x31637661", info.PrimaryVideoStream.CodecTag); Assert.AreEqual("0x31637661", info.PrimaryVideoStream.CodecTag);
} }
[TestMethod]
public void Probe_Rotation()
{
var info = FFProbe.Analyse(TestResources.Mp4Video);
Assert.AreEqual(0, info.PrimaryVideoStream.Rotation);
info = FFProbe.Analyse(TestResources.Mp4VideoRotation);
Assert.AreEqual(90, info.PrimaryVideoStream.Rotation);
}
[TestMethod, Timeout(10000)] [TestMethod, Timeout(10000)]
public async Task Probe_Async_Success() public async Task Probe_Async_Success()
{ {

View file

@ -13,6 +13,7 @@ public enum ImageType
public static class TestResources public static class TestResources
{ {
public static readonly string Mp4Video = "./Resources/input_3sec.mp4"; public static readonly string Mp4Video = "./Resources/input_3sec.mp4";
public static readonly string Mp4VideoRotation = "./Resources/input_3sec_rotation_90deg.mp4";
public static readonly string WebmVideo = "./Resources/input_3sec.webm"; public static readonly string WebmVideo = "./Resources/input_3sec.webm";
public static readonly string Mp4WithoutVideo = "./Resources/input_audio_only_10sec.mp4"; public static readonly string Mp4WithoutVideo = "./Resources/input_audio_only_10sec.mp4";
public static readonly string Mp4WithoutAudio = "./Resources/input_video_only_3sec.mp4"; public static readonly string Mp4WithoutAudio = "./Resources/input_video_only_3sec.mp4";

View file

@ -1,4 +1,5 @@
using System.Text.Json.Serialization; using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
namespace FFMpegCore namespace FFMpegCore
{ {
@ -84,6 +85,9 @@ public class FFProbeStream : ITagsContainer, IDispositionContainer
[JsonPropertyName("tags")] [JsonPropertyName("tags")]
public Dictionary<string, string> Tags { get; set; } = null!; public Dictionary<string, string> Tags { get; set; } = null!;
[JsonPropertyName("side_data_list")]
public List<Dictionary<string, JsonValue>> SideData { get; set; } = null!;
} }
public class Format : ITagsContainer public class Format : ITagsContainer

View file

@ -72,7 +72,7 @@ private VideoStream ParseVideoStream(FFProbeStream stream)
Width = stream.Width ?? 0, Width = stream.Width ?? 0,
Profile = stream.Profile, Profile = stream.Profile,
PixelFormat = stream.PixelFormat, PixelFormat = stream.PixelFormat,
Rotation = (int)float.Parse(stream.GetRotate() ?? "0"), Rotation = MediaAnalysisUtils.ParseRotation(stream),
Language = stream.GetLanguage(), Language = stream.GetLanguage(),
Disposition = MediaAnalysisUtils.FormatDisposition(stream.Disposition), Disposition = MediaAnalysisUtils.FormatDisposition(stream.Disposition),
Tags = stream.Tags.ToCaseInsensitive(), Tags = stream.Tags.ToCaseInsensitive(),
@ -196,6 +196,20 @@ public static TimeSpan ParseDuration(FFProbeStream ffProbeStream)
return ParseDuration(ffProbeStream.Duration); return ParseDuration(ffProbeStream.Duration);
} }
public static int ParseRotation(FFProbeStream fFProbeStream)
{
var displayMatrixSideData = fFProbeStream.SideData?.Find(item => item.TryGetValue("side_data_type", out var rawSideDataType) && rawSideDataType.ToString() == "Display Matrix");
if (displayMatrixSideData?.TryGetValue("rotation", out var rawRotation) ?? false)
{
return (int)float.Parse(rawRotation.ToString());
}
else
{
return (int)float.Parse(fFProbeStream.GetRotate() ?? "0");
}
}
public static Dictionary<string, bool>? FormatDisposition(Dictionary<string, int>? disposition) public static Dictionary<string, bool>? FormatDisposition(Dictionary<string, int>? disposition)
{ {
if (disposition == null) if (disposition == null)