From f0f60c8bd86a0edbe51aebab261e805e72610b23 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Tue, 28 Oct 2025 12:19:21 +0100 Subject: [PATCH 1/2] Add more missing tests --- FFMpegCore.Test/ArgumentBuilderTest.cs | 8 +++ FFMpegCore.Test/VideoTest.cs | 81 ++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/FFMpegCore.Test/ArgumentBuilderTest.cs b/FFMpegCore.Test/ArgumentBuilderTest.cs index 53999c3..64a116b 100644 --- a/FFMpegCore.Test/ArgumentBuilderTest.cs +++ b/FFMpegCore.Test/ArgumentBuilderTest.cs @@ -93,6 +93,14 @@ public class ArgumentBuilderTest Assert.AreEqual("-i \"concat:1.mp4|2.mp4|3.mp4|4.mp4\" \"output.mp4\"", str); } + [TestMethod] + public void Builder_BuildString_DemuxConcat() + { + var str = FFMpegArguments.FromDemuxConcatInput(_concatFiles).OutputToFile("output.mp4", false).Arguments; + Assert.Contains("-f concat -safe 0 -i", str); + Assert.Contains("\"output.mp4\"", str); + } + [TestMethod] public void Builder_BuildString_Copy_Audio() { diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index b9e586c..8dca0fa 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -589,6 +589,19 @@ public class VideoTest Assert.AreEqual(bitmap.RawFormat, ImageFormat.Png); } + [SupportedOSPlatform("windows")] + [OsSpecificTestMethod(OsPlatforms.Windows)] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] + public async Task Video_SnapshotAsync_InMemory_SystemDrawingCommon() + { + using var bitmap = await FFMpegImage.SnapshotAsync(TestResources.Mp4Video, cancellationToken: TestContext.CancellationToken); + + var input = await FFProbe.AnalyseAsync(TestResources.Mp4Video, cancellationToken: TestContext.CancellationToken); + Assert.AreEqual(input.PrimaryVideoStream!.Width, bitmap.Width); + Assert.AreEqual(input.PrimaryVideoStream.Height, bitmap.Height); + Assert.AreEqual(bitmap.RawFormat, ImageFormat.Png); + } + [TestMethod] [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Video_Snapshot_InMemory_SkiaSharp() @@ -602,6 +615,19 @@ public class VideoTest // e.g. Bgra8888 on Windows and Rgba8888 on macOS. } + [TestMethod] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] + public async Task Video_SnapshotAsync_InMemory_SkiaSharp() + { + using var bitmap = await Extensions.SkiaSharp.FFMpegImage.SnapshotAsync(TestResources.Mp4Video, cancellationToken: TestContext.CancellationToken); + + var input = await FFProbe.AnalyseAsync(TestResources.Mp4Video, cancellationToken: TestContext.CancellationToken); + Assert.AreEqual(input.PrimaryVideoStream!.Width, bitmap.Width); + Assert.AreEqual(input.PrimaryVideoStream.Height, bitmap.Height); + // Note: The resulting ColorType is dependent on the execution environment and therefore not assessed, + // e.g. Bgra8888 on Windows and Rgba8888 on macOS. + } + [TestMethod] [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Video_Snapshot_Png_PersistSnapshot() @@ -617,6 +643,21 @@ public class VideoTest Assert.AreEqual("png", analysis.PrimaryVideoStream!.CodecName); } + [TestMethod] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] + public async Task Video_SnapshotAsync_Png_PersistSnapshot() + { + using var outputPath = new TemporaryFile("out.png"); + var input = await FFProbe.AnalyseAsync(TestResources.Mp4Video, cancellationToken: TestContext.CancellationToken); + + await FFMpeg.SnapshotAsync(TestResources.Mp4Video, outputPath, cancellationToken: TestContext.CancellationToken); + + var analysis = FFProbe.Analyse(outputPath); + Assert.AreEqual(input.PrimaryVideoStream!.Width, analysis.PrimaryVideoStream!.Width); + Assert.AreEqual(input.PrimaryVideoStream.Height, analysis.PrimaryVideoStream!.Height); + Assert.AreEqual("png", analysis.PrimaryVideoStream!.CodecName); + } + [TestMethod] [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Video_Snapshot_Jpg_PersistSnapshot() @@ -780,6 +821,46 @@ public class VideoTest Assert.AreEqual(input.PrimaryVideoStream!.Height, result.PrimaryVideoStream!.Height); Assert.AreEqual(input.PrimaryVideoStream.Width, result.PrimaryVideoStream.Width); } + + [TestMethod] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] + public void Video_Convert_Webm() + { + using var outputPath = new TemporaryFile("out.webm"); + + var success = FFMpeg.Convert(TestResources.Mp4Video, outputPath, VideoType.WebM); + Assert.IsTrue(success); + Assert.IsTrue(File.Exists(outputPath)); + + var input = FFProbe.Analyse(TestResources.Mp4Video); + var result = FFProbe.Analyse(outputPath); + Assert.AreEqual(input.Duration.Days, result.Duration.Days); + Assert.AreEqual(input.Duration.Hours, result.Duration.Hours); + Assert.AreEqual(input.Duration.Minutes, result.Duration.Minutes); + Assert.AreEqual(input.Duration.Seconds, result.Duration.Seconds); + Assert.AreEqual(input.PrimaryVideoStream!.Height, result.PrimaryVideoStream!.Height); + Assert.AreEqual(input.PrimaryVideoStream.Width, result.PrimaryVideoStream.Width); + } + + [TestMethod] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] + public void Video_Convert_Ogv() + { + using var outputPath = new TemporaryFile("out.ogv"); + + var success = FFMpeg.Convert(TestResources.Mp4Video, outputPath, VideoType.Ogv); + Assert.IsTrue(success); + Assert.IsTrue(File.Exists(outputPath)); + + var input = FFProbe.Analyse(TestResources.Mp4Video); + var result = FFProbe.Analyse(outputPath); + Assert.AreEqual(input.Duration.Days, result.Duration.Days); + Assert.AreEqual(input.Duration.Hours, result.Duration.Hours); + Assert.AreEqual(input.Duration.Minutes, result.Duration.Minutes); + Assert.AreEqual(input.Duration.Seconds, result.Duration.Seconds); + Assert.AreEqual(input.PrimaryVideoStream!.Height, result.PrimaryVideoStream!.Height); + Assert.AreEqual(input.PrimaryVideoStream.Width, result.PrimaryVideoStream.Width); + } [TestMethod] [Timeout(2 * BaseTimeoutMilliseconds, CooperativeCancellation = true)] From 5356536f372b10c06421d174487579b6a610085b Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Tue, 28 Oct 2025 12:21:09 +0100 Subject: [PATCH 2/2] Fix linting --- FFMpegCore.Test/VideoTest.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index 8dca0fa..8e8fc59 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -821,17 +821,17 @@ public class VideoTest Assert.AreEqual(input.PrimaryVideoStream!.Height, result.PrimaryVideoStream!.Height); Assert.AreEqual(input.PrimaryVideoStream.Width, result.PrimaryVideoStream.Width); } - + [TestMethod] [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Video_Convert_Webm() { using var outputPath = new TemporaryFile("out.webm"); - + var success = FFMpeg.Convert(TestResources.Mp4Video, outputPath, VideoType.WebM); Assert.IsTrue(success); Assert.IsTrue(File.Exists(outputPath)); - + var input = FFProbe.Analyse(TestResources.Mp4Video); var result = FFProbe.Analyse(outputPath); Assert.AreEqual(input.Duration.Days, result.Duration.Days); @@ -841,17 +841,17 @@ public class VideoTest Assert.AreEqual(input.PrimaryVideoStream!.Height, result.PrimaryVideoStream!.Height); Assert.AreEqual(input.PrimaryVideoStream.Width, result.PrimaryVideoStream.Width); } - + [TestMethod] [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Video_Convert_Ogv() { using var outputPath = new TemporaryFile("out.ogv"); - + var success = FFMpeg.Convert(TestResources.Mp4Video, outputPath, VideoType.Ogv); Assert.IsTrue(success); Assert.IsTrue(File.Exists(outputPath)); - + var input = FFProbe.Analyse(TestResources.Mp4Video); var result = FFProbe.Analyse(outputPath); Assert.AreEqual(input.Duration.Days, result.Duration.Days);