mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
parent
62e0a55045
commit
e24b652695
4 changed files with 67 additions and 4 deletions
|
@ -3,6 +3,7 @@
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using FFMpegCore.FFMPEG;
|
||||||
|
|
||||||
namespace FFMpegCore.Test
|
namespace FFMpegCore.Test
|
||||||
{
|
{
|
||||||
|
@ -174,6 +175,37 @@ public void Builder_BuildString_Speed()
|
||||||
Assert.AreEqual(str, "-i \"input.mp4\" -preset fast \"output.mp4\"");
|
Assert.AreEqual(str, "-i \"input.mp4\" -preset fast \"output.mp4\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Builder_BuildString_DrawtextFilter()
|
||||||
|
{
|
||||||
|
|
||||||
|
var container = new ArgumentContainer
|
||||||
|
{
|
||||||
|
new InputArgument("input.mp4"),
|
||||||
|
new DrawTextArgument("Stack Overflow", "/path/to/font.ttf",
|
||||||
|
("fontcolor", "white"),
|
||||||
|
("fontsize", "24"),
|
||||||
|
("box", "1"),
|
||||||
|
("boxcolor", "black@0.5"),
|
||||||
|
("boxborderw", "5"),
|
||||||
|
("x", "(w-text_w)/2"),
|
||||||
|
("y", "(h-text_h)/2")),
|
||||||
|
new OutputArgument("output.mp4")
|
||||||
|
};
|
||||||
|
var result = new FFMpeg().Convert(container);
|
||||||
|
|
||||||
|
var str = GetArgumentsString(new DrawTextArgument("Stack Overflow", "/path/to/font.ttf",
|
||||||
|
("fontcolor", "white"),
|
||||||
|
("fontsize", "24"),
|
||||||
|
("box", "1"),
|
||||||
|
("boxcolor", "black@0.5"),
|
||||||
|
("boxborderw", "5"),
|
||||||
|
("x", "(w-text_w)/2"),
|
||||||
|
("y", "(h-text_h)/2")));
|
||||||
|
|
||||||
|
Assert.AreEqual("-i \"input.mp4\" -vf drawtext=\"text='Stack Overflow': fontfile=/path/to/font.ttf: fontcolor=white: fontsize=24: box=1: boxcolor=black@0.5: boxborderw=5: x=(w-text_w)/2: y=(h-text_h)/2\" \"output.mp4\"", str);
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Builder_BuildString_StartNumber()
|
public void Builder_BuildString_StartNumber()
|
||||||
{
|
{
|
||||||
|
@ -186,7 +218,7 @@ public void Builder_BuildString_StartNumber()
|
||||||
public void Builder_BuildString_Threads_1()
|
public void Builder_BuildString_Threads_1()
|
||||||
{
|
{
|
||||||
var str = GetArgumentsString(new ThreadsArgument(50));
|
var str = GetArgumentsString(new ThreadsArgument(50));
|
||||||
|
|
||||||
Assert.AreEqual(str, "-i \"input.mp4\" -threads 50 \"output.mp4\"");
|
Assert.AreEqual(str, "-i \"input.mp4\" -threads 50 \"output.mp4\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
31
FFMpegCore/FFMPEG/Argument/Atoms/DrawTextArgument.cs
Normal file
31
FFMpegCore/FFMPEG/Argument/Atoms/DrawTextArgument.cs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace FFMpegCore.FFMPEG.Argument
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Drawtext video filter argument
|
||||||
|
/// </summary>
|
||||||
|
public class DrawTextArgument : Argument<IEnumerable<(string key, string value)>>
|
||||||
|
{
|
||||||
|
public DrawTextArgument(string text, string fontPath, params (string, string)[] optionalArguments)
|
||||||
|
: base(new[] {("text", text), ("fontfile", fontPath)}.Concat(optionalArguments))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string GetStringValue()
|
||||||
|
{
|
||||||
|
return $"-vf drawtext=\"{string.Join(": ", Value.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -437,7 +437,7 @@ public VideoInfo ReplaceAudio(VideoInfo source, FileInfo audio, FileInfo output,
|
||||||
|
|
||||||
return new VideoInfo(output);
|
return new VideoInfo(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
public VideoInfo Convert(ArgumentContainer arguments)
|
public VideoInfo Convert(ArgumentContainer arguments)
|
||||||
{
|
{
|
||||||
var output = ((OutputArgument) arguments[typeof(OutputArgument)]).GetAsFileInfo();
|
var output = ((OutputArgument) arguments[typeof(OutputArgument)]).GetAsFileInfo();
|
||||||
|
|
|
@ -10,9 +10,9 @@
|
||||||
<Version>1.0.12</Version>
|
<Version>1.0.12</Version>
|
||||||
<AssemblyVersion>1.1.0.0</AssemblyVersion>
|
<AssemblyVersion>1.1.0.0</AssemblyVersion>
|
||||||
<FileVersion>1.1.0.0</FileVersion>
|
<FileVersion>1.1.0.0</FileVersion>
|
||||||
<PackageReleaseNotes>Minor fixes and refactoring</PackageReleaseNotes>
|
<PackageReleaseNotes>Add support for drawtext</PackageReleaseNotes>
|
||||||
<LangVersion>8</LangVersion>
|
<LangVersion>8</LangVersion>
|
||||||
<PackageVersion>1.1.0</PackageVersion>
|
<PackageVersion>1.2.0</PackageVersion>
|
||||||
<Authors>Vlad Jerca, Malte Rosenbjerg</Authors>
|
<Authors>Vlad Jerca, Malte Rosenbjerg</Authors>
|
||||||
<PackageTags>ffmpeg ffprobe convert video audio mediafile resize analyze muxing</PackageTags>
|
<PackageTags>ffmpeg ffprobe convert video audio mediafile resize analyze muxing</PackageTags>
|
||||||
<RepositoryType>GitHub</RepositoryType>
|
<RepositoryType>GitHub</RepositoryType>
|
||||||
|
|
Loading…
Reference in a new issue