From d8b2cbe3ca4d9c2be1d13365da35226e6ed33ea3 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: Thu, 30 Apr 2020 14:46:20 +0300 Subject: [PATCH 1/4] Added Fluent API methods for ArgumentContainer --- .../ArgumentContainerFluentExtensions.cs | 331 ++++++++++++++++++ 1 file changed, 331 insertions(+) create mode 100644 FFMpegCore/FFMPEG/Argument/ArgumentContainerFluentExtensions.cs diff --git a/FFMpegCore/FFMPEG/Argument/ArgumentContainerFluentExtensions.cs b/FFMpegCore/FFMPEG/Argument/ArgumentContainerFluentExtensions.cs new file mode 100644 index 0000000..4e8cc98 --- /dev/null +++ b/FFMpegCore/FFMPEG/Argument/ArgumentContainerFluentExtensions.cs @@ -0,0 +1,331 @@ +using FFMpegCore.FFMPEG.Enums; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; + +namespace FFMpegCore.FFMPEG.Argument.Fluent +{ + public static class ArgumentContainerFluentExtensions + { + public static ArgumentContainer AudioCodec(this ArgumentContainer container, AudioCodec codec) + { + container.Add(new AudioCodecArgument(codec)); + return container; + } + + public static ArgumentContainer AudioCodec(this ArgumentContainer container, AudioCodec codec, AudioQuality bitrate) + { + container.Add(new AudioCodecArgument(codec, bitrate)); + return container; + } + + public static ArgumentContainer AudioCodec(this ArgumentContainer container, AudioCodec codec, int bitrate) + { + container.Add(new AudioCodecArgument(codec, bitrate)); + return container; + } + + public static ArgumentContainer AudioSamplingRate(this ArgumentContainer container) + { + container.Add(new AudioSamplingRateArgument()); + return container; + } + + public static ArgumentContainer AudioSamplingRate(this ArgumentContainer container, int sampleRate) + { + container.Add(new AudioSamplingRateArgument(sampleRate)); + return container; + } + + public static ArgumentContainer BitStreamFilter(this ArgumentContainer container, Channel first, Filter second) + { + container.Add(new BitStreamFilterArgument(first, second)); + return container; + } + + public static ArgumentContainer Concat(this ArgumentContainer container, IEnumerable paths) + { + container.Add(new ConcatArgument(paths)); + return container; + } + + public static ArgumentContainer ConstantRateFactor(this ArgumentContainer container, int crf) + { + container.Add(new ConstantRateFactorArgument(crf)); + return container; + } + + public static ArgumentContainer Copy(this ArgumentContainer container) + { + container.Add(new CopyArgument()); + return container; + } + + public static ArgumentContainer Copy(this ArgumentContainer container, Channel value) + { + container.Add(new CopyArgument(value)); + return container; + } + + public static ArgumentContainer CpuSpeed(this ArgumentContainer container, int value) + { + container.Add(new CpuSpeedArgument(value)); + return container; + } + + public static ArgumentContainer DisableChannel(this ArgumentContainer container, Channel channel) + { + container.Add(new DisableChannelArgument(channel)); + return container; + } + + public static ArgumentContainer DrawText(this ArgumentContainer container, string text, string fontPath, params (string, string)[] optionalArguments) + { + container.Add(new DrawTextArgument(text, fontPath, optionalArguments)); + return container; + } + + public static ArgumentContainer Duration(this ArgumentContainer container, TimeSpan? duration) + { + container.Add(new DurationArgument(duration)); + return container; + } + + public static ArgumentContainer FastStart(this ArgumentContainer container) + { + container.Add(new FaststartArgument()); + return container; + } + + public static ArgumentContainer ForceFormat(this ArgumentContainer container, VideoCodec codec) + { + container.Add(new ForceFormatArgument(codec)); + return container; + } + + public static ArgumentContainer FrameOutputCount(this ArgumentContainer container, int count) + { + container.Add(new FrameOutputCountArgument(count)); + return container; + } + + public static ArgumentContainer FrameRate(this ArgumentContainer container, double framerate) + { + container.Add(new FrameRateArgument(framerate)); + return container; + } + + public static ArgumentContainer Input(this ArgumentContainer container, string path) + { + container.Add(new InputArgument(path)); + return container; + } + + public static ArgumentContainer Input(this ArgumentContainer container, IEnumerable paths) + { + container.Add(new InputArgument(paths.ToArray())); + return container; + } + + public static ArgumentContainer Input(this ArgumentContainer container, params string[] paths) + { + container.Add(new InputArgument(paths)); + return container; + } + + public static ArgumentContainer Input(this ArgumentContainer container, VideoInfo path) + { + container.Add(new InputArgument(path)); + return container; + } + + public static ArgumentContainer Input(this ArgumentContainer container, IEnumerable paths) + { + container.Add(new InputArgument(paths.ToArray())); + return container; + } + + public static ArgumentContainer Input(this ArgumentContainer container, params VideoInfo[] paths) + { + container.Add(new InputArgument(paths)); + return container; + } + + public static ArgumentContainer Input(this ArgumentContainer container, FileInfo path) + { + container.Add(new InputArgument(path)); + return container; + } + + public static ArgumentContainer Input(this ArgumentContainer container, IEnumerable paths) + { + container.Add(new InputArgument(paths.ToArray())); + return container; + } + + public static ArgumentContainer Input(this ArgumentContainer container, params FileInfo[] paths) + { + container.Add(new InputArgument(paths)); + return container; + } + + public static ArgumentContainer Input(this ArgumentContainer container, Uri uri) + { + container.Add(new InputArgument(uri)); + return container; + } + + public static ArgumentContainer Input(this ArgumentContainer container, IEnumerable uris) + { + container.Add(new InputArgument(uris.ToArray())); + return container; + } + + public static ArgumentContainer Input(this ArgumentContainer container, params Uri[] uris) + { + container.Add(new InputArgument(uris)); + return container; + } + + public static ArgumentContainer Loop(this ArgumentContainer container, int times) + { + container.Add(new LoopArgument(times)); + return container; + } + + public static ArgumentContainer Output(this ArgumentContainer container, string path) + { + container.Add(new OutputArgument(path)); + return container; + } + + public static ArgumentContainer Output(this ArgumentContainer container, VideoInfo path) + { + container.Add(new OutputArgument(path)); + return container; + } + + public static ArgumentContainer Output(this ArgumentContainer container, FileInfo path) + { + container.Add(new OutputArgument(path)); + return container; + } + + public static ArgumentContainer Output(this ArgumentContainer container, Uri path) + { + container.Add(new OutputArgument(path)); + return container; + } + + public static ArgumentContainer Override(this ArgumentContainer container) + { + container.Add(new OverrideArgument()); + return container; + } + + public static ArgumentContainer RemoveMetadata(this ArgumentContainer container) + { + container.Add(new RemoveMetadataArgument()); + return container; + } + + public static ArgumentContainer Scale(this ArgumentContainer container, Size value) + { + container.Add(new ScaleArgument(value)); + return container; + } + + public static ArgumentContainer Scale(this ArgumentContainer container, VideoSize value) + { + container.Add(new ScaleArgument(value)); + return container; + } + + public static ArgumentContainer Scale(this ArgumentContainer container, int width, int height) + { + container.Add(new ScaleArgument(width, height)); + return container; + } + + public static ArgumentContainer Seek(this ArgumentContainer container, TimeSpan? value) + { + container.Add(new SeekArgument(value)); + return container; + } + + public static ArgumentContainer Shortest(this ArgumentContainer container) + { + container.Add(new ShortestArgument(true)); + return container; + } + + public static ArgumentContainer Size(this ArgumentContainer container, Size value) + { + container.Add(new SizeArgument(value)); + return container; + } + + public static ArgumentContainer Size(this ArgumentContainer container, VideoSize value) + { + container.Add(new SizeArgument(value)); + return container; + } + + public static ArgumentContainer Size(this ArgumentContainer container, int width, int height) + { + container.Add(new SizeArgument(width, height)); + return container; + } + + public static ArgumentContainer Speed(this ArgumentContainer container, Speed value) + { + container.Add(new SpeedArgument(value)); + return container; + } + + public static ArgumentContainer StartNumber(this ArgumentContainer container, int value) + { + container.Add(new StartNumberArgument(value)); + return container; + } + + public static ArgumentContainer Threads(this ArgumentContainer container, int value) + { + container.Add(new ThreadsArgument(value)); + return container; + } + + public static ArgumentContainer MultiThreaded(this ArgumentContainer container) + { + container.Add(new ThreadsArgument(true)); + return container; + } + + public static ArgumentContainer Transpose(this ArgumentContainer container, int transpose) + { + container.Add(new TransposeArgument(transpose)); + return container; + } + + public static ArgumentContainer VariableBitRate(this ArgumentContainer container, int vbr) + { + container.Add(new VariableBitRateArgument(vbr)); + return container; + } + + public static ArgumentContainer VideoCodec(this ArgumentContainer container, VideoCodec codec) + { + container.Add(new VideoCodecArgument(codec)); + return container; + } + + public static ArgumentContainer VideoCodec(this ArgumentContainer container, VideoCodec codec, int bitrate) + { + container.Add(new VideoCodecArgument(codec, bitrate)); + return container; + } + } +} From 240c9bb23b990855a1e102edb459217975eb2a29 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: Thu, 30 Apr 2020 15:13:47 +0300 Subject: [PATCH 2/4] Added DrawTextOptions --- .../ArgumentContainerFluentExtensions.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/FFMpegCore/FFMPEG/Argument/ArgumentContainerFluentExtensions.cs b/FFMpegCore/FFMPEG/Argument/ArgumentContainerFluentExtensions.cs index 4e8cc98..daf905c 100644 --- a/FFMpegCore/FFMPEG/Argument/ArgumentContainerFluentExtensions.cs +++ b/FFMpegCore/FFMPEG/Argument/ArgumentContainerFluentExtensions.cs @@ -82,6 +82,32 @@ public static ArgumentContainer DisableChannel(this ArgumentContainer container, return container; } + public class DrawTextOptions + { + public string Text { get; set; } + public string FontPath { get; set; } + public List<(string, string)> Params { get; private set; } + + public DrawTextOptions() + { + Params = new List<(string, string)>(); + } + + public DrawTextOptions AddParam(string key, string value) + { + Params.Add((key, value)); + return this; + } + } + + public static ArgumentContainer DrawText(this ArgumentContainer container, Action builder) + { + var argumentParams = new DrawTextOptions(); + builder.Invoke(argumentParams); + container.Add(new DrawTextArgument(argumentParams.Text, argumentParams.FontPath, argumentParams.Params.ToArray())); + return container; + } + public static ArgumentContainer DrawText(this ArgumentContainer container, string text, string fontPath, params (string, string)[] optionalArguments) { container.Add(new DrawTextArgument(text, fontPath, optionalArguments)); From b7aafeb586a8aef8f11bf7c8aca4754d93a23d22 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: Thu, 30 Apr 2020 15:14:10 +0300 Subject: [PATCH 3/4] Added Fluent tests --- FFMpegCore.Test/ArgumentBuilderTest.cs | 219 +++++++++++++++++++++++++ 1 file changed, 219 insertions(+) diff --git a/FFMpegCore.Test/ArgumentBuilderTest.cs b/FFMpegCore.Test/ArgumentBuilderTest.cs index cde8da2..482830d 100644 --- a/FFMpegCore.Test/ArgumentBuilderTest.cs +++ b/FFMpegCore.Test/ArgumentBuilderTest.cs @@ -1,4 +1,5 @@ using FFMpegCore.FFMPEG.Argument; +using FFMpegCore.FFMPEG.Argument.Fluent; using FFMpegCore.FFMPEG.Enums; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; @@ -31,6 +32,18 @@ private string GetArgumentsString(params Argument[] args) return builder.BuildArguments(container); } + private string GetArgumentsString(ArgumentContainer container) + { + var resContainer = new ArgumentContainer { new InputArgument("input.mp4") }; + foreach (var a in container) + { + resContainer.Add(a.Value); + } + resContainer.Add(new OutputArgument("output.mp4")); + + return builder.BuildArguments(resContainer); + } + [TestMethod] public void Builder_BuildString_IO_1() @@ -48,6 +61,15 @@ public void Builder_BuildString_Scale() Assert.AreEqual(str, "-i \"input.mp4\" -vf scale=-1:720 \"output.mp4\""); } + + [TestMethod] + public void Builder_BuildString_Scale_Fluent() + { + var str = GetArgumentsString(new ArgumentContainer().Scale(VideoSize.Hd)); + + Assert.AreEqual(str, "-i \"input.mp4\" -vf scale=-1:720 \"output.mp4\""); + } + [TestMethod] public void Builder_BuildString_AudioCodec() { @@ -55,6 +77,14 @@ public void Builder_BuildString_AudioCodec() Assert.AreEqual(str, "-i \"input.mp4\" -c:a aac -b:a 128k \"output.mp4\""); } + + [TestMethod] + public void Builder_BuildString_AudioCodec_Fluent() + { + var str = GetArgumentsString(new ArgumentContainer().AudioCodec(AudioCodec.Aac, AudioQuality.Normal)); + Assert.AreEqual(str, "-i \"input.mp4\" -c:a aac -b:a 128k \"output.mp4\""); + } + [TestMethod] public void Builder_BuildString_BitStream() { @@ -63,6 +93,14 @@ public void Builder_BuildString_BitStream() Assert.AreEqual(str, "-i \"input.mp4\" -bsf:a h264_mp4toannexb \"output.mp4\""); } + [TestMethod] + public void Builder_BuildString_BitStream_Fluent() + { + var str = GetArgumentsString(new ArgumentContainer().BitStreamFilter(Channel.Audio, Filter.H264_Mp4ToAnnexB)); + + Assert.AreEqual(str, "-i \"input.mp4\" -bsf:a h264_mp4toannexb \"output.mp4\""); + } + [TestMethod] public void Builder_BuildString_Concat() { @@ -74,6 +112,20 @@ public void Builder_BuildString_Concat() Assert.AreEqual(str, "-i \"concat:1.mp4|2.mp4|3.mp4|4.mp4\" \"output.mp4\""); } + + [TestMethod] + public void Builder_BuildString_Concat_Fluent() + { + var container = new ArgumentContainer() + .Concat(concatFiles) + .Output("output.mp4"); + + + var str = builder.BuildArguments(container); + + Assert.AreEqual(str, "-i \"concat:1.mp4|2.mp4|3.mp4|4.mp4\" \"output.mp4\""); + } + [TestMethod] public void Builder_BuildString_Copy_Audio() { @@ -82,6 +134,13 @@ public void Builder_BuildString_Copy_Audio() Assert.AreEqual(str, "-i \"input.mp4\" -c:a copy \"output.mp4\""); } + [TestMethod] + public void Builder_BuildString_Copy_Audio_Fluent() + { + var str = GetArgumentsString(new ArgumentContainer().Copy(Channel.Audio)); + + Assert.AreEqual(str, "-i \"input.mp4\" -c:a copy \"output.mp4\""); + } [TestMethod] public void Builder_BuildString_Copy_Video() @@ -91,6 +150,15 @@ public void Builder_BuildString_Copy_Video() Assert.AreEqual(str, "-i \"input.mp4\" -c:v copy \"output.mp4\""); } + [TestMethod] + public void Builder_BuildString_Copy_Video_Fluent() + { + var str = GetArgumentsString(new ArgumentContainer().Copy(Channel.Video)); + + Assert.AreEqual(str, "-i \"input.mp4\" -c:v copy \"output.mp4\""); + } + + [TestMethod] public void Builder_BuildString_Copy_Both() { @@ -99,6 +167,14 @@ public void Builder_BuildString_Copy_Both() Assert.AreEqual(str, "-i \"input.mp4\" -c copy \"output.mp4\""); } + [TestMethod] + public void Builder_BuildString_Copy_Both_Fluent() + { + var str = GetArgumentsString(new ArgumentContainer().Copy(Channel.Both)); + + Assert.AreEqual(str, "-i \"input.mp4\" -c copy \"output.mp4\""); + } + [TestMethod] public void Builder_BuildString_CpuSpeed() { @@ -107,6 +183,14 @@ public void Builder_BuildString_CpuSpeed() Assert.AreEqual(str, "-i \"input.mp4\" -quality good -cpu-used 10 -deadline realtime \"output.mp4\""); } + [TestMethod] + public void Builder_BuildString_CpuSpeed_Fluent() + { + var str = GetArgumentsString(new ArgumentContainer().CpuSpeed(10)); + + Assert.AreEqual(str, "-i \"input.mp4\" -quality good -cpu-used 10 -deadline realtime \"output.mp4\""); + } + [TestMethod] public void Builder_BuildString_ForceFormat() { @@ -115,6 +199,14 @@ public void Builder_BuildString_ForceFormat() Assert.AreEqual(str, "-i \"input.mp4\" -f libx264 \"output.mp4\""); } + [TestMethod] + public void Builder_BuildString_ForceFormat_Fluent() + { + var str = GetArgumentsString(new ArgumentContainer().ForceFormat(VideoCodec.LibX264)); + + Assert.AreEqual(str, "-i \"input.mp4\" -f libx264 \"output.mp4\""); + } + [TestMethod] public void Builder_BuildString_FrameOutputCount() { @@ -123,6 +215,14 @@ public void Builder_BuildString_FrameOutputCount() Assert.AreEqual(str, "-i \"input.mp4\" -vframes 50 \"output.mp4\""); } + [TestMethod] + public void Builder_BuildString_FrameOutputCount_Fluent() + { + var str = GetArgumentsString(new ArgumentContainer().FrameOutputCount(50)); + + Assert.AreEqual(str, "-i \"input.mp4\" -vframes 50 \"output.mp4\""); + } + [TestMethod] public void Builder_BuildString_FrameRate() { @@ -131,6 +231,14 @@ public void Builder_BuildString_FrameRate() Assert.AreEqual(str, "-i \"input.mp4\" -r 50 \"output.mp4\""); } + [TestMethod] + public void Builder_BuildString_FrameRate_Fluent() + { + var str = GetArgumentsString(new ArgumentContainer().FrameRate(50)); + + Assert.AreEqual(str, "-i \"input.mp4\" -r 50 \"output.mp4\""); + } + [TestMethod] public void Builder_BuildString_Loop() { @@ -139,6 +247,14 @@ public void Builder_BuildString_Loop() Assert.AreEqual(str, "-i \"input.mp4\" -loop 50 \"output.mp4\""); } + [TestMethod] + public void Builder_BuildString_Loop_Fluent() + { + var str = GetArgumentsString(new ArgumentContainer().Loop(50)); + + Assert.AreEqual(str, "-i \"input.mp4\" -loop 50 \"output.mp4\""); + } + [TestMethod] public void Builder_BuildString_Seek() { @@ -147,6 +263,14 @@ public void Builder_BuildString_Seek() Assert.AreEqual(str, "-i \"input.mp4\" -ss 00:00:10 \"output.mp4\""); } + [TestMethod] + public void Builder_BuildString_Seek_Fluent() + { + var str = GetArgumentsString(new ArgumentContainer().Seek(TimeSpan.FromSeconds(10))); + + Assert.AreEqual(str, "-i \"input.mp4\" -ss 00:00:10 \"output.mp4\""); + } + [TestMethod] public void Builder_BuildString_Shortest() { @@ -155,6 +279,14 @@ public void Builder_BuildString_Shortest() Assert.AreEqual(str, "-i \"input.mp4\" -shortest \"output.mp4\""); } + [TestMethod] + public void Builder_BuildString_Shortest_Fluent() + { + var str = GetArgumentsString(new ArgumentContainer().Shortest()); + + Assert.AreEqual(str, "-i \"input.mp4\" -shortest \"output.mp4\""); + } + [TestMethod] public void Builder_BuildString_Size() { @@ -163,6 +295,14 @@ public void Builder_BuildString_Size() Assert.AreEqual(str, "-i \"input.mp4\" -s 1920x1080 \"output.mp4\""); } + [TestMethod] + public void Builder_BuildString_Size_Fluent() + { + var str = GetArgumentsString(new ArgumentContainer().Size(1920, 1080)); + + Assert.AreEqual(str, "-i \"input.mp4\" -s 1920x1080 \"output.mp4\""); + } + [TestMethod] public void Builder_BuildString_Speed() { @@ -171,6 +311,14 @@ public void Builder_BuildString_Speed() Assert.AreEqual(str, "-i \"input.mp4\" -preset fast \"output.mp4\""); } + [TestMethod] + public void Builder_BuildString_Speed_Fluent() + { + var str = GetArgumentsString(new ArgumentContainer().Speed(Speed.Fast)); + + Assert.AreEqual(str, "-i \"input.mp4\" -preset fast \"output.mp4\""); + } + [TestMethod] public void Builder_BuildString_DrawtextFilter() { @@ -186,6 +334,27 @@ public void Builder_BuildString_DrawtextFilter() Assert.AreEqual("-i \"input.mp4\" -vf drawtext=\"text='Stack Overflow': fontfile=/path/to/font.ttf: fontcolor=white: fontsize=24: box=1: boxcolor=black@0.5: boxborderw=5: x=(w-text_w)/2: y=(h-text_h)/2\" \"output.mp4\"", str); } + [TestMethod] + public void Builder_BuildString_DrawtextFilter_Fluent() + { + var container = new ArgumentContainer(). + DrawText((options) => + { + options.Text = "Stack Overflow"; + options.FontPath = "/path/to/font.ttf"; + options.AddParam("fontcolor", "white") + .AddParam("fontsize", "24") + .AddParam("box", "1") + .AddParam("boxcolor", "black@0.5") + .AddParam("boxborderw", "5") + .AddParam("x", "(w-text_w)/2") + .AddParam("y", "(h-text_h)/2"); + }); + var str = GetArgumentsString(container); + + Assert.AreEqual("-i \"input.mp4\" -vf drawtext=\"text='Stack Overflow': fontfile=/path/to/font.ttf: fontcolor=white: fontsize=24: box=1: boxcolor=black@0.5: boxborderw=5: x=(w-text_w)/2: y=(h-text_h)/2\" \"output.mp4\"", str); + } + [TestMethod] public void Builder_BuildString_StartNumber() { @@ -194,6 +363,15 @@ public void Builder_BuildString_StartNumber() Assert.AreEqual(str, "-i \"input.mp4\" -start_number 50 \"output.mp4\""); } + + [TestMethod] + public void Builder_BuildString_StartNumber_Fluent() + { + var str = GetArgumentsString(new ArgumentContainer().StartNumber(50)); + + Assert.AreEqual(str, "-i \"input.mp4\" -start_number 50 \"output.mp4\""); + } + [TestMethod] public void Builder_BuildString_Threads_1() { @@ -202,6 +380,14 @@ public void Builder_BuildString_Threads_1() Assert.AreEqual(str, "-i \"input.mp4\" -threads 50 \"output.mp4\""); } + [TestMethod] + public void Builder_BuildString_Threads_1_Fluent() + { + var str = GetArgumentsString(new ArgumentContainer().Threads(50)); + + Assert.AreEqual(str, "-i \"input.mp4\" -threads 50 \"output.mp4\""); + } + [TestMethod] public void Builder_BuildString_Threads_2() { @@ -210,6 +396,14 @@ public void Builder_BuildString_Threads_2() Assert.AreEqual(str, $"-i \"input.mp4\" -threads {Environment.ProcessorCount} \"output.mp4\""); } + [TestMethod] + public void Builder_BuildString_Threads_2_Fluent() + { + var str = GetArgumentsString(new ArgumentContainer().MultiThreaded()); + + Assert.AreEqual(str, $"-i \"input.mp4\" -threads {Environment.ProcessorCount} \"output.mp4\""); + } + [TestMethod] public void Builder_BuildString_Codec() @@ -219,6 +413,14 @@ public void Builder_BuildString_Codec() Assert.AreEqual(str, "-i \"input.mp4\" -c:v libx264 -pix_fmt yuv420p \"output.mp4\""); } + [TestMethod] + public void Builder_BuildString_Codec_Fluent() + { + var str = GetArgumentsString(new ArgumentContainer().VideoCodec(VideoCodec.LibX264)); + + Assert.AreEqual(str, "-i \"input.mp4\" -c:v libx264 -pix_fmt yuv420p \"output.mp4\""); + } + [TestMethod] public void Builder_BuildString_Codec_Override() { @@ -227,11 +429,28 @@ public void Builder_BuildString_Codec_Override() Assert.AreEqual(str, "-i \"input.mp4\" -c:v libx264 -pix_fmt yuv420p -y \"output.mp4\""); } + [TestMethod] + public void Builder_BuildString_Codec_Override_Fluent() + { + var str = GetArgumentsString(new ArgumentContainer().VideoCodec(VideoCodec.LibX264).Override()); + + Assert.AreEqual(str, "-i \"input.mp4\" -c:v libx264 -pix_fmt yuv420p -y \"output.mp4\""); + } + + [TestMethod] public void Builder_BuildString_Duration() { var str = GetArgumentsString(new DurationArgument(TimeSpan.FromSeconds(20))); Assert.AreEqual(str, "-i \"input.mp4\" -t 00:00:20 \"output.mp4\""); } + + [TestMethod] + public void Builder_BuildString_Duration_Fluent() + { + var str = GetArgumentsString(new ArgumentContainer().Duration(TimeSpan.FromSeconds(20))); + + Assert.AreEqual(str, "-i \"input.mp4\" -t 00:00:20 \"output.mp4\""); + } } } From 7884e91f636fc7027c9403f6e6cad59b0575d349 Mon Sep 17 00:00:00 2001 From: Max Bagryantsev Date: Thu, 30 Apr 2020 15:23:55 +0300 Subject: [PATCH 4/4] Update README.md --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 6fddd05..04214df 100644 --- a/README.md +++ b/README.md @@ -363,7 +363,16 @@ Custom video converting presets could be created with help of `ArgumentsContaine var container = new ArgumentsContainer(); container.Add(new VideoCodecArgument(VideoCodec.LibX264)); container.Add(new ScaleArgument(VideoSize.Hd)); +``` +or use Fluent API +```csharp +var container = new ArgumentContainer() + .VideoCodec(VideoCodec.LibX264) + .Scale(VideoSize.Hd); +``` + +```csharp var ffmpeg = new FFMpeg(); var result = ffmpeg.Convert(container, new FileInfo("input.mp4"), new FileInfo("output.mp4")); ```