From b3b613b42510f9310d7dde733001f3c861d1c606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20B=C3=BChler?= Date: Thu, 10 Jan 2019 12:01:30 +0100 Subject: [PATCH 1/6] add preset support --- Hudl.FFmpeg/Enums/PresetType.cs | 25 +++++++++++++++++++++++++ Hudl.FFmpeg/Settings/Preset.cs | 29 +++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 Hudl.FFmpeg/Enums/PresetType.cs create mode 100644 Hudl.FFmpeg/Settings/Preset.cs diff --git a/Hudl.FFmpeg/Enums/PresetType.cs b/Hudl.FFmpeg/Enums/PresetType.cs new file mode 100644 index 0000000..828f8b9 --- /dev/null +++ b/Hudl.FFmpeg/Enums/PresetType.cs @@ -0,0 +1,25 @@ +namespace Hudl.FFmpeg.Enums +{ + + /// + /// enumeration containing the known preset types + /// The general guideline is to use the slowest preset that you have patience for. + /// Current presets in descending order of speed are: ultrafast,superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo. + /// The default preset is medium. Ignore placebo as it is not useful (see https://trac.ffmpeg.org/wiki/Encode/H.264#FAQ). + /// You can see a list of current presets with -preset help (see example below), and what settings they apply with x264 --fullhelp. + /// https://trac.ffmpeg.org/wiki/Encode/H.264#a2.Chooseapreset + /// + public enum PresetType + { + ultrafast, + superfast, + veryfast, + faster, + fast, + medium, + slow, + slower, + veryslow, + placebo + } +} \ No newline at end of file diff --git a/Hudl.FFmpeg/Settings/Preset.cs b/Hudl.FFmpeg/Settings/Preset.cs new file mode 100644 index 0000000..a38b71b --- /dev/null +++ b/Hudl.FFmpeg/Settings/Preset.cs @@ -0,0 +1,29 @@ +using System; +using Hudl.FFmpeg.Attributes; +using Hudl.FFmpeg.Enums; +using Hudl.FFmpeg.Formatters; +using Hudl.FFmpeg.Resources.BaseTypes; +using Hudl.FFmpeg.Settings.Attributes; +using Hudl.FFmpeg.Settings.Interfaces; +using Hudl.FFmpeg.Validators; + +namespace Hudl.FFmpeg.Settings{ + + /// + /// Set Encoding Preset + /// + [ForStream(Type = typeof(VideoStream))] + [Setting(Name = "preset")] + public class Preset : ISetting + { + + public Preset(PresetType preset) + { + PresetType = preset; + } + + [SettingParameter(Formatter = typeof(EnumParameterFormatter))] + [Validate(typeof(NullOrWhitespaceValidator))] + public PresetType PresetType { get; set; } + } + } \ No newline at end of file From 3900c240a423602abbfc14691a1c73b10e913442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20B=C3=BChler?= Date: Thu, 10 Jan 2019 12:07:05 +0100 Subject: [PATCH 2/6] Animated Gif - add support for rgba and lavfi formats - add Gif tyep as Video - add Pattegen/Palleteuse filters for optimizing gif palettes - add 420p Format --- Hudl.FFmpeg/Enums/FormatType.cs | 2 ++ Hudl.FFmpeg/Enums/OverlayVideoFormatType.cs | 4 +++ Hudl.FFmpeg/Filters/Format.cs | 30 +++++++++++++++++++++ Hudl.FFmpeg/Filters/Palettegen.cs | 18 +++++++++++++ Hudl.FFmpeg/Filters/Paletteuse.cs | 18 +++++++++++++ Hudl.FFmpeg/Resources/Gif.cs | 22 +++++++++++++++ 6 files changed, 94 insertions(+) create mode 100644 Hudl.FFmpeg/Filters/Format.cs create mode 100644 Hudl.FFmpeg/Filters/Palettegen.cs create mode 100644 Hudl.FFmpeg/Filters/Paletteuse.cs create mode 100644 Hudl.FFmpeg/Resources/Gif.cs diff --git a/Hudl.FFmpeg/Enums/FormatType.cs b/Hudl.FFmpeg/Enums/FormatType.cs index 2f992e4..ccf3a33 100644 --- a/Hudl.FFmpeg/Enums/FormatType.cs +++ b/Hudl.FFmpeg/Enums/FormatType.cs @@ -9,5 +9,7 @@ public enum FormatType /// indicates the input format is a concatenation file. /// Concat + rgba, + lavfi } } \ No newline at end of file diff --git a/Hudl.FFmpeg/Enums/OverlayVideoFormatType.cs b/Hudl.FFmpeg/Enums/OverlayVideoFormatType.cs index e4a7222..8b97a1f 100644 --- a/Hudl.FFmpeg/Enums/OverlayVideoFormatType.cs +++ b/Hudl.FFmpeg/Enums/OverlayVideoFormatType.cs @@ -17,6 +17,10 @@ public enum OverlayVideoFormatType /// forces an RGB pixel output format /// Rgb = 2 + /// + /// forces a YUV420P pixel output format + /// + Yuv420P = 3 } } diff --git a/Hudl.FFmpeg/Filters/Format.cs b/Hudl.FFmpeg/Filters/Format.cs new file mode 100644 index 0000000..d7f398a --- /dev/null +++ b/Hudl.FFmpeg/Filters/Format.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Hudl.FFmpeg.Attributes; +using Hudl.FFmpeg.DataTypes; +using Hudl.FFmpeg.Enums; +using Hudl.FFmpeg.Filters.Attributes; +using Hudl.FFmpeg.Filters.Interfaces; +using Hudl.FFmpeg.Formatters; +using Hudl.FFmpeg.Resources; +using Hudl.FFmpeg.Resources.BaseTypes; + +namespace Hudl.FFmpeg.Filters +{ + /// + /// Formats the Video stream + /// + [ForStream(Type = typeof(VideoStream))] + [Filter(Name = "format", MinInputs = 1, MaxInputs = 1)] + public class Format :IFilter + { + public Format() + { + } + [FilterParameter( Formatter = typeof(EnumParameterFormatter))] + public PixelFormatType PixelFormat { get; set; } + } +} diff --git a/Hudl.FFmpeg/Filters/Palettegen.cs b/Hudl.FFmpeg/Filters/Palettegen.cs new file mode 100644 index 0000000..d1c317f --- /dev/null +++ b/Hudl.FFmpeg/Filters/Palettegen.cs @@ -0,0 +1,18 @@ +using System.Drawing; +using Hudl.FFmpeg.Attributes; +using Hudl.FFmpeg.Enums; +using Hudl.FFmpeg.Filters.Interfaces; +using Hudl.FFmpeg.Resources.BaseTypes; +using Hudl.FFmpeg.Filters.Attributes; + +namespace Hudl.FFmpeg.Filters +{ + /// + /// Filter that generates Palette file + /// + [ForStream(Type = typeof(VideoStream))] + [Filter(Name = "palettegen", MinInputs = 1, MaxInputs = 1)] + public class Palettegen : IFilter + { + } +} diff --git a/Hudl.FFmpeg/Filters/Paletteuse.cs b/Hudl.FFmpeg/Filters/Paletteuse.cs new file mode 100644 index 0000000..5590681 --- /dev/null +++ b/Hudl.FFmpeg/Filters/Paletteuse.cs @@ -0,0 +1,18 @@ +using System.Drawing; +using Hudl.FFmpeg.Attributes; +using Hudl.FFmpeg.Enums; +using Hudl.FFmpeg.Filters.Interfaces; +using Hudl.FFmpeg.Resources.BaseTypes; +using Hudl.FFmpeg.Filters.Attributes; + +namespace Hudl.FFmpeg.Filters +{ + /// + /// Filter that uses the Paletteuse file + /// + [ForStream(Type = typeof(VideoStream))] + [Filter(Name = "paletteuse", MinInputs = 2, MaxInputs = 2)] + public class Paletteuse : IFilter + { + } +} diff --git a/Hudl.FFmpeg/Resources/Gif.cs b/Hudl.FFmpeg/Resources/Gif.cs new file mode 100644 index 0000000..996593d --- /dev/null +++ b/Hudl.FFmpeg/Resources/Gif.cs @@ -0,0 +1,22 @@ +using Hudl.FFmpeg.Attributes; +using Hudl.FFmpeg.Resources.BaseTypes; +using Hudl.FFmpeg.Resources.Interfaces; + +namespace Hudl.FFmpeg.Resources +{ + [ContainsStream(Type = typeof(VideoStream))] + public class Gif : BaseContainer + { + private const string FileFormat = ".gif"; + + public Gif() + : base(FileFormat) + { + } + + protected override IContainer Clone() + { + return new Gif(); + } + } +} From 68f8264b8885d84fa7b35c0f1e697030a2c1a2bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20B=C3=BChler?= Date: Thu, 10 Jan 2019 12:12:19 +0100 Subject: [PATCH 3/6] add Curves filter, FrameRateInput (-framerate predeclared variant), fix FormattingUtility --- .../Formatters/Utility/FormattingUtility.cs | 2 +- Hudl.FFmpeg/Filters/Curves.cs | 32 +++++++++++++++++++ Hudl.FFmpeg/Settings/FrameRateInput.cs | 1 + Hudl.FFmpeg/Settings/FrameRateInputPre.cs | 30 +++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 Hudl.FFmpeg/Filters/Curves.cs create mode 100644 Hudl.FFmpeg/Settings/FrameRateInputPre.cs diff --git a/Hudl.FFmpeg.Core/Formatters/Utility/FormattingUtility.cs b/Hudl.FFmpeg.Core/Formatters/Utility/FormattingUtility.cs index 1bed0a0..f3d00bb 100644 --- a/Hudl.FFmpeg.Core/Formatters/Utility/FormattingUtility.cs +++ b/Hudl.FFmpeg.Core/Formatters/Utility/FormattingUtility.cs @@ -24,7 +24,7 @@ public static string Duration(TimeSpan timespan) timespan.Hours.ToString(CultureInfo.InvariantCulture).PadLeft(2, '0'), timespan.Minutes.ToString(CultureInfo.InvariantCulture).PadLeft(2, '0'), timespan.Seconds.ToString(CultureInfo.InvariantCulture).PadLeft(2, '0'), - timespan.Milliseconds.ToString(CultureInfo.InvariantCulture)); + timespan.Milliseconds.ToString(CultureInfo.InvariantCulture).PadLeft(3, '0')); } public static string Map(IStream stream, int index) diff --git a/Hudl.FFmpeg/Filters/Curves.cs b/Hudl.FFmpeg/Filters/Curves.cs new file mode 100644 index 0000000..15ccc15 --- /dev/null +++ b/Hudl.FFmpeg/Filters/Curves.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Hudl.FFmpeg.Attributes; +using Hudl.FFmpeg.Filters.Attributes; +using Hudl.FFmpeg.Filters.Interfaces; +using Hudl.FFmpeg.Resources.BaseTypes; + +namespace Hudl.FFmpeg.Filters +{ + /// + /// Apply color adjustments using curves. + /// + [ForStream(Type = typeof(VideoStream))] + [Filter(Name = "curves", MinInputs = 1, MaxInputs = 1)] + public class Curves : IFilter + { + public Curves() + { + } + public Curves(string expression) + : this() + { + Expression = expression; + } + + [FilterParameter] + public string Expression { get; set; } + } +} diff --git a/Hudl.FFmpeg/Settings/FrameRateInput.cs b/Hudl.FFmpeg/Settings/FrameRateInput.cs index ce9be48..662b796 100644 --- a/Hudl.FFmpeg/Settings/FrameRateInput.cs +++ b/Hudl.FFmpeg/Settings/FrameRateInput.cs @@ -8,6 +8,7 @@ namespace Hudl.FFmpeg.Settings { /// /// Set frame rate (Hz value, fraction or abbreviation). + /// This is not the same as the -framerate option used for some input formats like image2 or v4l2 (it used to be the same in older versions of FFmpeg). /// [ForStream(Type = typeof(VideoStream))] [Setting(Name = "r", ResourceType = SettingsCollectionResourceType.Input)] diff --git a/Hudl.FFmpeg/Settings/FrameRateInputPre.cs b/Hudl.FFmpeg/Settings/FrameRateInputPre.cs new file mode 100644 index 0000000..dd233de --- /dev/null +++ b/Hudl.FFmpeg/Settings/FrameRateInputPre.cs @@ -0,0 +1,30 @@ +using System; +using Hudl.FFmpeg.Attributes; +using Hudl.FFmpeg.Enums; +using Hudl.FFmpeg.Resources.BaseTypes; +using Hudl.FFmpeg.Settings.Attributes; +using Hudl.FFmpeg.Settings.BaseTypes; + +namespace Hudl.FFmpeg.Settings +{ + /// + /// Set frame rate (Hz value, fraction or abbreviation). + /// + [ForStream(Type = typeof(VideoStream))] + [Setting(Name = "framerate", IsPreDeclaration = true, ResourceType = SettingsCollectionResourceType.Input)] + public class FrameRateInput : BaseFrameRate + { + public FrameRateInput() + : base() + { + } + public FrameRateInput(double rate) + : base(rate) + { + } + + [SettingParameter] + [Validate(LogicalOperators.GreaterThan, 0)] + public double Rate { get; set; } + } +} From 849d60a2cf5c05760c5d50a0ba0eca832a7862eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20B=C3=BChler?= Date: Thu, 10 Jan 2019 12:40:35 +0100 Subject: [PATCH 4/6] fix build errors --- Hudl.FFmpeg/Enums/FormatType.cs | 2 +- Hudl.FFmpeg/Enums/OverlayVideoFormatType.cs | 2 +- Hudl.FFmpeg/Hudl.Ffmpeg.csproj | 5 ++++ Hudl.FFmpeg/Preset.cs | 29 +++++++++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 Hudl.FFmpeg/Preset.cs diff --git a/Hudl.FFmpeg/Enums/FormatType.cs b/Hudl.FFmpeg/Enums/FormatType.cs index ccf3a33..31d09a6 100644 --- a/Hudl.FFmpeg/Enums/FormatType.cs +++ b/Hudl.FFmpeg/Enums/FormatType.cs @@ -8,7 +8,7 @@ public enum FormatType /// /// indicates the input format is a concatenation file. /// - Concat + Concat, rgba, lavfi } diff --git a/Hudl.FFmpeg/Enums/OverlayVideoFormatType.cs b/Hudl.FFmpeg/Enums/OverlayVideoFormatType.cs index 8b97a1f..84bd68b 100644 --- a/Hudl.FFmpeg/Enums/OverlayVideoFormatType.cs +++ b/Hudl.FFmpeg/Enums/OverlayVideoFormatType.cs @@ -16,7 +16,7 @@ public enum OverlayVideoFormatType /// /// forces an RGB pixel output format /// - Rgb = 2 + Rgb = 2, /// /// forces a YUV420P pixel output format /// diff --git a/Hudl.FFmpeg/Hudl.Ffmpeg.csproj b/Hudl.FFmpeg/Hudl.Ffmpeg.csproj index 1588972..e9752fc 100644 --- a/Hudl.FFmpeg/Hudl.Ffmpeg.csproj +++ b/Hudl.FFmpeg/Hudl.Ffmpeg.csproj @@ -58,9 +58,12 @@ + + + @@ -100,9 +103,11 @@ + + diff --git a/Hudl.FFmpeg/Preset.cs b/Hudl.FFmpeg/Preset.cs new file mode 100644 index 0000000..a38b71b --- /dev/null +++ b/Hudl.FFmpeg/Preset.cs @@ -0,0 +1,29 @@ +using System; +using Hudl.FFmpeg.Attributes; +using Hudl.FFmpeg.Enums; +using Hudl.FFmpeg.Formatters; +using Hudl.FFmpeg.Resources.BaseTypes; +using Hudl.FFmpeg.Settings.Attributes; +using Hudl.FFmpeg.Settings.Interfaces; +using Hudl.FFmpeg.Validators; + +namespace Hudl.FFmpeg.Settings{ + + /// + /// Set Encoding Preset + /// + [ForStream(Type = typeof(VideoStream))] + [Setting(Name = "preset")] + public class Preset : ISetting + { + + public Preset(PresetType preset) + { + PresetType = preset; + } + + [SettingParameter(Formatter = typeof(EnumParameterFormatter))] + [Validate(typeof(NullOrWhitespaceValidator))] + public PresetType PresetType { get; set; } + } + } \ No newline at end of file From 141d83162851db0a45800e511dc427fb43646832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20B=C3=BChler?= Date: Thu, 10 Jan 2019 16:10:43 +0100 Subject: [PATCH 5/6] move preset to Settings dir --- Hudl.FFmpeg/Hudl.Ffmpeg.csproj | 2 +- Hudl.FFmpeg/Preset.cs | 29 ----------------------------- 2 files changed, 1 insertion(+), 30 deletions(-) delete mode 100644 Hudl.FFmpeg/Preset.cs diff --git a/Hudl.FFmpeg/Hudl.Ffmpeg.csproj b/Hudl.FFmpeg/Hudl.Ffmpeg.csproj index e9752fc..a94b9fb 100644 --- a/Hudl.FFmpeg/Hudl.Ffmpeg.csproj +++ b/Hudl.FFmpeg/Hudl.Ffmpeg.csproj @@ -103,7 +103,6 @@ - @@ -139,6 +138,7 @@ + diff --git a/Hudl.FFmpeg/Preset.cs b/Hudl.FFmpeg/Preset.cs deleted file mode 100644 index a38b71b..0000000 --- a/Hudl.FFmpeg/Preset.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using Hudl.FFmpeg.Attributes; -using Hudl.FFmpeg.Enums; -using Hudl.FFmpeg.Formatters; -using Hudl.FFmpeg.Resources.BaseTypes; -using Hudl.FFmpeg.Settings.Attributes; -using Hudl.FFmpeg.Settings.Interfaces; -using Hudl.FFmpeg.Validators; - -namespace Hudl.FFmpeg.Settings{ - - /// - /// Set Encoding Preset - /// - [ForStream(Type = typeof(VideoStream))] - [Setting(Name = "preset")] - public class Preset : ISetting - { - - public Preset(PresetType preset) - { - PresetType = preset; - } - - [SettingParameter(Formatter = typeof(EnumParameterFormatter))] - [Validate(typeof(NullOrWhitespaceValidator))] - public PresetType PresetType { get; set; } - } - } \ No newline at end of file From 8b32fe6fc3053aa8f93984f8e397e97cf8d91322 Mon Sep 17 00:00:00 2001 From: simon <78061+simonbuehler@users.noreply.github.com> Date: Wed, 18 May 2022 09:59:58 +0200 Subject: [PATCH 6/6] fix Naming --- Hudl.FFmpeg/Settings/FrameRateInputPre.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Hudl.FFmpeg/Settings/FrameRateInputPre.cs b/Hudl.FFmpeg/Settings/FrameRateInputPre.cs index dd233de..1ae1367 100644 --- a/Hudl.FFmpeg/Settings/FrameRateInputPre.cs +++ b/Hudl.FFmpeg/Settings/FrameRateInputPre.cs @@ -12,13 +12,13 @@ namespace Hudl.FFmpeg.Settings /// [ForStream(Type = typeof(VideoStream))] [Setting(Name = "framerate", IsPreDeclaration = true, ResourceType = SettingsCollectionResourceType.Input)] - public class FrameRateInput : BaseFrameRate + public class FrameRateInputPre : BaseFrameRate { - public FrameRateInput() + public FrameRateInputPre() : base() { } - public FrameRateInput(double rate) + public FrameRateInputPre(double rate) : base(rate) { }