Add HardwareAccelerationArgument

This commit is contained in:
Malte Rosenbjerg 2020-10-24 23:33:44 +02:00
parent 010e9947e9
commit 5fb2305b5b
5 changed files with 47 additions and 1 deletions

View file

@ -62,6 +62,19 @@ public void Builder_BuildString_BitStream()
Assert.AreEqual("-i \"input.mp4\" -bsf:a h264_mp4toannexb \"output.mp4\"", str); Assert.AreEqual("-i \"input.mp4\" -bsf:a h264_mp4toannexb \"output.mp4\"", str);
} }
[TestMethod]
public void Builder_BuildString_HardwareAcceleration_Auto()
{
var str = FFMpegArguments.FromFileInput("input.mp4").OutputToFile("output.mp4", false, opt => opt.WithHardwareAcceleration()).Arguments;
Assert.AreEqual("-i \"input.mp4\" -hwaccel \"output.mp4\"", str);
}
[TestMethod]
public void Builder_BuildString_HardwareAcceleration_Specific()
{
var str = FFMpegArguments.FromFileInput("input.mp4").OutputToFile("output.mp4", false, opt => opt.WithHardwareAcceleration(HardwareAccelerationDevice.CUVID)).Arguments;
Assert.AreEqual("-i \"input.mp4\" -hwaccel cuvid \"output.mp4\"", str);
}
[TestMethod] [TestMethod]
public void Builder_BuildString_Concat() public void Builder_BuildString_Concat()
{ {

View file

@ -4,7 +4,7 @@ namespace FFMpegCore.Arguments
{ {
public class ForcePixelFormat : IArgument public class ForcePixelFormat : IArgument
{ {
public string PixelFormat { get; private set; } public string PixelFormat { get; }
public string Text => $"-pix_fmt {PixelFormat}"; public string Text => $"-pix_fmt {PixelFormat}";
public ForcePixelFormat(string format) public ForcePixelFormat(string format)

View file

@ -0,0 +1,18 @@
using FFMpegCore.Enums;
namespace FFMpegCore.Arguments
{
public class HardwareAccelerationArgument : IArgument
{
public HardwareAccelerationDevice HardwareAccelerationDevice { get; }
public HardwareAccelerationArgument(HardwareAccelerationDevice hardwareAccelerationDevice)
{
HardwareAccelerationDevice = hardwareAccelerationDevice;
}
public string Text => HardwareAccelerationDevice != HardwareAccelerationDevice.Auto
? $"-hwaccel {HardwareAccelerationDevice.ToString().ToLower()}"
: "-hwaccel";
}
}

View file

@ -0,0 +1,14 @@
namespace FFMpegCore.Enums
{
public enum HardwareAccelerationDevice
{
Auto,
D3D11VA,
DXVA2,
QSV,
CUVID,
VDPAU,
VAAPI,
LibMFX
}
}

View file

@ -31,6 +31,7 @@ internal FFMpegArgumentOptions() { }
public FFMpegArgumentOptions WithDuration(TimeSpan? duration) => WithArgument(new DurationArgument(duration)); public FFMpegArgumentOptions WithDuration(TimeSpan? duration) => WithArgument(new DurationArgument(duration));
public FFMpegArgumentOptions WithFastStart() => WithArgument(new FaststartArgument()); public FFMpegArgumentOptions WithFastStart() => WithArgument(new FaststartArgument());
public FFMpegArgumentOptions WithFrameOutputCount(int frames) => WithArgument(new FrameOutputCountArgument(frames)); public FFMpegArgumentOptions WithFrameOutputCount(int frames) => WithArgument(new FrameOutputCountArgument(frames));
public FFMpegArgumentOptions WithHardwareAcceleration(HardwareAccelerationDevice hardwareAccelerationDevice = HardwareAccelerationDevice.Auto) => WithArgument(new HardwareAccelerationArgument(hardwareAccelerationDevice));
public FFMpegArgumentOptions UsingShortest(bool shortest = true) => WithArgument(new ShortestArgument(shortest)); public FFMpegArgumentOptions UsingShortest(bool shortest = true) => WithArgument(new ShortestArgument(shortest));
public FFMpegArgumentOptions UsingMultithreading(bool multithread) => WithArgument(new ThreadsArgument(multithread)); public FFMpegArgumentOptions UsingMultithreading(bool multithread) => WithArgument(new ThreadsArgument(multithread));