36 lines
1.3 KiB
C#
36 lines
1.3 KiB
C#
namespace ytLive.Services.Encoder;
|
|
|
|
/// <summary>
|
|
/// Picks the best available H.264 encoder from ffmpeg's <c>-encoders</c> listing,
|
|
/// honoring the license posture (no GPL libx264): hardware NVENC → QSV → AMF, then
|
|
/// the OpenH264 software fallback. Pure parser — the <c>-encoders</c> probe output is
|
|
/// fetched by the encoder via an <see cref="IEncoderProcess"/> and fed here.
|
|
/// </summary>
|
|
public static class FfmpegEncoderPicker
|
|
{
|
|
/// <summary>Preference order, best first. All ship in the pinned BtbN lgpl-shared build.</summary>
|
|
public static readonly string[] Preference =
|
|
[
|
|
"h264_nvenc",
|
|
"h264_qsv",
|
|
"h264_amf",
|
|
"libopenh264",
|
|
];
|
|
|
|
/// <summary>
|
|
/// First <see cref="Preference"/> entry present in the probe output, or the
|
|
/// software fallback (which the pinned build always contains) if none matched.
|
|
/// Never returns libx264 — it is GPL and would contaminate the paid product.
|
|
/// </summary>
|
|
public static string Pick(string probeOutput)
|
|
{
|
|
var available = probeOutput.Split('\n');
|
|
foreach (var name in Preference)
|
|
{
|
|
if (available.Any(line => line.Contains(name, StringComparison.Ordinal)))
|
|
return name;
|
|
}
|
|
return Preference[^1];
|
|
}
|
|
}
|