From 229fb9398093a9b156e873072e72b8eee0292e6d Mon Sep 17 00:00:00 2001 From: Victor Horobchuk Date: Wed, 17 Mar 2021 00:09:56 +0200 Subject: [PATCH 1/6] Add mirror and default ForceFormat for OutputPipeArgument Former-commit-id: ec1b8a6b0757281825c4c9e869b698e8ada33206 --- FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs | 11 +++++++++++ FFMpegCore/FFMpeg/FFMpegArguments.cs | 6 ++++++ 2 files changed, 17 insertions(+) create mode 100644 FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs diff --git a/FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs b/FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs new file mode 100644 index 0000000..4c18cef --- /dev/null +++ b/FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace FFMpegCore.Arguments +{ + public class SetMirrorVideo : IArgument + { + public string Text { get; set; } = "-vf \"hflip\""; + } +} diff --git a/FFMpegCore/FFMpeg/FFMpegArguments.cs b/FFMpegCore/FFMpeg/FFMpegArguments.cs index 847e68c..5aa913d 100644 --- a/FFMpegCore/FFMpeg/FFMpegArguments.cs +++ b/FFMpegCore/FFMpeg/FFMpegArguments.cs @@ -57,6 +57,12 @@ private FFMpegArgumentProcessor ToProcessor(IOutputArgument argument, Action x is ForceFormatArgument)) + { + args.ForceFormat("matroska"); + } + Arguments.AddRange(args.Arguments); Arguments.Add(argument); return new FFMpegArgumentProcessor(this); From d0afc5001b468f5889a30787ff141927d7efb05b Mon Sep 17 00:00:00 2001 From: Victor Horobchuk Date: Wed, 17 Mar 2021 09:58:01 +0200 Subject: [PATCH 2/6] Update Former-commit-id: ab8be5cd57318d7b6e948afed23c136faa6d6a68 --- FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs | 27 +++++++++++++++++-- FFMpegCore/FFMpeg/Enums/Mirror.cs | 12 +++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 FFMpegCore/FFMpeg/Enums/Mirror.cs diff --git a/FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs b/FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs index 4c18cef..91ab1c4 100644 --- a/FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs +++ b/FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs @@ -1,4 +1,5 @@ -using System; +using FFMpegCore.Enums; +using System; using System.Collections.Generic; using System.Text; @@ -6,6 +7,28 @@ namespace FFMpegCore.Arguments { public class SetMirrorVideo : IArgument { - public string Text { get; set; } = "-vf \"hflip\""; + public SetMirrorVideo(Mirror value) + { + _value = value; + } + + public Mirror _value { get; set; } + + public string Text + { + get + { + switch (_value) + { + case Mirror.Horizontall: + return "-vf \"hflip\""; + case Mirror.Verticall: + return "-vf \"vflip\""; + default: + throw new Exception("SetMirrorVideo: argument not found"); + } + + } + } } } diff --git a/FFMpegCore/FFMpeg/Enums/Mirror.cs b/FFMpegCore/FFMpeg/Enums/Mirror.cs new file mode 100644 index 0000000..da5523c --- /dev/null +++ b/FFMpegCore/FFMpeg/Enums/Mirror.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace FFMpegCore.Enums +{ + public enum Mirror : byte + { + Verticall = 1, + Horizontall = 2 + } +} From 93496db720b2a5814a5815ee98126b11daf256bc Mon Sep 17 00:00:00 2001 From: Victor Horobchuk Date: Thu, 18 Mar 2021 21:37:02 +0200 Subject: [PATCH 3/6] Update Former-commit-id: 4e8548298813016a967b8e1a101abf7371e85e69 --- FFMpegCore.sln | 8 ++++---- FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs | 10 ++++++---- FFMpegCore/FFMpeg/Enums/Mirror.cs | 6 +++--- FFMpegCore/FFMpeg/FFMpegArguments.cs | 6 ------ 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/FFMpegCore.sln b/FFMpegCore.sln index 27eab0a..7a27980 100644 --- a/FFMpegCore.sln +++ b/FFMpegCore.sln @@ -1,13 +1,13 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28307.329 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31005.135 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FFMpegCore", "FFMpegCore\FFMpegCore.csproj", "{19DE2EC2-9955-4712-8096-C22EF6713E4F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FFMpegCore", "FFMpegCore\FFMpegCore.csproj", "{19DE2EC2-9955-4712-8096-C22EF6713E4F}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FFMpegCore.Test", "FFMpegCore.Test\FFMpegCore.Test.csproj", "{F20C8353-72D9-454B-9F16-3624DBAD2328}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FFMpegCore.Examples", "FFMpegCore.Examples\FFMpegCore.Examples.csproj", "{3125CF91-FFBD-4E4E-8930-247116AFE772}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FFMpegCore.Examples", "FFMpegCore.Examples\FFMpegCore.Examples.csproj", "{3125CF91-FFBD-4E4E-8930-247116AFE772}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs b/FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs index 91ab1c4..94fbd0f 100644 --- a/FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs +++ b/FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs @@ -5,7 +5,7 @@ namespace FFMpegCore.Arguments { - public class SetMirrorVideo : IArgument + public class SetMirrorVideo : IVideoFilterArgument { public SetMirrorVideo(Mirror value) { @@ -14,16 +14,18 @@ public SetMirrorVideo(Mirror value) public Mirror _value { get; set; } - public string Text + public string Key => string.Empty; + + public string Value { get { switch (_value) { case Mirror.Horizontall: - return "-vf \"hflip\""; + return "hflip"; case Mirror.Verticall: - return "-vf \"vflip\""; + return "vflip"; default: throw new Exception("SetMirrorVideo: argument not found"); } diff --git a/FFMpegCore/FFMpeg/Enums/Mirror.cs b/FFMpegCore/FFMpeg/Enums/Mirror.cs index da5523c..e091c5b 100644 --- a/FFMpegCore/FFMpeg/Enums/Mirror.cs +++ b/FFMpegCore/FFMpeg/Enums/Mirror.cs @@ -4,9 +4,9 @@ namespace FFMpegCore.Enums { - public enum Mirror : byte + public enum Mirror { - Verticall = 1, - Horizontall = 2 + Verticall, + Horizontall } } diff --git a/FFMpegCore/FFMpeg/FFMpegArguments.cs b/FFMpegCore/FFMpeg/FFMpegArguments.cs index 5aa913d..847e68c 100644 --- a/FFMpegCore/FFMpeg/FFMpegArguments.cs +++ b/FFMpegCore/FFMpeg/FFMpegArguments.cs @@ -57,12 +57,6 @@ private FFMpegArgumentProcessor ToProcessor(IOutputArgument argument, Action x is ForceFormatArgument)) - { - args.ForceFormat("matroska"); - } - Arguments.AddRange(args.Arguments); Arguments.Add(argument); return new FFMpegArgumentProcessor(this); From c690817135f8080498e1e61b0062721ef37fe144 Mon Sep 17 00:00:00 2001 From: Victor Horobchuk Date: Mon, 22 Mar 2021 12:25:13 +0200 Subject: [PATCH 4/6] update Former-commit-id: 4e6ecda8843f0462a379cdda4a05a99fd6edaedf --- FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs | 6 +++--- FFMpegCore/FFMpeg/Enums/Mirror.cs | 10 +++------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs b/FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs index 94fbd0f..d394856 100644 --- a/FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs +++ b/FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs @@ -22,12 +22,12 @@ public string Value { switch (_value) { - case Mirror.Horizontall: + case Mirror.Horizontal: return "hflip"; - case Mirror.Verticall: + case Mirror.Vertical: return "vflip"; default: - throw new Exception("SetMirrorVideo: argument not found"); + throw new ArgumentOutOfRangeException("SetMirrorVideo: argument not found"); } } diff --git a/FFMpegCore/FFMpeg/Enums/Mirror.cs b/FFMpegCore/FFMpeg/Enums/Mirror.cs index e091c5b..72e98e4 100644 --- a/FFMpegCore/FFMpeg/Enums/Mirror.cs +++ b/FFMpegCore/FFMpeg/Enums/Mirror.cs @@ -1,12 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace FFMpegCore.Enums +namespace FFMpegCore.Enums { public enum Mirror { - Verticall, - Horizontall + Vertical, + Horizontal } } From 12e031dfb3efce06d163986bf922e85c2bd38dfa Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Fri, 14 May 2021 01:02:00 +0200 Subject: [PATCH 5/6] Fixes, renames and missing stuff Former-commit-id: 27a2219b8e86a8e62172c8e1ecd09a48fd076439 --- FFMpegCore.Test/ArgumentBuilderTest.cs | 11 ++++++ FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs | 36 ------------------- .../FFMpeg/Arguments/SetMirroringArgument.cs | 32 +++++++++++++++++ .../FFMpeg/Arguments/VideoFiltersArgument.cs | 13 +++++-- .../FFMpeg/Enums/{Mirror.cs => Mirroring.cs} | 2 +- 5 files changed, 55 insertions(+), 39 deletions(-) delete mode 100644 FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs create mode 100644 FFMpegCore/FFMpeg/Arguments/SetMirroringArgument.cs rename FFMpegCore/FFMpeg/Enums/{Mirror.cs => Mirroring.cs} (76%) diff --git a/FFMpegCore.Test/ArgumentBuilderTest.cs b/FFMpegCore.Test/ArgumentBuilderTest.cs index 18a8c7d..daa3eda 100644 --- a/FFMpegCore.Test/ArgumentBuilderTest.cs +++ b/FFMpegCore.Test/ArgumentBuilderTest.cs @@ -192,6 +192,17 @@ public void Builder_BuildString_Transpose() Assert.AreEqual("-i \"input.mp4\" -vf \"transpose=2\" \"output.mp4\"", str); } + [TestMethod] + public void Builder_BuildString_Mirroring() + { + var str = FFMpegArguments.FromFileInput("input.mp4") + .OutputToFile("output.mp4", false, opt => opt + .WithVideoFilters(filterOptions => filterOptions + .Mirror(Mirroring.Horizontal))) + .Arguments; + Assert.AreEqual("-i \"input.mp4\" -vf \"hflip\" \"output.mp4\"", str); + } + [TestMethod] public void Builder_BuildString_TransposeScale() { diff --git a/FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs b/FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs deleted file mode 100644 index d394856..0000000 --- a/FFMpegCore/FFMpeg/Arguments/SetMirrorVideo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using FFMpegCore.Enums; -using System; -using System.Collections.Generic; -using System.Text; - -namespace FFMpegCore.Arguments -{ - public class SetMirrorVideo : IVideoFilterArgument - { - public SetMirrorVideo(Mirror value) - { - _value = value; - } - - public Mirror _value { get; set; } - - public string Key => string.Empty; - - public string Value - { - get - { - switch (_value) - { - case Mirror.Horizontal: - return "hflip"; - case Mirror.Vertical: - return "vflip"; - default: - throw new ArgumentOutOfRangeException("SetMirrorVideo: argument not found"); - } - - } - } - } -} diff --git a/FFMpegCore/FFMpeg/Arguments/SetMirroringArgument.cs b/FFMpegCore/FFMpeg/Arguments/SetMirroringArgument.cs new file mode 100644 index 0000000..f042f77 --- /dev/null +++ b/FFMpegCore/FFMpeg/Arguments/SetMirroringArgument.cs @@ -0,0 +1,32 @@ +using FFMpegCore.Enums; +using System; +using System.Collections.Generic; +using System.Text; + +namespace FFMpegCore.Arguments +{ + public class SetMirroringArgument : IVideoFilterArgument + { + public SetMirroringArgument(Mirroring mirroring) + { + Mirroring = mirroring; + } + + public Mirroring Mirroring { get; set; } + + public string Key => string.Empty; + + public string Value + { + get + { + return Mirroring switch + { + Mirroring.Horizontal => "hflip", + Mirroring.Vertical => "vflip", + _ => throw new ArgumentOutOfRangeException(nameof(Mirroring)) + }; + } + } + } +} diff --git a/FFMpegCore/FFMpeg/Arguments/VideoFiltersArgument.cs b/FFMpegCore/FFMpeg/Arguments/VideoFiltersArgument.cs index f7fef93..fa4ae1e 100644 --- a/FFMpegCore/FFMpeg/Arguments/VideoFiltersArgument.cs +++ b/FFMpegCore/FFMpeg/Arguments/VideoFiltersArgument.cs @@ -17,12 +17,20 @@ public VideoFiltersArgument(VideoFilterOptions options) public string Text => GetText(); - public string GetText() + private string GetText() { if (!Options.Arguments.Any()) throw new FFMpegArgumentException("No video-filter arguments provided"); - return $"-vf \"{string.Join(", ", Options.Arguments.Where(arg => !string.IsNullOrEmpty(arg.Value)).Select(arg => $"{arg.Key}={arg.Value.Replace(",", "\\,")}"))}\""; + var arguments = Options.Arguments + .Where(arg => !string.IsNullOrEmpty(arg.Value)) + .Select(arg => + { + var escapedValue = arg.Value.Replace(",", "\\,"); + return string.IsNullOrEmpty(arg.Key) ? escapedValue : $"{arg.Key}={escapedValue}"; + }); + + return $"-vf \"{string.Join(", ", arguments)}\""; } } @@ -40,6 +48,7 @@ public class VideoFilterOptions public VideoFilterOptions Scale(int width, int height) => WithArgument(new ScaleArgument(width, height)); public VideoFilterOptions Scale(Size size) => WithArgument(new ScaleArgument(size)); public VideoFilterOptions Transpose(Transposition transposition) => WithArgument(new TransposeArgument(transposition)); + public VideoFilterOptions Mirror(Mirroring mirroring) => WithArgument(new SetMirroringArgument(mirroring)); public VideoFilterOptions DrawText(DrawTextOptions drawTextOptions) => WithArgument(new DrawTextArgument(drawTextOptions)); private VideoFilterOptions WithArgument(IVideoFilterArgument argument) diff --git a/FFMpegCore/FFMpeg/Enums/Mirror.cs b/FFMpegCore/FFMpeg/Enums/Mirroring.cs similarity index 76% rename from FFMpegCore/FFMpeg/Enums/Mirror.cs rename to FFMpegCore/FFMpeg/Enums/Mirroring.cs index 72e98e4..5768163 100644 --- a/FFMpegCore/FFMpeg/Enums/Mirror.cs +++ b/FFMpegCore/FFMpeg/Enums/Mirroring.cs @@ -1,6 +1,6 @@ namespace FFMpegCore.Enums { - public enum Mirror + public enum Mirroring { Vertical, Horizontal From 4d3ba4192b1e86d4a5be36a4268ccdc3305faf78 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Fri, 14 May 2021 01:08:01 +0200 Subject: [PATCH 6/6] Update nuget meta Former-commit-id: 811471ed7782d1e1935b897a8750a72f63f05b31 --- FFMpegCore/FFMpegCore.csproj | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/FFMpegCore/FFMpegCore.csproj b/FFMpegCore/FFMpegCore.csproj index 47b41d8..bf9e682 100644 --- a/FFMpegCore/FFMpegCore.csproj +++ b/FFMpegCore/FFMpegCore.csproj @@ -9,11 +9,9 @@ 3.0.0.0 3.0.0.0 3.0.0.0 - - Fixes for RawVideoPipeSource hanging (thanks to max619) -- Added .OutputToUrl(..) method for outputting to url using supported protocol (thanks to TFleury) -- Improved timespan parsing (thanks to test-in-prod) + - Added support for mirroring video filter (thanks gorobvictor) 8 - 4.1.0 + 4.2.0 MIT Malte Rosenbjerg, Vlad Jerca, Max Bagryantsev ffmpeg ffprobe convert video audio mediafile resize analyze muxing