mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-01-18 12:36:44 +00:00
Add unit tests
This commit is contained in:
parent
a90918eac6
commit
c218b3592b
2 changed files with 95 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
||||||
using FFMpegCore.Arguments;
|
using System.Drawing;
|
||||||
|
using FFMpegCore.Arguments;
|
||||||
using FFMpegCore.Enums;
|
using FFMpegCore.Enums;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
|
@ -537,5 +538,38 @@ public void Builder_BuildString_PadFilter_Alt()
|
||||||
"-i \"input.mp4\" -vf \"pad=aspect=4/3:x=(ow-iw)/2:y=(oh-ih)/2:color=violet:eval=frame\" \"output.mp4\"",
|
"-i \"input.mp4\" -vf \"pad=aspect=4/3:x=(ow-iw)/2:y=(oh-ih)/2:color=violet:eval=frame\" \"output.mp4\"",
|
||||||
str);
|
str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Builder_BuildString_GifPallet()
|
||||||
|
{
|
||||||
|
var streamIndex = 0;
|
||||||
|
var size = new Size(640, 480);
|
||||||
|
|
||||||
|
var str = FFMpegArguments
|
||||||
|
.FromFileInput("input.mp4")
|
||||||
|
.OutputToFile("output.gif", false, opt => opt
|
||||||
|
.WithGifPalettArgument(streamIndex, size))
|
||||||
|
.Arguments;
|
||||||
|
|
||||||
|
Assert.AreEqual($"""
|
||||||
|
-i "input.mp4" -filter_complex "[0:v] fps=12,scale=w={size.Width}:h={size.Height},split [a][b];[a] palettegen=max_colors=32 [p];[b][p] paletteuse=dither=bayer" "output.gif"
|
||||||
|
""", str);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Builder_BuildString_GifPallet_NullSize_FpsSupplied()
|
||||||
|
{
|
||||||
|
var streamIndex = 1;
|
||||||
|
|
||||||
|
var str = FFMpegArguments
|
||||||
|
.FromFileInput("input.mp4")
|
||||||
|
.OutputToFile("output.gif", false, opt => opt
|
||||||
|
.WithGifPalettArgument(streamIndex, null, 10))
|
||||||
|
.Arguments;
|
||||||
|
|
||||||
|
Assert.AreEqual($"""
|
||||||
|
-i "input.mp4" -filter_complex "[{streamIndex}:v] fps=10,split [a][b];[a] palettegen=max_colors=32 [p];[b][p] paletteuse=dither=bayer" "output.gif"
|
||||||
|
""", str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using FFMpegCore.Arguments;
|
using FFMpegCore.Arguments;
|
||||||
|
@ -479,6 +480,64 @@ public void Video_Snapshot_PersistSnapshot()
|
||||||
Assert.AreEqual("png", analysis.PrimaryVideoStream!.CodecName);
|
Assert.AreEqual("png", analysis.PrimaryVideoStream!.CodecName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod, Timeout(BaseTimeoutMilliseconds)]
|
||||||
|
public void Video_GifSnapshot_PersistSnapshot()
|
||||||
|
{
|
||||||
|
using var outputPath = new TemporaryFile("out.gif");
|
||||||
|
var input = FFProbe.Analyse(TestResources.Mp4Video);
|
||||||
|
|
||||||
|
FFMpeg.GifSnapshot(TestResources.Mp4Video, outputPath, captureTime: TimeSpan.FromSeconds(0));
|
||||||
|
|
||||||
|
var analysis = FFProbe.Analyse(outputPath);
|
||||||
|
Assert.AreNotEqual(input.PrimaryVideoStream!.Width, analysis.PrimaryVideoStream!.Width);
|
||||||
|
Assert.AreNotEqual(input.PrimaryVideoStream.Height, analysis.PrimaryVideoStream!.Height);
|
||||||
|
Assert.AreEqual("gif", analysis.PrimaryVideoStream!.CodecName);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod, Timeout(BaseTimeoutMilliseconds)]
|
||||||
|
public void Video_GifSnapshot_PersistSnapshot_SizeSupplied()
|
||||||
|
{
|
||||||
|
using var outputPath = new TemporaryFile("out.gif");
|
||||||
|
var input = FFProbe.Analyse(TestResources.Mp4Video);
|
||||||
|
var desiredGifSize = new Size(320, 240);
|
||||||
|
|
||||||
|
FFMpeg.GifSnapshot(TestResources.Mp4Video, outputPath, desiredGifSize, captureTime: TimeSpan.FromSeconds(0));
|
||||||
|
|
||||||
|
var analysis = FFProbe.Analyse(outputPath);
|
||||||
|
Assert.AreNotEqual(input.PrimaryVideoStream!.Width, desiredGifSize.Width);
|
||||||
|
Assert.AreNotEqual(input.PrimaryVideoStream.Height, desiredGifSize.Height);
|
||||||
|
Assert.AreEqual("gif", analysis.PrimaryVideoStream!.CodecName);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod, Timeout(BaseTimeoutMilliseconds)]
|
||||||
|
public async Task Video_GifSnapshot_PersistSnapshotAsync()
|
||||||
|
{
|
||||||
|
using var outputPath = new TemporaryFile("out.gif");
|
||||||
|
var input = FFProbe.Analyse(TestResources.Mp4Video);
|
||||||
|
|
||||||
|
await FFMpeg.GifSnapshotAsync(TestResources.Mp4Video, outputPath, captureTime: TimeSpan.FromSeconds(0));
|
||||||
|
|
||||||
|
var analysis = FFProbe.Analyse(outputPath);
|
||||||
|
Assert.AreNotEqual(input.PrimaryVideoStream!.Width, analysis.PrimaryVideoStream!.Width);
|
||||||
|
Assert.AreNotEqual(input.PrimaryVideoStream.Height, analysis.PrimaryVideoStream!.Height);
|
||||||
|
Assert.AreEqual("gif", analysis.PrimaryVideoStream!.CodecName);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod, Timeout(BaseTimeoutMilliseconds)]
|
||||||
|
public async Task Video_GifSnapshot_PersistSnapshotAsync_SizeSupplied()
|
||||||
|
{
|
||||||
|
using var outputPath = new TemporaryFile("out.gif");
|
||||||
|
var input = FFProbe.Analyse(TestResources.Mp4Video);
|
||||||
|
var desiredGifSize = new Size(320, 240);
|
||||||
|
|
||||||
|
await FFMpeg.GifSnapshotAsync(TestResources.Mp4Video, outputPath, desiredGifSize, captureTime: TimeSpan.FromSeconds(0));
|
||||||
|
|
||||||
|
var analysis = FFProbe.Analyse(outputPath);
|
||||||
|
Assert.AreNotEqual(input.PrimaryVideoStream!.Width, desiredGifSize.Width);
|
||||||
|
Assert.AreNotEqual(input.PrimaryVideoStream.Height, desiredGifSize.Height);
|
||||||
|
Assert.AreEqual("gif", analysis.PrimaryVideoStream!.CodecName);
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod, Timeout(BaseTimeoutMilliseconds)]
|
[TestMethod, Timeout(BaseTimeoutMilliseconds)]
|
||||||
public void Video_Join()
|
public void Video_Join()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue