From 696b29c9e9d49e32bbdbececcdc1e7c615f45675 Mon Sep 17 00:00:00 2001 From: Jason Dove Date: Sat, 26 Feb 2022 18:45:05 -0600 Subject: [PATCH] fix videotoolbox acceleration with new transcoder (#658) * fix videotoolbox acceleration with new transcoder * cleanup --- ErsatzTV.FFmpeg/Decoder/AvailableDecoders.cs | 3 +++ .../Decoder/DecoderVideoToolbox.cs | 8 +++++++ ErsatzTV.FFmpeg/Filter/OverlayFilter.cs | 21 +------------------ .../Filter/WatermarkHardwareUploadFilter.cs | 5 ++++- .../VideoToolboxHardwareAccelerationOption.cs | 5 +++++ ErsatzTV.FFmpeg/PipelineBuilder.cs | 3 ++- 6 files changed, 23 insertions(+), 22 deletions(-) create mode 100644 ErsatzTV.FFmpeg/Decoder/DecoderVideoToolbox.cs diff --git a/ErsatzTV.FFmpeg/Decoder/AvailableDecoders.cs b/ErsatzTV.FFmpeg/Decoder/AvailableDecoders.cs index 5c3e0a1ad..4a17ed01d 100644 --- a/ErsatzTV.FFmpeg/Decoder/AvailableDecoders.cs +++ b/ErsatzTV.FFmpeg/Decoder/AvailableDecoders.cs @@ -41,6 +41,9 @@ public static class AvailableDecoders // vaapi should use implicit decoders (HardwareAccelerationMode.Vaapi, _, _) => new DecoderVaapi(), + // videotoolbox should use implicit decoders + (HardwareAccelerationMode.VideoToolbox, _, _) => new DecoderVideoToolbox(), + (_, VideoFormat.Hevc, _) => new DecoderHevc(), (_, VideoFormat.H264, _) => new DecoderH264(), (_, VideoFormat.Mpeg1Video, _) => new DecoderMpeg1Video(), diff --git a/ErsatzTV.FFmpeg/Decoder/DecoderVideoToolbox.cs b/ErsatzTV.FFmpeg/Decoder/DecoderVideoToolbox.cs new file mode 100644 index 000000000..f394d2d02 --- /dev/null +++ b/ErsatzTV.FFmpeg/Decoder/DecoderVideoToolbox.cs @@ -0,0 +1,8 @@ +namespace ErsatzTV.FFmpeg.Decoder; + +public class DecoderVideoToolbox : DecoderBase +{ + protected override FrameDataLocation OutputFrameDataLocation => FrameDataLocation.Software; + public override string Name => "implicit_videotoolbox"; + public override IList InputOptions(InputFile inputFile) => Array.Empty(); +} diff --git a/ErsatzTV.FFmpeg/Filter/OverlayFilter.cs b/ErsatzTV.FFmpeg/Filter/OverlayFilter.cs index 62dbe121d..eef2220f4 100644 --- a/ErsatzTV.FFmpeg/Filter/OverlayFilter.cs +++ b/ErsatzTV.FFmpeg/Filter/OverlayFilter.cs @@ -18,26 +18,7 @@ public class OverlayFilter : BaseFilter public override FrameState NextState(FrameState currentState) => currentState; - public override string Filter - { - get - { - string hwdownload = string.Empty; - if (_currentState.FrameDataLocation == FrameDataLocation.Hardware) - { - hwdownload = "hwdownload,"; - foreach (IPixelFormat pixelFormat in _currentState.PixelFormat) - { - if (pixelFormat.FFmpegName == FFmpegFormat.NV12) - { - hwdownload = "hwdownload,format=nv12,"; - } - } - } - - return $"{hwdownload}overlay={Position}"; - } - } + public override string Filter => $"overlay={Position}"; protected string Position { diff --git a/ErsatzTV.FFmpeg/Filter/WatermarkHardwareUploadFilter.cs b/ErsatzTV.FFmpeg/Filter/WatermarkHardwareUploadFilter.cs index 9b5e4becf..feab909b3 100644 --- a/ErsatzTV.FFmpeg/Filter/WatermarkHardwareUploadFilter.cs +++ b/ErsatzTV.FFmpeg/Filter/WatermarkHardwareUploadFilter.cs @@ -22,7 +22,10 @@ public class WatermarkHardwareUploadFilter : BaseFilter // leave vaapi in software since we don't (yet) use overlay_vaapi HardwareAccelerationMode.Vaapi when _currentState.FrameDataLocation == FrameDataLocation.Software => string.Empty, - + + // leave videotoolbox in software since we use a software overlay filter + HardwareAccelerationMode.VideoToolbox => string.Empty, + _ => "hwupload" }; } diff --git a/ErsatzTV.FFmpeg/Option/HardwareAcceleration/VideoToolboxHardwareAccelerationOption.cs b/ErsatzTV.FFmpeg/Option/HardwareAcceleration/VideoToolboxHardwareAccelerationOption.cs index 9f64d7644..94126a71a 100644 --- a/ErsatzTV.FFmpeg/Option/HardwareAcceleration/VideoToolboxHardwareAccelerationOption.cs +++ b/ErsatzTV.FFmpeg/Option/HardwareAcceleration/VideoToolboxHardwareAccelerationOption.cs @@ -3,4 +3,9 @@ public class VideoToolboxHardwareAccelerationOption : GlobalOption { public override IList GlobalOptions => new List { "-hwaccel", "videotoolbox" }; + + public override FrameState NextState(FrameState currentState) => currentState with + { + FrameDataLocation = FrameDataLocation.Software + }; } diff --git a/ErsatzTV.FFmpeg/PipelineBuilder.cs b/ErsatzTV.FFmpeg/PipelineBuilder.cs index 9ba323cd1..9b6984a87 100644 --- a/ErsatzTV.FFmpeg/PipelineBuilder.cs +++ b/ErsatzTV.FFmpeg/PipelineBuilder.cs @@ -443,7 +443,8 @@ public class PipelineBuilder foreach (WatermarkInputFile watermarkInputFile in _watermarkInputFile) { - // vaapi uses a software overlay, so we need to ensure the background is already in software + // vaapi and videotoolbox use a software overlay, so we need to ensure the background is already in software + // though videotoolbox uses software decoders, so no need to download for that if (ffmpegState.HardwareAccelerationMode == HardwareAccelerationMode.Vaapi) { var downloadFilter = new HardwareDownloadFilter(currentState);