diff --git a/FFMpegCore.Test/FFMpegCore.Test.csproj b/FFMpegCore.Test/FFMpegCore.Test.csproj index 7c4b888..e9488ef 100644 --- a/FFMpegCore.Test/FFMpegCore.Test.csproj +++ b/FFMpegCore.Test/FFMpegCore.Test.csproj @@ -51,6 +51,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/FFMpegCore.Test/FFProbeTests.cs b/FFMpegCore.Test/FFProbeTests.cs index a507078..7789434 100644 --- a/FFMpegCore.Test/FFProbeTests.cs +++ b/FFMpegCore.Test/FFProbeTests.cs @@ -145,6 +145,13 @@ public void Probe_Rotation() Assert.AreEqual(90, info.PrimaryVideoStream.Rotation); } + [TestMethod] + public void Probe_Rotation_Negative_Value() + { + var info = FFProbe.Analyse(TestResources.Mp4VideoRotationNegative); + Assert.AreEqual(-90, info.PrimaryVideoStream.Rotation); + } + [TestMethod, Timeout(10000)] public async Task Probe_Async_Success() { diff --git a/FFMpegCore.Test/Resources/TestResources.cs b/FFMpegCore.Test/Resources/TestResources.cs index b958b80..beb7ead 100644 --- a/FFMpegCore.Test/Resources/TestResources.cs +++ b/FFMpegCore.Test/Resources/TestResources.cs @@ -4,6 +4,7 @@ public static class TestResources { public static readonly string Mp4Video = "./Resources/input_3sec.mp4"; public static readonly string Mp4VideoRotation = "./Resources/input_3sec_rotation_90deg.mp4"; + public static readonly string Mp4VideoRotationNegative = "./Resources/input_3sec_rotation_negative_90deg.mp4"; public static readonly string WebmVideo = "./Resources/input_3sec.webm"; public static readonly string Mp4WithoutVideo = "./Resources/input_audio_only_10sec.mp4"; public static readonly string Mp4WithoutAudio = "./Resources/input_video_only_3sec.mp4"; diff --git a/FFMpegCore.Test/Resources/input_3sec_rotation_negative_90deg.mp4 b/FFMpegCore.Test/Resources/input_3sec_rotation_negative_90deg.mp4 new file mode 100644 index 0000000..9a135f0 Binary files /dev/null and b/FFMpegCore.Test/Resources/input_3sec_rotation_negative_90deg.mp4 differ diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index 5071a48..ee6c5de 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -480,6 +480,21 @@ public void Video_Snapshot_PersistSnapshot() Assert.AreEqual("png", analysis.PrimaryVideoStream!.CodecName); } + [TestMethod, Timeout(BaseTimeoutMilliseconds)] + public void Video_Snapshot_Rotated_PersistSnapshot() + { + using var outputPath = new TemporaryFile("out.png"); + var input = FFProbe.Analyse(TestResources.Mp4VideoRotationNegative); + + FFMpeg.Snapshot(TestResources.Mp4VideoRotationNegative, outputPath); + + var analysis = FFProbe.Analyse(outputPath); + // height and width should be swapped + Assert.AreEqual(input.PrimaryVideoStream!.Height, analysis.PrimaryVideoStream!.Width); + Assert.AreEqual(input.PrimaryVideoStream.Width, analysis.PrimaryVideoStream!.Height); + Assert.AreEqual("png", analysis.PrimaryVideoStream!.CodecName); + } + [TestMethod, Timeout(BaseTimeoutMilliseconds)] public void Video_GifSnapshot_PersistSnapshot() { diff --git a/FFMpegCore/FFMpeg/SnapshotArgumentBuilder.cs b/FFMpegCore/FFMpeg/SnapshotArgumentBuilder.cs index 0d9b414..7d83183 100644 --- a/FFMpegCore/FFMpeg/SnapshotArgumentBuilder.cs +++ b/FFMpegCore/FFMpeg/SnapshotArgumentBuilder.cs @@ -64,7 +64,7 @@ public static (FFMpegArguments, Action outputOptions) Bui } var currentSize = new Size(source.PrimaryVideoStream.Width, source.PrimaryVideoStream.Height); - if (source.PrimaryVideoStream.Rotation == 90 || source.PrimaryVideoStream.Rotation == 180) + if (IsRotated(source.PrimaryVideoStream.Rotation)) { currentSize = new Size(source.PrimaryVideoStream.Height, source.PrimaryVideoStream.Width); } @@ -88,4 +88,10 @@ public static (FFMpegArguments, Action outputOptions) Bui return null; } + + private static bool IsRotated(int rotation) + { + var absRotation = Math.Abs(rotation); + return absRotation == 90 || absRotation == 180; + } }