TASK 4 ship step 3: encoder + RTMP push — FFmpeg subprocess with probed H.264 picker, BGRA stdin feed, stderr health parsing, graceful stop — 122 tests passing, 0 warnings

This commit is contained in:
2026-08-12 20:32:24 -07:00
parent e494dce311
commit ba427e85e1
13 changed files with 891 additions and 62 deletions
+35
View File
@@ -0,0 +1,35 @@
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];
}
}