SHA256
Refactor Encoder Detection
This commit is contained in:
3 files changed
+159
-57
No files matched your search
+8
-19
@@ -25,15 +25,6 @@ namespace ADOFAIRenderer.Util
|
||||
// ReSharper disable once InconsistentNaming
|
||||
private const string AMDPattern =
|
||||
@"^AMD Radeon RX [0-9]+(?> XT)?$";
|
||||
|
||||
private static readonly Dictionary<Codec, List<(GPUVendor, string)>> CodecMap = new()
|
||||
{
|
||||
[Codec.H264] = new List<(GPUVendor, string)> { (GPUVendor.NVIDIA, "h264_nvenc"), (GPUVendor.Intel, "h264_qsv"), (GPUVendor.AMD, "h264_amf"), (GPUVendor.Apple, "h264_videotoolbox"), (GPUVendor.Unknown, "libx264") },
|
||||
[Codec.H265] = new List<(GPUVendor, string)> { (GPUVendor.NVIDIA, "hevc_nvenc"), (GPUVendor.Intel, "hevc_qsv"), (GPUVendor.AMD, "hevc_amf"), (GPUVendor.Apple, "hevc_videotoolbox"), (GPUVendor.Unknown, "libx265") },
|
||||
[Codec.VP9] = new List<(GPUVendor, string)> { (GPUVendor.NVIDIA, "vp9_nvenc"), (GPUVendor.Intel, "vp9_qsv"), (GPUVendor.Unknown, "libvpx-vp9") },
|
||||
[Codec.AV1] = new List<(GPUVendor, string)> { (GPUVendor.NVIDIA, "av1_nvenc"), (GPUVendor.Intel, "av1_qsv"), (GPUVendor.AMD, "av1_amf"), (GPUVendor.Unknown, "libsvtav1"), (GPUVendor.Unknown, "libaom-av1") },
|
||||
[Codec.VVC] = new List<(GPUVendor, string)> { (GPUVendor.Unknown, "libvvenc") }
|
||||
};
|
||||
|
||||
private static GPUVendor _cachedVendor = GPUVendor.Unknown;
|
||||
private static bool _hasCachedVendor;
|
||||
@@ -137,24 +128,22 @@ namespace ADOFAIRenderer.Util
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<string> GetPrioritizedEncoderCandidates(Codec codec, bool forceSoftware = false)
|
||||
public static List<VideoEncoder> GetPrioritizedEncoders(Codec codec, bool forceSoftware = false)
|
||||
{
|
||||
if (!CodecMap.TryGetValue(codec, out var list)) return new List<string>();
|
||||
|
||||
var prioritized = new List<string>();
|
||||
var encoders = VideoEncoder.All.Where(e => e.Codec == codec).ToList();
|
||||
if (forceSoftware)
|
||||
{
|
||||
prioritized.AddRange(from item in list where item.Item1 == GPUVendor.Unknown select item.Item2);
|
||||
return prioritized;
|
||||
return encoders.Where(e => !e.IsHardware).ToList();
|
||||
}
|
||||
|
||||
var vendor = GetActiveGPUVendor();
|
||||
var others = new List<string>();
|
||||
var prioritized = new List<VideoEncoder>();
|
||||
var others = new List<VideoEncoder>();
|
||||
|
||||
foreach (var item in list)
|
||||
foreach (var item in encoders)
|
||||
{
|
||||
if (item.Item1 == vendor) prioritized.Add(item.Item2);
|
||||
else others.Add(item.Item2);
|
||||
if (item.Vendor == vendor) prioritized.Add(item);
|
||||
else others.Add(item);
|
||||
}
|
||||
|
||||
prioritized.AddRange(others);
|
||||
|
||||
Reference in new issue
Block a user