-
Notifications
You must be signed in to change notification settings - Fork 32
Creating Custom Settings
Hudl.FFmpeg is already packaged with support for many of the commonly used settings. Still if you find yourself in need of one that we have not included, you may create and implement your own project.
In Hudl.FFmpeg we use classes to represent settings. These classes are serialized to command strings at the time of rendering. In order to correctly serialize a setting we need to know a little bit about it. We can start by taking a simple setting such as c:v
, which is used for setting the codec used in the output stream. Let's start by stubbing out our class.
public class CodecVideo
{
public CodecVideo(string codec)
{
Codec = codec;
}
public string Codec { get; set; }
}
The ISetting
interface is what Hudl.FFmpeg uses to identify a class as a setting. All setting implementations must implement the ```ISetting interface in order to use them in production.
public class CodecVideo : ISetting
...
ForStream
is a class-level attribute used to tell Hudl.FFmpeg what kinds of streams the setting supports. This is done by passing the Type
of stream to expect. For example if I was to implement an audio only setting, such as c:a
, I would write [ForStream(typeof(AudioStream)]
. You may use multiple attributes if your setting supports both VideoStream
s and AudioStream
s.
Parameter | Type | Description |
---|---|---|
Type | Type | sets the type of stream that is allowed when using this setting. |
[ForStream(typeof(VideoStream)]
public class CodecVideo : ISetting
...
Setting
is a class-level attribute used in serialization and validation. It contains the following parameters
Parameter | Type | Description |
---|---|---|
Name | string | sets the ffmpeg name of the setting, this name is used in serialization. |
IsParameterless | bool | sets a boolean indicating if the setting contains a value or not. |
IsPreDeclaration | bool | sets a boolean indicating if the setting comes before the output or input declaration. |
IsMultipleAllowed | bool | sets a boolean indicating if multiple of this setting is allowed. |
ResourceType | SettingsCollectionResourceType | sets the type of setting that you are defining, input or output. |
[ForStream(typeof(VideoStream)]
[Setting(Name = "c:v")]
public class CodecVideo : ISetting
...
SettingParameter
is a property-level attribute used in serialization. It is used to dictate which properties make up the setting properties. It contains the following parameters
Parameter | Type | Description |
---|---|---|
Formatter | Type | sets a type of IFormatter that will be used to format the value object to string. |
...
[SettingParameter]
public string Codec { get; set; }
When you put it all together you get something that looks like this
[ForStream(Type = typeof(VideoStream))]
[Setting(Name = "c:v", MinInputs = 1, MaxInputs = 1)]
public class CodecVideo: ISetting
{
public CodecVideo()
{
}
public CodecVideo(string codec)
{
Codec = codec;
}
[SettingParameter]
public string Codec { get; set; }
}
Please contribute your custom settings to our project, if you need them then there is a good chance that someone else does too!