-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #341 from glebmxyz/pad-video-filter
Add pad video filter
- Loading branch information
Showing
3 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using FFMpegCore.Extend; | ||
|
||
namespace FFMpegCore.Arguments | ||
{ | ||
public class PadArgument : IVideoFilterArgument | ||
{ | ||
private readonly PadOptions _options; | ||
|
||
public PadArgument(PadOptions options) | ||
{ | ||
_options = options; | ||
} | ||
|
||
public string Key => "pad"; | ||
public string Value => _options.TextInternal; | ||
|
||
} | ||
|
||
public class PadOptions | ||
{ | ||
public readonly Dictionary<string, string> Parameters = new Dictionary<string, string>(); | ||
|
||
internal string TextInternal => string.Join(":", Parameters.Select(parameter => parameter.FormatArgumentPair(true))); | ||
|
||
public static PadOptions Create(string? width, string? height) | ||
{ | ||
return new PadOptions(width, height); | ||
} | ||
|
||
public static PadOptions Create(string aspectRatio) | ||
{ | ||
return new PadOptions(aspectRatio); | ||
} | ||
|
||
public PadOptions WithParameter(string key, string value) | ||
{ | ||
Parameters.Add(key, value); | ||
return this; | ||
} | ||
|
||
private PadOptions(string? width, string? height) | ||
{ | ||
if (width == null && height == null) | ||
{ | ||
throw new Exception("At least one of the parameters must be not null"); | ||
} | ||
if (width != null) | ||
{ | ||
Parameters.Add("width", width); | ||
} | ||
if (height != null) | ||
{ | ||
Parameters.Add("height", height); | ||
} | ||
} | ||
|
||
private PadOptions(string aspectRatio) | ||
{ | ||
Parameters.Add("aspect", aspectRatio); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters