Browse Source

fix videotoolbox acceleration with new transcoder (#658)

* fix videotoolbox acceleration with new transcoder

* cleanup
pull/659/head
Jason Dove 4 years ago committed by GitHub
parent
commit
696b29c9e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      ErsatzTV.FFmpeg/Decoder/AvailableDecoders.cs
  2. 8
      ErsatzTV.FFmpeg/Decoder/DecoderVideoToolbox.cs
  3. 21
      ErsatzTV.FFmpeg/Filter/OverlayFilter.cs
  4. 5
      ErsatzTV.FFmpeg/Filter/WatermarkHardwareUploadFilter.cs
  5. 5
      ErsatzTV.FFmpeg/Option/HardwareAcceleration/VideoToolboxHardwareAccelerationOption.cs
  6. 3
      ErsatzTV.FFmpeg/PipelineBuilder.cs

3
ErsatzTV.FFmpeg/Decoder/AvailableDecoders.cs

@ -41,6 +41,9 @@ public static class AvailableDecoders
// vaapi should use implicit decoders // vaapi should use implicit decoders
(HardwareAccelerationMode.Vaapi, _, _) => new DecoderVaapi(), (HardwareAccelerationMode.Vaapi, _, _) => new DecoderVaapi(),
// videotoolbox should use implicit decoders
(HardwareAccelerationMode.VideoToolbox, _, _) => new DecoderVideoToolbox(),
(_, VideoFormat.Hevc, _) => new DecoderHevc(), (_, VideoFormat.Hevc, _) => new DecoderHevc(),
(_, VideoFormat.H264, _) => new DecoderH264(), (_, VideoFormat.H264, _) => new DecoderH264(),
(_, VideoFormat.Mpeg1Video, _) => new DecoderMpeg1Video(), (_, VideoFormat.Mpeg1Video, _) => new DecoderMpeg1Video(),

8
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<string> InputOptions(InputFile inputFile) => Array.Empty<string>();
}

21
ErsatzTV.FFmpeg/Filter/OverlayFilter.cs

@ -18,26 +18,7 @@ public class OverlayFilter : BaseFilter
public override FrameState NextState(FrameState currentState) => currentState; public override FrameState NextState(FrameState currentState) => currentState;
public override string Filter public override string Filter => $"overlay={Position}";
{
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}";
}
}
protected string Position protected string Position
{ {

5
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 // leave vaapi in software since we don't (yet) use overlay_vaapi
HardwareAccelerationMode.Vaapi when _currentState.FrameDataLocation == FrameDataLocation.Software => HardwareAccelerationMode.Vaapi when _currentState.FrameDataLocation == FrameDataLocation.Software =>
string.Empty, string.Empty,
// leave videotoolbox in software since we use a software overlay filter
HardwareAccelerationMode.VideoToolbox => string.Empty,
_ => "hwupload" _ => "hwupload"
}; };
} }

5
ErsatzTV.FFmpeg/Option/HardwareAcceleration/VideoToolboxHardwareAccelerationOption.cs

@ -3,4 +3,9 @@
public class VideoToolboxHardwareAccelerationOption : GlobalOption public class VideoToolboxHardwareAccelerationOption : GlobalOption
{ {
public override IList<string> GlobalOptions => new List<string> { "-hwaccel", "videotoolbox" }; public override IList<string> GlobalOptions => new List<string> { "-hwaccel", "videotoolbox" };
public override FrameState NextState(FrameState currentState) => currentState with
{
FrameDataLocation = FrameDataLocation.Software
};
} }

3
ErsatzTV.FFmpeg/PipelineBuilder.cs

@ -443,7 +443,8 @@ public class PipelineBuilder
foreach (WatermarkInputFile watermarkInputFile in _watermarkInputFile) 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) if (ffmpegState.HardwareAccelerationMode == HardwareAccelerationMode.Vaapi)
{ {
var downloadFilter = new HardwareDownloadFilter(currentState); var downloadFilter = new HardwareDownloadFilter(currentState);

Loading…
Cancel
Save