mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.2 KiB
76 lines
2.2 KiB
using ErsatzTV.FFmpeg.Capabilities; |
|
using ErsatzTV.FFmpeg.Capabilities.Qsv; |
|
using ErsatzTV.FFmpeg.Format; |
|
|
|
namespace ErsatzTV.FFmpeg.GlobalOption.HardwareAcceleration; |
|
|
|
public class QsvHardwareAccelerationOption( |
|
Option<string> device, |
|
FFmpegCapability decodeCapability, |
|
QsvInitMode qsvInitMode) : GlobalOption |
|
{ |
|
// TODO: read this from ffmpeg output |
|
private readonly List<string> _supportedFFmpegFormats = |
|
[ |
|
FFmpegFormat.NV12, |
|
FFmpegFormat.P010LE |
|
]; |
|
|
|
public override string[] GlobalOptions |
|
{ |
|
get |
|
{ |
|
string[] initDevices = qsvInitMode switch |
|
{ |
|
QsvInitMode.None => [], |
|
QsvInitMode.Qsv => ["-init_hw_device", "qsv=hw", "-filter_hw_device", "hw"], |
|
QsvInitMode.D3d11Va => ["-init_hw_device", "d3d11va=hw:,vendor=0x8086", "-filter_hw_device", "hw"], |
|
_ => throw new NotSupportedException() |
|
}; |
|
|
|
var result = new List<string> |
|
{ |
|
"-hwaccel", "qsv", |
|
"-hwaccel_output_format", "qsv" |
|
}; |
|
|
|
if (decodeCapability is not FFmpegCapability.Hardware) |
|
{ |
|
result.Clear(); |
|
} |
|
|
|
if (OperatingSystem.IsLinux()) |
|
{ |
|
foreach (string qsvDevice in device) |
|
{ |
|
if (!string.IsNullOrWhiteSpace(qsvDevice)) |
|
{ |
|
result.AddRange(new[] { "-qsv_device", qsvDevice }); |
|
} |
|
} |
|
} |
|
|
|
result.AddRange(initDevices); |
|
|
|
return result.ToArray(); |
|
} |
|
} |
|
|
|
// qsv encoders want nv12 |
|
public override FrameState NextState(FrameState currentState) |
|
{ |
|
FrameState result = currentState; |
|
|
|
foreach (IPixelFormat pixelFormat in currentState.PixelFormat) |
|
{ |
|
if (_supportedFFmpegFormats.Contains(pixelFormat.FFmpegName)) |
|
{ |
|
return result; |
|
} |
|
|
|
return result with { PixelFormat = new PixelFormatNv12(pixelFormat.Name) }; |
|
} |
|
|
|
return result with { PixelFormat = new PixelFormatNv12(new PixelFormatUnknown().Name) }; |
|
} |
|
}
|
|
|