mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-12-16 19:15:44 +00:00
* Move PosterWithAudio to FFMpegCore
* Reduce windows only tests
* Update Directory.Build.props
* Create .editorconfig
* More cleanup
* Enable implicit usings
* Remove unused method
* Apply dotnet format
* Fix unused variable in AudioGateArgument
* Fix boolean conditions in AudioGateArgument
* Merge boolean conditions into pattern
* Use target-typed new
* Add linting to CI
* Add CUDA to HardwareAccelerationDevice enum
* Increase timeout for Video_Join_Image_Sequence
* Adjust Video_Join_Image_Sequence timeout
* Fix expected seconds in Video_Join_Image_Sequence
* Increase timeout for Video_TranscodeToMemory due to macos agents
Former-commit-id: f9f7161686
59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
namespace FFMpegCore.Arguments
|
|
{
|
|
/// <summary>
|
|
/// Drawtext video filter argument
|
|
/// </summary>
|
|
public class DrawTextArgument : IVideoFilterArgument
|
|
{
|
|
public readonly DrawTextOptions Options;
|
|
|
|
public DrawTextArgument(DrawTextOptions options)
|
|
{
|
|
Options = options;
|
|
}
|
|
|
|
public string Key { get; } = "drawtext";
|
|
public string Value => Options.TextInternal;
|
|
}
|
|
|
|
public class DrawTextOptions
|
|
{
|
|
public readonly string Text;
|
|
public readonly string Font;
|
|
public readonly List<(string key, string value)> Parameters;
|
|
|
|
public static DrawTextOptions Create(string text, string font)
|
|
{
|
|
return new DrawTextOptions(text, font, new List<(string, string)>());
|
|
}
|
|
public static DrawTextOptions Create(string text, string font, params (string key, string value)[] parameters)
|
|
{
|
|
return new DrawTextOptions(text, font, parameters);
|
|
}
|
|
|
|
internal string TextInternal => string.Join(":", new[] { ("text", Text), ("fontfile", Font) }.Concat(Parameters).Select(FormatArgumentPair));
|
|
|
|
private static string FormatArgumentPair((string key, string value) pair)
|
|
{
|
|
return $"{pair.key}={EncloseIfContainsSpace(pair.value)}";
|
|
}
|
|
|
|
private static string EncloseIfContainsSpace(string input)
|
|
{
|
|
return input.Contains(" ") ? $"'{input}'" : input;
|
|
}
|
|
|
|
private DrawTextOptions(string text, string font, IEnumerable<(string, string)> parameters)
|
|
{
|
|
Text = text;
|
|
Font = font;
|
|
Parameters = parameters.ToList();
|
|
}
|
|
|
|
public DrawTextOptions WithParameter(string key, string value)
|
|
{
|
|
Parameters.Add((key, value));
|
|
return this;
|
|
}
|
|
}
|
|
}
|