From 5991cc99f007822f02266be6840b55631642e14e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=91=D0=B0=D0=B3?= =?UTF-8?q?=D1=80=D1=8F=D0=BD=D1=86=D0=B5=D0=B2?= Date: Tue, 28 Apr 2020 22:40:33 +0300 Subject: [PATCH] Added Unit tests for input and output pipes --- FFMpegCore.Test/VideoTest.cs | 124 ++++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 2 deletions(-) diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index 63c40d0..25ff2f6 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -1,6 +1,7 @@ using FFMpegCore.Enums; using FFMpegCore.FFMPEG.Argument; using FFMpegCore.FFMPEG.Enums; +using FFMpegCore.FFMPEG.Exceptions; using FFMpegCore.FFMPEG.Pipes; using FFMpegCore.Test.Resources; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -62,7 +63,7 @@ public bool Convert(VideoType type, bool multithreaded = false, VideoSize size = File.Delete(output.FullName); } } - + private void ConvertFromStreamPipe(VideoType type, ArgumentContainer container) { var output = Input.OutputLocation(type); @@ -118,6 +119,54 @@ private void ConvertFromStreamPipe(VideoType type, ArgumentContainer container) } } + private void ConvertToStreamPipe(VideoType type, ArgumentContainer container) + { + using (var ms = new MemoryStream()) + { + var input = VideoInfo.FromFileInfo(VideoLibrary.LocalVideo); + var arguments = new ArgumentContainer { new InputArgument(input) }; + + foreach (var arg in container) + { + arguments.Add(arg.Value); + } + + var streamPipeDataReader = new StreamPipeDataReader(ms); + streamPipeDataReader.BlockSize = streamPipeDataReader.BlockSize * 16; + arguments.Add(new OutputPipeArgument(streamPipeDataReader)); + + var scaling = container.Find(); + + Encoder.Convert(arguments); + + ms.Position = 0; + var outputVideo = VideoInfo.FromStream(ms); + + Assert.IsTrue(Math.Abs((outputVideo.Duration - input.Duration).TotalMilliseconds) < 1000.0 / input.FrameRate); + + if (scaling == null) + { + Assert.AreEqual(outputVideo.Width, input.Width); + Assert.AreEqual(outputVideo.Height, input.Height); + } + else + { + if (scaling.Value.Width != -1) + { + Assert.AreEqual(outputVideo.Width, scaling.Value.Width); + } + + if (scaling.Value.Height != -1) + { + Assert.AreEqual(outputVideo.Height, scaling.Value.Height); + } + + Assert.AreNotEqual(outputVideo.Width, input.Width); + Assert.AreNotEqual(outputVideo.Height, input.Height); + } + } + } + public void Convert(VideoType type, ArgumentContainer container) { var output = Input.OutputLocation(type); @@ -255,6 +304,78 @@ public void Video_ToMP4_Args_StreamPipe() ConvertFromStreamPipe(VideoType.Mp4, container); } + [TestMethod] + public void Video_ToMP4_Args_StreamOutputPipe_Async_Failure() + { + Assert.ThrowsException(() => + { + using (var ms = new MemoryStream()) + { + var pipeSource = new StreamPipeDataReader(ms); + var container = new ArgumentContainer + { + new InputArgument(VideoLibrary.LocalVideo), + new VideoCodecArgument(VideoCodec.LibX264), + new ForceFormatArgument("mkv"), + new OutputPipeArgument(pipeSource) + }; + + var input = VideoInfo.FromFileInfo(VideoLibrary.LocalVideoWebm); + Encoder.ConvertAsync(container).WaitForResult(); + } + }); + } + + [TestMethod] + public void Video_ToMP4_Args_StreamOutputPipe_Failure() + { + Assert.ThrowsException(() => + { + var container = new ArgumentContainer + { + new ForceFormatArgument("mkv") + }; + ConvertToStreamPipe(VideoType.Mp4, container); + }); + } + + + [TestMethod] + public void Video_ToMP4_Args_StreamOutputPipe_Async() + { + Assert.ThrowsException(() => + { + using (var ms = new MemoryStream()) + { + var pipeSource = new StreamPipeDataReader(ms); + var container = new ArgumentContainer + { + new InputArgument(VideoLibrary.LocalVideo), + new VideoCodecArgument(VideoCodec.LibX264), + new ForceFormatArgument("mp4"), + new OutputPipeArgument(pipeSource) + }; + + var input = VideoInfo.FromFileInfo(VideoLibrary.LocalVideoWebm); + Encoder.ConvertAsync(container).WaitForResult(); + } + }); + } + + [TestMethod] + public void Video_ToMP4_Args_StreamOutputPipe() + { + Assert.ThrowsException(() => + { + var container = new ArgumentContainer + { + new VideoCodecArgument(VideoCodec.LibX264), + new ForceFormatArgument("mp4") + }; + ConvertToStreamPipe(VideoType.Mp4, container); + }); + } + [TestMethod] public void Video_ToTS() { @@ -278,7 +399,6 @@ public void Video_ToTS_Args_Pipe() { var container = new ArgumentContainer { - new CopyArgument(), new ForceFormatArgument(VideoCodec.MpegTs) }; ConvertFromPipe(VideoType.Ts, container);