Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add preset support / animated gif #96

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion Hudl.FFmpeg.Core/Formatters/Utility/FormattingUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion Hudl.FFmpeg/Enums/FormatType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public enum FormatType
/// <summary>
/// indicates the input format is a concatenation file.
/// </summary>
Concat
Concat,
rgba,
lavfi
}
}
6 changes: 5 additions & 1 deletion Hudl.FFmpeg/Enums/OverlayVideoFormatType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ public enum OverlayVideoFormatType
/// <summary>
/// forces an RGB pixel output format
/// </summary>
Rgb = 2
Rgb = 2,
/// <summary>
/// forces a YUV420P pixel output format
/// </summary>
Yuv420P = 3
}

}
25 changes: 25 additions & 0 deletions Hudl.FFmpeg/Enums/PresetType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Hudl.FFmpeg.Enums
{

/// <summary>
/// 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
/// </summary>
public enum PresetType
{
ultrafast,
superfast,
veryfast,
faster,
fast,
medium,
slow,
slower,
veryslow,
placebo
}
}
32 changes: 32 additions & 0 deletions Hudl.FFmpeg/Filters/Curves.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Apply color adjustments using curves.
/// </summary>
[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; }
}
}
30 changes: 30 additions & 0 deletions Hudl.FFmpeg/Filters/Format.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Formats the Video stream
/// </summary>
[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; }
}
}
18 changes: 18 additions & 0 deletions Hudl.FFmpeg/Filters/Palettegen.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Filter that generates Palette file
/// </summary>
[ForStream(Type = typeof(VideoStream))]
[Filter(Name = "palettegen", MinInputs = 1, MaxInputs = 1)]
public class Palettegen : IFilter
{
}
}
18 changes: 18 additions & 0 deletions Hudl.FFmpeg/Filters/Paletteuse.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Filter that uses the Paletteuse file
/// </summary>
[ForStream(Type = typeof(VideoStream))]
[Filter(Name = "paletteuse", MinInputs = 2, MaxInputs = 2)]
public class Paletteuse : IFilter
{
}
}
22 changes: 22 additions & 0 deletions Hudl.FFmpeg/Resources/Gif.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
1 change: 1 addition & 0 deletions Hudl.FFmpeg/Settings/FrameRateInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Hudl.FFmpeg.Settings
{
/// <summary>
/// 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).
/// </summary>
[ForStream(Type = typeof(VideoStream))]
[Setting(Name = "r", ResourceType = SettingsCollectionResourceType.Input)]
Expand Down
30 changes: 30 additions & 0 deletions Hudl.FFmpeg/Settings/FrameRateInputPre.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Set frame rate (Hz value, fraction or abbreviation).
/// </summary>
[ForStream(Type = typeof(VideoStream))]
[Setting(Name = "framerate", IsPreDeclaration = true, ResourceType = SettingsCollectionResourceType.Input)]
public class FrameRateInputPre : BaseFrameRate
{
public FrameRateInputPre()
: base()
{
}
public FrameRateInputPre(double rate)
: base(rate)
{
}

[SettingParameter]
[Validate(LogicalOperators.GreaterThan, 0)]
public double Rate { get; set; }
}
}
29 changes: 29 additions & 0 deletions Hudl.FFmpeg/Settings/Preset.cs
Original file line number Diff line number Diff line change
@@ -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{

/// <summary>
/// Set Encoding Preset
/// </summary>
[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; }
}
}