Fixes, renames and missing stuff

Former-commit-id: 27a2219b8e
This commit is contained in:
Malte Rosenbjerg 2021-05-14 01:02:00 +02:00
parent c690817135
commit 12e031dfb3
5 changed files with 55 additions and 39 deletions

View file

@ -192,6 +192,17 @@ public void Builder_BuildString_Transpose()
Assert.AreEqual("-i \"input.mp4\" -vf \"transpose=2\" \"output.mp4\"", str); Assert.AreEqual("-i \"input.mp4\" -vf \"transpose=2\" \"output.mp4\"", str);
} }
[TestMethod]
public void Builder_BuildString_Mirroring()
{
var str = FFMpegArguments.FromFileInput("input.mp4")
.OutputToFile("output.mp4", false, opt => opt
.WithVideoFilters(filterOptions => filterOptions
.Mirror(Mirroring.Horizontal)))
.Arguments;
Assert.AreEqual("-i \"input.mp4\" -vf \"hflip\" \"output.mp4\"", str);
}
[TestMethod] [TestMethod]
public void Builder_BuildString_TransposeScale() public void Builder_BuildString_TransposeScale()
{ {

View file

@ -1,36 +0,0 @@
using FFMpegCore.Enums;
using System;
using System.Collections.Generic;
using System.Text;
namespace FFMpegCore.Arguments
{
public class SetMirrorVideo : IVideoFilterArgument
{
public SetMirrorVideo(Mirror value)
{
_value = value;
}
public Mirror _value { get; set; }
public string Key => string.Empty;
public string Value
{
get
{
switch (_value)
{
case Mirror.Horizontal:
return "hflip";
case Mirror.Vertical:
return "vflip";
default:
throw new ArgumentOutOfRangeException("SetMirrorVideo: argument not found");
}
}
}
}
}

View file

@ -0,0 +1,32 @@
using FFMpegCore.Enums;
using System;
using System.Collections.Generic;
using System.Text;
namespace FFMpegCore.Arguments
{
public class SetMirroringArgument : IVideoFilterArgument
{
public SetMirroringArgument(Mirroring mirroring)
{
Mirroring = mirroring;
}
public Mirroring Mirroring { get; set; }
public string Key => string.Empty;
public string Value
{
get
{
return Mirroring switch
{
Mirroring.Horizontal => "hflip",
Mirroring.Vertical => "vflip",
_ => throw new ArgumentOutOfRangeException(nameof(Mirroring))
};
}
}
}
}

View file

@ -17,12 +17,20 @@ public VideoFiltersArgument(VideoFilterOptions options)
public string Text => GetText(); public string Text => GetText();
public string GetText() private string GetText()
{ {
if (!Options.Arguments.Any()) if (!Options.Arguments.Any())
throw new FFMpegArgumentException("No video-filter arguments provided"); throw new FFMpegArgumentException("No video-filter arguments provided");
return $"-vf \"{string.Join(", ", Options.Arguments.Where(arg => !string.IsNullOrEmpty(arg.Value)).Select(arg => $"{arg.Key}={arg.Value.Replace(",", "\\,")}"))}\""; var arguments = Options.Arguments
.Where(arg => !string.IsNullOrEmpty(arg.Value))
.Select(arg =>
{
var escapedValue = arg.Value.Replace(",", "\\,");
return string.IsNullOrEmpty(arg.Key) ? escapedValue : $"{arg.Key}={escapedValue}";
});
return $"-vf \"{string.Join(", ", arguments)}\"";
} }
} }
@ -40,6 +48,7 @@ public class VideoFilterOptions
public VideoFilterOptions Scale(int width, int height) => WithArgument(new ScaleArgument(width, height)); public VideoFilterOptions Scale(int width, int height) => WithArgument(new ScaleArgument(width, height));
public VideoFilterOptions Scale(Size size) => WithArgument(new ScaleArgument(size)); public VideoFilterOptions Scale(Size size) => WithArgument(new ScaleArgument(size));
public VideoFilterOptions Transpose(Transposition transposition) => WithArgument(new TransposeArgument(transposition)); public VideoFilterOptions Transpose(Transposition transposition) => WithArgument(new TransposeArgument(transposition));
public VideoFilterOptions Mirror(Mirroring mirroring) => WithArgument(new SetMirroringArgument(mirroring));
public VideoFilterOptions DrawText(DrawTextOptions drawTextOptions) => WithArgument(new DrawTextArgument(drawTextOptions)); public VideoFilterOptions DrawText(DrawTextOptions drawTextOptions) => WithArgument(new DrawTextArgument(drawTextOptions));
private VideoFilterOptions WithArgument(IVideoFilterArgument argument) private VideoFilterOptions WithArgument(IVideoFilterArgument argument)

View file

@ -1,6 +1,6 @@
namespace FFMpegCore.Enums namespace FFMpegCore.Enums
{ {
public enum Mirror public enum Mirroring
{ {
Vertical, Vertical,
Horizontal Horizontal