namespace ytLive.Services.Encoder;
///
/// Picks the best available H.264 encoder from ffmpeg's -encoders listing,
/// honoring the license posture (no GPL libx264): hardware NVENC → QSV → AMF, then
/// the OpenH264 software fallback. Pure parser — the -encoders probe output is
/// fetched by the encoder via an and fed here.
///
public static class FfmpegEncoderPicker
{
/// Preference order, best first. All ship in the pinned BtbN lgpl-shared build.
public static readonly string[] Preference =
[
"h264_nvenc",
"h264_qsv",
"h264_amf",
"libopenh264",
];
///
/// First 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.
///
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];
}
}