diff --git a/FFMpegCore.Test/ArgumentBuilderTest.cs b/FFMpegCore.Test/ArgumentBuilderTest.cs index 6421560..6c79d98 100644 --- a/FFMpegCore.Test/ArgumentBuilderTest.cs +++ b/FFMpegCore.Test/ArgumentBuilderTest.cs @@ -61,6 +61,19 @@ public void Builder_BuildString_BitStream() var str = FFMpegArguments.FromFileInput("input.mp4").OutputToFile("output.mp4", false, opt => opt.WithBitStreamFilter(Channel.Audio, Filter.H264_Mp4ToAnnexB)).Arguments; 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] public void Builder_BuildString_Concat() diff --git a/FFMpegCore/FFMpeg/Arguments/ForcePixelFormat.cs b/FFMpegCore/FFMpeg/Arguments/ForcePixelFormat.cs index 7614ae3..8402552 100644 --- a/FFMpegCore/FFMpeg/Arguments/ForcePixelFormat.cs +++ b/FFMpegCore/FFMpeg/Arguments/ForcePixelFormat.cs @@ -4,7 +4,7 @@ namespace FFMpegCore.Arguments { public class ForcePixelFormat : IArgument { - public string PixelFormat { get; private set; } + public string PixelFormat { get; } public string Text => $"-pix_fmt {PixelFormat}"; public ForcePixelFormat(string format) diff --git a/FFMpegCore/FFMpeg/Arguments/HardwareAccelerationArgument.cs b/FFMpegCore/FFMpeg/Arguments/HardwareAccelerationArgument.cs new file mode 100644 index 0000000..da4b9ee --- /dev/null +++ b/FFMpegCore/FFMpeg/Arguments/HardwareAccelerationArgument.cs @@ -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"; + } +} \ No newline at end of file diff --git a/FFMpegCore/FFMpeg/Enums/HardwareAccelerationDevice.cs b/FFMpegCore/FFMpeg/Enums/HardwareAccelerationDevice.cs new file mode 100644 index 0000000..1d92f53 --- /dev/null +++ b/FFMpegCore/FFMpeg/Enums/HardwareAccelerationDevice.cs @@ -0,0 +1,14 @@ +namespace FFMpegCore.Enums +{ + public enum HardwareAccelerationDevice + { + Auto, + D3D11VA, + DXVA2, + QSV, + CUVID, + VDPAU, + VAAPI, + LibMFX + } +} \ No newline at end of file diff --git a/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs b/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs index a50d370..e41f8ee 100644 --- a/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs +++ b/FFMpegCore/FFMpeg/FFMpegArgumentOptions.cs @@ -31,6 +31,7 @@ internal FFMpegArgumentOptions() { } public FFMpegArgumentOptions WithDuration(TimeSpan? duration) => WithArgument(new DurationArgument(duration)); public FFMpegArgumentOptions WithFastStart() => WithArgument(new FaststartArgument()); 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 UsingMultithreading(bool multithread) => WithArgument(new ThreadsArgument(multithread));