diff --git a/FFMpegCore.Test/FFMpegCore.Test.csproj b/FFMpegCore.Test/FFMpegCore.Test.csproj
index 22cc7dc..84b863f 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 2458c1b..6ebad0f 100644
--- a/FFMpegCore.Test/FFProbeTests.cs
+++ b/FFMpegCore.Test/FFProbeTests.cs
@@ -146,6 +146,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 280a051..97e7892 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 HdrVideo = "./Resources/input_hdr.mov";
public static readonly string Mp4WithoutVideo = "./Resources/input_audio_only_10sec.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..8da9c19 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 size = new Size(360, 0); // half the size of original video, keeping height 0 for keeping aspect ratio
+ FFMpeg.Snapshot(TestResources.Mp4VideoRotationNegative, outputPath, size);
+
+ var analysis = FFProbe.Analyse(outputPath);
+ Assert.AreEqual(size.Width, analysis.PrimaryVideoStream!.Width);
+ Assert.AreEqual(1280 / 2, analysis.PrimaryVideoStream!.Height);
+ Assert.AreEqual(0, analysis.PrimaryVideoStream!.Rotation);
+ 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;
+ }
}