mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-14 02:04:14 +01:00
Cleanup tests
This commit is contained in:
parent
a12c322de9
commit
e0819c89bf
1 changed files with 61 additions and 142 deletions
|
@ -12,111 +12,56 @@
|
||||||
using FFMpegCore.Arguments;
|
using FFMpegCore.Arguments;
|
||||||
using FFMpegCore.Exceptions;
|
using FFMpegCore.Exceptions;
|
||||||
using FFMpegCore.Pipes;
|
using FFMpegCore.Pipes;
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
namespace FFMpegCore.Test
|
namespace FFMpegCore.Test
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class VideoTest
|
public class VideoTest
|
||||||
{
|
{
|
||||||
public bool Convert(ContainerFormat type, bool multithreaded = false, VideoSize size = VideoSize.Original)
|
[TestMethod, Timeout(10000)]
|
||||||
|
public void Video_ToOGV()
|
||||||
{
|
{
|
||||||
using var outputFile = new TemporaryFile($"out{type.Extension}");
|
using var outputFile = new TemporaryFile($"out{VideoType.Ogv.Extension}");
|
||||||
|
|
||||||
var input = FFProbe.Analyse(TestResources.Mp4Video);
|
var success = FFMpegArguments
|
||||||
FFMpeg.Convert(TestResources.Mp4Video, outputFile, type, size: size, multithreaded: multithreaded);
|
.FromFileInput(TestResources.WebmVideo)
|
||||||
var outputVideo = FFProbe.Analyse(outputFile);
|
.OutputToFile(outputFile, false)
|
||||||
|
.ProcessSynchronously();
|
||||||
Assert.IsTrue(File.Exists(outputFile));
|
Assert.IsTrue(success);
|
||||||
Assert.AreEqual(outputVideo.Duration.TotalSeconds, input.Duration.TotalSeconds, 0.1);
|
|
||||||
if (size == VideoSize.Original)
|
|
||||||
{
|
|
||||||
Assert.AreEqual(outputVideo.PrimaryVideoStream.Width, input.PrimaryVideoStream.Width);
|
|
||||||
Assert.AreEqual(outputVideo.PrimaryVideoStream.Height, input.PrimaryVideoStream.Height);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Assert.AreNotEqual(outputVideo.PrimaryVideoStream.Width, input.PrimaryVideoStream.Width);
|
|
||||||
Assert.AreNotEqual(outputVideo.PrimaryVideoStream.Height, input.PrimaryVideoStream.Height);
|
|
||||||
Assert.AreEqual(outputVideo.PrimaryVideoStream.Height, (int)size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return File.Exists(outputFile) &&
|
|
||||||
outputVideo.Duration == input.Duration &&
|
|
||||||
(
|
|
||||||
(
|
|
||||||
size == VideoSize.Original &&
|
|
||||||
outputVideo.PrimaryVideoStream.Width == input.PrimaryVideoStream.Width &&
|
|
||||||
outputVideo.PrimaryVideoStream.Height == input.PrimaryVideoStream.Height
|
|
||||||
) ||
|
|
||||||
(
|
|
||||||
size != VideoSize.Original &&
|
|
||||||
outputVideo.PrimaryVideoStream.Width != input.PrimaryVideoStream.Width &&
|
|
||||||
outputVideo.PrimaryVideoStream.Height != input.PrimaryVideoStream.Height &&
|
|
||||||
outputVideo.PrimaryVideoStream.Height == (int)size
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Convert(ContainerFormat type, Action<IMediaAnalysis> validationMethod, params IArgument[] arguments)
|
|
||||||
{
|
|
||||||
using var outputFile = new TemporaryFile($"out{type.Extension}");
|
|
||||||
|
|
||||||
var input = FFProbe.Analyse(TestResources.Mp4Video);
|
|
||||||
|
|
||||||
var processor = FFMpegArguments
|
|
||||||
.FromFileInput(TestResources.Mp4Video)
|
|
||||||
.OutputToFile(outputFile, false, opt =>
|
|
||||||
{
|
|
||||||
foreach (var arg in arguments)
|
|
||||||
opt.WithArgument(arg);
|
|
||||||
});
|
|
||||||
|
|
||||||
var scaling = arguments.OfType<ScaleArgument>().FirstOrDefault();
|
|
||||||
processor.ProcessSynchronously();
|
|
||||||
|
|
||||||
var outputVideo = FFProbe.Analyse(outputFile);
|
|
||||||
|
|
||||||
Assert.IsTrue(File.Exists(outputFile));
|
|
||||||
Assert.AreEqual(outputVideo.Duration.TotalSeconds, input.Duration.TotalSeconds, 0.1);
|
|
||||||
validationMethod?.Invoke(outputVideo);
|
|
||||||
if (scaling?.Size == null)
|
|
||||||
{
|
|
||||||
Assert.AreEqual(outputVideo.PrimaryVideoStream.Width, input.PrimaryVideoStream.Width);
|
|
||||||
Assert.AreEqual(outputVideo.PrimaryVideoStream.Height, input.PrimaryVideoStream.Height);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (scaling.Size.Value.Width != -1)
|
|
||||||
{
|
|
||||||
Assert.AreEqual(outputVideo.PrimaryVideoStream.Width, scaling.Size.Value.Width);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scaling.Size.Value.Height != -1)
|
|
||||||
{
|
|
||||||
Assert.AreEqual(outputVideo.PrimaryVideoStream.Height, scaling.Size.Value.Height);
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert.AreNotEqual(outputVideo.PrimaryVideoStream.Width, input.PrimaryVideoStream.Width);
|
|
||||||
Assert.AreNotEqual(outputVideo.PrimaryVideoStream.Height, input.PrimaryVideoStream.Height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Convert(ContainerFormat type, params IArgument[] inputArguments)
|
|
||||||
{
|
|
||||||
Convert(type, null, inputArguments);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod, Timeout(10000)]
|
[TestMethod, Timeout(10000)]
|
||||||
public void Video_ToMP4()
|
public void Video_ToMP4()
|
||||||
{
|
{
|
||||||
Convert(VideoType.Mp4);
|
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
|
||||||
|
|
||||||
|
var success = FFMpegArguments
|
||||||
|
.FromFileInput(TestResources.WebmVideo)
|
||||||
|
.OutputToFile(outputFile, false)
|
||||||
|
.ProcessSynchronously();
|
||||||
|
Assert.IsTrue(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod, Timeout(10000)]
|
[TestMethod, Timeout(10000)]
|
||||||
public void Video_ToMP4_YUV444p()
|
public void Video_ToMP4_YUV444p()
|
||||||
{
|
{
|
||||||
using var outputFile = new TemporaryFile($"out{VideoType.WebM.Extension}");
|
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
|
||||||
|
|
||||||
|
var success = FFMpegArguments
|
||||||
|
.FromFileInput(TestResources.WebmVideo)
|
||||||
|
.OutputToFile(outputFile, false, opt => opt
|
||||||
|
.WithVideoCodec(VideoCodec.LibX264)
|
||||||
|
.ForcePixelFormat("yuv444p"))
|
||||||
|
.ProcessSynchronously();
|
||||||
|
Assert.IsTrue(success);
|
||||||
|
var analysis = FFProbe.Analyse(outputFile);
|
||||||
|
Assert.IsTrue(analysis.VideoStreams.First().PixelFormat == "yuv444p");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod, Timeout(10000)]
|
||||||
|
public void Video_ToMP4_Args()
|
||||||
|
{
|
||||||
|
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
|
||||||
|
|
||||||
var success = FFMpegArguments
|
var success = FFMpegArguments
|
||||||
.FromFileInput(TestResources.WebmVideo)
|
.FromFileInput(TestResources.WebmVideo)
|
||||||
|
@ -124,16 +69,6 @@ public void Video_ToMP4_YUV444p()
|
||||||
.WithVideoCodec(VideoCodec.LibX264))
|
.WithVideoCodec(VideoCodec.LibX264))
|
||||||
.ProcessSynchronously();
|
.ProcessSynchronously();
|
||||||
Assert.IsTrue(success);
|
Assert.IsTrue(success);
|
||||||
var analysis = FFProbe.Analyse(outputFile);
|
|
||||||
|
|
||||||
Convert(VideoType.Mp4, (a) => Assert.IsTrue(a.VideoStreams.First().PixelFormat == "yuv444p"),
|
|
||||||
new ForcePixelFormat("yuv444p"));
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod, Timeout(10000)]
|
|
||||||
public void Video_ToMP4_Args()
|
|
||||||
{
|
|
||||||
Convert(VideoType.Mp4, new VideoCodecArgument(VideoCodec.LibX264));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataTestMethod, Timeout(10000)]
|
[DataTestMethod, Timeout(10000)]
|
||||||
|
@ -164,8 +99,6 @@ public void Video_ToMP4_Args_StreamPipe()
|
||||||
.WithVideoCodec(VideoCodec.LibX264))
|
.WithVideoCodec(VideoCodec.LibX264))
|
||||||
.ProcessSynchronously();
|
.ProcessSynchronously();
|
||||||
Assert.IsTrue(success);
|
Assert.IsTrue(success);
|
||||||
|
|
||||||
var outputVideo = FFProbe.Analyse(output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod, Timeout(10000)]
|
[TestMethod, Timeout(10000)]
|
||||||
|
@ -204,13 +137,11 @@ public void Video_ToMP4_Args_StreamOutputPipe_Failure()
|
||||||
Assert.ThrowsException<FFMpegProcessException>(() =>
|
Assert.ThrowsException<FFMpegProcessException>(() =>
|
||||||
{
|
{
|
||||||
using var ms = new MemoryStream();
|
using var ms = new MemoryStream();
|
||||||
var processor = FFMpegArguments
|
FFMpegArguments
|
||||||
.FromFileInput(TestResources.Mp4Video)
|
.FromFileInput(TestResources.Mp4Video)
|
||||||
.OutputToPipe(new StreamPipeSink(ms), opt => opt
|
.OutputToPipe(new StreamPipeSink(ms), opt => opt
|
||||||
.ForceFormat("mkv"))
|
.ForceFormat("mkv"))
|
||||||
.ProcessSynchronously();
|
.ProcessSynchronously();
|
||||||
ms.Position = 0;
|
|
||||||
var outputVideo = FFProbe.Analyse(ms);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,16 +196,28 @@ public void TranscodeToMemoryStream_Success()
|
||||||
[TestMethod, Timeout(10000)]
|
[TestMethod, Timeout(10000)]
|
||||||
public void Video_ToTS()
|
public void Video_ToTS()
|
||||||
{
|
{
|
||||||
Convert(VideoType.Ts);
|
using var outputFile = new TemporaryFile($"out{VideoType.MpegTs.Extension}");
|
||||||
|
|
||||||
|
var success = FFMpegArguments
|
||||||
|
.FromFileInput(TestResources.Mp4Video)
|
||||||
|
.OutputToFile(outputFile, false)
|
||||||
|
.ProcessSynchronously();
|
||||||
|
Assert.IsTrue(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod, Timeout(10000)]
|
[TestMethod, Timeout(10000)]
|
||||||
public void Video_ToTS_Args()
|
public void Video_ToTS_Args()
|
||||||
{
|
{
|
||||||
Convert(VideoType.Ts,
|
using var outputFile = new TemporaryFile($"out{VideoType.MpegTs.Extension}");
|
||||||
new CopyArgument(),
|
|
||||||
new BitStreamFilterArgument(Channel.Video, Filter.H264_Mp4ToAnnexB),
|
var success = FFMpegArguments
|
||||||
new ForceFormatArgument(VideoType.MpegTs));
|
.FromFileInput(TestResources.Mp4Video)
|
||||||
|
.OutputToFile(outputFile, false, opt => opt
|
||||||
|
.CopyChannel()
|
||||||
|
.WithBitStreamFilter(Channel.Video, Filter.H264_Mp4ToAnnexB)
|
||||||
|
.ForceFormat(VideoType.MpegTs))
|
||||||
|
.ProcessSynchronously();
|
||||||
|
Assert.IsTrue(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataTestMethod, Timeout(10000)]
|
[DataTestMethod, Timeout(10000)]
|
||||||
|
@ -327,7 +270,7 @@ public void RawVideoPipeSource_Ogv_Scale(System.Drawing.Imaging.PixelFormat pixe
|
||||||
.ProcessSynchronously();
|
.ProcessSynchronously();
|
||||||
|
|
||||||
var analysis = FFProbe.Analyse(outputFile);
|
var analysis = FFProbe.Analyse(outputFile);
|
||||||
Assert.AreEqual((int)VideoSize.Ed, analysis!.PrimaryVideoStream.Width);
|
Assert.AreEqual((int)VideoSize.Ed, analysis.PrimaryVideoStream!.Width);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod, Timeout(10000)]
|
[TestMethod, Timeout(10000)]
|
||||||
|
@ -361,37 +304,13 @@ public void Video_ToMP4_Resize_Args_Pipe(System.Drawing.Imaging.PixelFormat pixe
|
||||||
Assert.IsTrue(success);
|
Assert.IsTrue(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod, Timeout(10000)]
|
|
||||||
public void Video_ToOGV()
|
|
||||||
{
|
|
||||||
Convert(VideoType.Ogv);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod, Timeout(10000)]
|
|
||||||
public void Video_ToMP4_MultiThread()
|
|
||||||
{
|
|
||||||
Convert(VideoType.Mp4, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod, Timeout(10000)]
|
|
||||||
public void Video_ToTS_MultiThread()
|
|
||||||
{
|
|
||||||
Convert(VideoType.Ts, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod, Timeout(10000)]
|
|
||||||
public void Video_ToOGV_MultiThread()
|
|
||||||
{
|
|
||||||
Convert(VideoType.Ogv, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod, Timeout(10000)]
|
[TestMethod, Timeout(10000)]
|
||||||
public void Video_Snapshot_InMemory()
|
public void Video_Snapshot_InMemory()
|
||||||
{
|
{
|
||||||
var input = FFProbe.Analyse(TestResources.Mp4Video);
|
var input = FFProbe.Analyse(TestResources.Mp4Video);
|
||||||
using var bitmap = FFMpeg.Snapshot(TestResources.Mp4Video);
|
using var bitmap = FFMpeg.Snapshot(TestResources.Mp4Video);
|
||||||
|
|
||||||
Assert.AreEqual(input.PrimaryVideoStream.Width, bitmap.Width);
|
Assert.AreEqual(input.PrimaryVideoStream!.Width, bitmap.Width);
|
||||||
Assert.AreEqual(input.PrimaryVideoStream.Height, bitmap.Height);
|
Assert.AreEqual(input.PrimaryVideoStream.Height, bitmap.Height);
|
||||||
Assert.AreEqual(bitmap.RawFormat, ImageFormat.Png);
|
Assert.AreEqual(bitmap.RawFormat, ImageFormat.Png);
|
||||||
}
|
}
|
||||||
|
@ -405,7 +324,7 @@ public void Video_Snapshot_PersistSnapshot()
|
||||||
FFMpeg.Snapshot(TestResources.Mp4Video, outputPath);
|
FFMpeg.Snapshot(TestResources.Mp4Video, outputPath);
|
||||||
|
|
||||||
using var bitmap = Image.FromFile(outputPath);
|
using var bitmap = Image.FromFile(outputPath);
|
||||||
Assert.AreEqual(input.PrimaryVideoStream.Width, bitmap.Width);
|
Assert.AreEqual(input.PrimaryVideoStream!.Width, bitmap.Width);
|
||||||
Assert.AreEqual(input.PrimaryVideoStream.Height, bitmap.Height);
|
Assert.AreEqual(input.PrimaryVideoStream.Height, bitmap.Height);
|
||||||
Assert.AreEqual(bitmap.RawFormat, ImageFormat.Png);
|
Assert.AreEqual(bitmap.RawFormat, ImageFormat.Png);
|
||||||
}
|
}
|
||||||
|
@ -428,7 +347,7 @@ public void Video_Join()
|
||||||
Assert.AreEqual(expectedDuration.Hours, result.Duration.Hours);
|
Assert.AreEqual(expectedDuration.Hours, result.Duration.Hours);
|
||||||
Assert.AreEqual(expectedDuration.Minutes, result.Duration.Minutes);
|
Assert.AreEqual(expectedDuration.Minutes, result.Duration.Minutes);
|
||||||
Assert.AreEqual(expectedDuration.Seconds, result.Duration.Seconds);
|
Assert.AreEqual(expectedDuration.Seconds, result.Duration.Seconds);
|
||||||
Assert.AreEqual(input.PrimaryVideoStream.Height, result.PrimaryVideoStream.Height);
|
Assert.AreEqual(input.PrimaryVideoStream!.Height, result.PrimaryVideoStream!.Height);
|
||||||
Assert.AreEqual(input.PrimaryVideoStream.Width, result.PrimaryVideoStream.Width);
|
Assert.AreEqual(input.PrimaryVideoStream.Width, result.PrimaryVideoStream.Width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -452,7 +371,7 @@ public void Video_Join_Image_Sequence()
|
||||||
Assert.IsTrue(success);
|
Assert.IsTrue(success);
|
||||||
var result = FFProbe.Analyse(outputFile);
|
var result = FFProbe.Analyse(outputFile);
|
||||||
Assert.AreEqual(3, result.Duration.Seconds);
|
Assert.AreEqual(3, result.Duration.Seconds);
|
||||||
Assert.AreEqual(imageSet.First().Width, result.PrimaryVideoStream.Width);
|
Assert.AreEqual(imageSet.First().Width, result.PrimaryVideoStream!.Width);
|
||||||
Assert.AreEqual(imageSet.First().Height, result.PrimaryVideoStream.Height);
|
Assert.AreEqual(imageSet.First().Height, result.PrimaryVideoStream.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,7 +380,7 @@ public void Video_With_Only_Audio_Should_Extract_Metadata()
|
||||||
{
|
{
|
||||||
var video = FFProbe.Analyse(TestResources.Mp4WithoutVideo);
|
var video = FFProbe.Analyse(TestResources.Mp4WithoutVideo);
|
||||||
Assert.AreEqual(null, video.PrimaryVideoStream);
|
Assert.AreEqual(null, video.PrimaryVideoStream);
|
||||||
Assert.AreEqual("aac", video.PrimaryAudioStream.CodecName);
|
Assert.AreEqual("aac", video.PrimaryAudioStream!.CodecName);
|
||||||
Assert.AreEqual(10, video.Duration.TotalSeconds, 0.5);
|
Assert.AreEqual(10, video.Duration.TotalSeconds, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -547,7 +466,7 @@ public void Video_TranscodeInMemory()
|
||||||
|
|
||||||
resStream.Position = 0;
|
resStream.Position = 0;
|
||||||
var vi = FFProbe.Analyse(resStream);
|
var vi = FFProbe.Analyse(resStream);
|
||||||
Assert.AreEqual(vi.PrimaryVideoStream.Width, 128);
|
Assert.AreEqual(vi.PrimaryVideoStream!.Width, 128);
|
||||||
Assert.AreEqual(vi.PrimaryVideoStream.Height, 128);
|
Assert.AreEqual(vi.PrimaryVideoStream.Height, 128);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -596,14 +515,14 @@ public async Task Video_Cancel_Async_With_Timeout()
|
||||||
|
|
||||||
var result = await task;
|
var result = await task;
|
||||||
|
|
||||||
var outputInfo = FFProbe.Analyse(outputFile);
|
var outputInfo = await FFProbe.AnalyseAsync(outputFile);
|
||||||
|
|
||||||
Assert.IsTrue(result);
|
Assert.IsTrue(result);
|
||||||
Assert.IsNotNull(outputInfo);
|
Assert.IsNotNull(outputInfo);
|
||||||
Assert.AreEqual(320, outputInfo.PrimaryVideoStream.Width);
|
Assert.AreEqual(320, outputInfo.PrimaryVideoStream!.Width);
|
||||||
Assert.AreEqual(240, outputInfo.PrimaryVideoStream.Height);
|
Assert.AreEqual(240, outputInfo.PrimaryVideoStream.Height);
|
||||||
Assert.AreEqual("h264", outputInfo.PrimaryVideoStream.CodecName);
|
Assert.AreEqual("h264", outputInfo.PrimaryVideoStream.CodecName);
|
||||||
Assert.AreEqual("aac", outputInfo.PrimaryAudioStream.CodecName);
|
Assert.AreEqual("aac", outputInfo.PrimaryAudioStream!.CodecName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue