mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
parent
c690817135
commit
12e031dfb3
5 changed files with 55 additions and 39 deletions
|
@ -192,6 +192,17 @@ public void Builder_BuildString_Transpose()
|
|||
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]
|
||||
public void Builder_BuildString_TransposeScale()
|
||||
{
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
32
FFMpegCore/FFMpeg/Arguments/SetMirroringArgument.cs
Normal file
32
FFMpegCore/FFMpeg/Arguments/SetMirroringArgument.cs
Normal 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))
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,12 +17,20 @@ public VideoFiltersArgument(VideoFilterOptions options)
|
|||
|
||||
public string Text => GetText();
|
||||
|
||||
public string GetText()
|
||||
private string GetText()
|
||||
{
|
||||
if (!Options.Arguments.Any())
|
||||
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(Size size) => WithArgument(new ScaleArgument(size));
|
||||
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));
|
||||
|
||||
private VideoFilterOptions WithArgument(IVideoFilterArgument argument)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
namespace FFMpegCore.Enums
|
||||
{
|
||||
public enum Mirror
|
||||
public enum Mirroring
|
||||
{
|
||||
Vertical,
|
||||
Horizontal
|
Loading…
Reference in a new issue