Files
ersatztv/ErsatzTV.FFmpeg/GlobalOption/HardwareAcceleration/QsvHardwareAccelerationOption.cs
T
timothy e170b2dc3c
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 4m4s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 5m17s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
fix(ffmpeg): align transcode pipelines with ffmpeg 8
refs #9
2026-07-01 19:37:51 +02:00

73 lines
2.0 KiB
C#

using ErsatzTV.FFmpeg.Capabilities;
using ErsatzTV.FFmpeg.Format;
namespace ErsatzTV.FFmpeg.GlobalOption.HardwareAcceleration;
public class QsvHardwareAccelerationOption(Option<string> device, FFmpegCapability decodeCapability) : GlobalOption
{
// TODO: read this from ffmpeg output
private readonly List<string> _supportedFFmpegFormats = new()
{
FFmpegFormat.NV12,
FFmpegFormat.P010LE
};
public override string[] GlobalOptions
{
get
{
var result = new List<string>
{
"-hwaccel", "qsv",
"-hwaccel_output_format", "qsv"
};
if (decodeCapability is not FFmpegCapability.Hardware)
{
result.Clear();
}
var deviceConfigured = false;
foreach (string qsvDevice in device)
{
if (!string.IsNullOrWhiteSpace(qsvDevice))
{
result.AddRange(
[
"-init_hw_device", $"vaapi=va:{qsvDevice}",
"-init_hw_device", "qsv=hw@va"
]);
deviceConfigured = true;
}
}
if (!deviceConfigured)
{
result.AddRange(["-init_hw_device", "qsv=hw"]);
}
result.AddRange(["-filter_hw_device", "hw"]);
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) };
}
}