mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
parent
2b93cb3495
commit
25c3cab7f1
3 changed files with 106 additions and 0 deletions
|
@ -495,5 +495,45 @@ public void Builder_BuildString_Audible_AAXC_Decryption()
|
||||||
|
|
||||||
Assert.AreEqual("-audible_key 123 -audible_iv 456 -i \"input.aaxc\" -map_metadata 0 -id3v2_version 3 -vn -c:a copy \"output.m4b\" -y", str);
|
Assert.AreEqual("-audible_key 123 -audible_iv 456 -i \"input.aaxc\" -map_metadata 0 -id3v2_version 3 -vn -c:a copy \"output.m4b\" -y", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Builder_BuildString_PadFilter()
|
||||||
|
{
|
||||||
|
var str = FFMpegArguments
|
||||||
|
.FromFileInput("input.mp4")
|
||||||
|
.OutputToFile("output.mp4", false, opt => opt
|
||||||
|
.WithVideoFilters(filterOptions => filterOptions
|
||||||
|
.Pad(PadOptions
|
||||||
|
.Create("max(iw,ih)", "ow")
|
||||||
|
.WithParameter("x", "(ow-iw)/2")
|
||||||
|
.WithParameter("y", "(oh-ih)/2")
|
||||||
|
.WithParameter("color", "violet")
|
||||||
|
.WithParameter("eval", "frame"))))
|
||||||
|
.Arguments;
|
||||||
|
|
||||||
|
Assert.AreEqual(
|
||||||
|
"-i \"input.mp4\" -vf \"pad=width=max(iw\\,ih):height=ow:x=(ow-iw)/2:y=(oh-ih)/2:color=violet:eval=frame\" \"output.mp4\"",
|
||||||
|
str);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Builder_BuildString_PadFilter_Alt()
|
||||||
|
{
|
||||||
|
var str = FFMpegArguments
|
||||||
|
.FromFileInput("input.mp4")
|
||||||
|
.OutputToFile("output.mp4", false, opt => opt
|
||||||
|
.WithVideoFilters(filterOptions => filterOptions
|
||||||
|
.Pad(PadOptions
|
||||||
|
.Create("4/3")
|
||||||
|
.WithParameter("x", "(ow-iw)/2")
|
||||||
|
.WithParameter("y", "(oh-ih)/2")
|
||||||
|
.WithParameter("color", "violet")
|
||||||
|
.WithParameter("eval", "frame"))))
|
||||||
|
.Arguments;
|
||||||
|
|
||||||
|
Assert.AreEqual(
|
||||||
|
"-i \"input.mp4\" -vf \"pad=aspect=4/3:x=(ow-iw)/2:y=(oh-ih)/2:color=violet:eval=frame\" \"output.mp4\"",
|
||||||
|
str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
65
FFMpegCore/FFMpeg/Arguments/PadArgument.cs
Normal file
65
FFMpegCore/FFMpeg/Arguments/PadArgument.cs
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -53,6 +53,7 @@ public class VideoFilterOptions
|
||||||
public VideoFilterOptions HardBurnSubtitle(SubtitleHardBurnOptions subtitleHardBurnOptions) => WithArgument(new SubtitleHardBurnArgument(subtitleHardBurnOptions));
|
public VideoFilterOptions HardBurnSubtitle(SubtitleHardBurnOptions subtitleHardBurnOptions) => WithArgument(new SubtitleHardBurnArgument(subtitleHardBurnOptions));
|
||||||
public VideoFilterOptions BlackDetect(double minimumDuration = 2.0, double pictureBlackRatioThreshold = 0.98, double pixelBlackThreshold = 0.1) => WithArgument(new BlackDetectArgument(minimumDuration, pictureBlackRatioThreshold, pixelBlackThreshold));
|
public VideoFilterOptions BlackDetect(double minimumDuration = 2.0, double pictureBlackRatioThreshold = 0.98, double pixelBlackThreshold = 0.1) => WithArgument(new BlackDetectArgument(minimumDuration, pictureBlackRatioThreshold, pixelBlackThreshold));
|
||||||
public VideoFilterOptions BlackFrame(int amount = 98, int threshold = 32) => WithArgument(new BlackFrameArgument(amount, threshold));
|
public VideoFilterOptions BlackFrame(int amount = 98, int threshold = 32) => WithArgument(new BlackFrameArgument(amount, threshold));
|
||||||
|
public VideoFilterOptions Pad(PadOptions padOptions) => WithArgument(new PadArgument(padOptions));
|
||||||
|
|
||||||
private VideoFilterOptions WithArgument(IVideoFilterArgument argument)
|
private VideoFilterOptions WithArgument(IVideoFilterArgument argument)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue