fix(transcode): make preset libx264-only + restore quality opt-in
Two issues with the 0.9.9 preset retune: 1. applyDefaults was filling Preset="veryfast" before ResolveEncoderProfile got to pick the latency-biased default, so the "superfast" change never reached users with a freshly-generated config.toml — only those who left the field empty saw it. 2. The configured preset was being passed through to every encoder. That's only valid for libx264 (ultrafast…veryslow); NVENC uses p1-p7 and rejects anything else, QSV uses its own subset. A user with NVENC + preset="veryfast" would have ffmpeg reject the argv. Now: - TranscodeConfig.Preset documented as libx264-only with the full range + advice on quality vs first-start latency. - Default in applyDefaults is empty (was "veryfast") so the engine fills in "superfast" on libx264. - ResolveEncoderProfile ignores configuredPreset for vendor encoders (NVENC sticks to p3, QSV to veryfast, VideoToolbox has no preset knob). Test cases updated to lock in this behaviour. Users who want better quality at slower first-play should set download.transcode.preset = "veryfast" (previous default) / "faster" / "fast" / "medium" in their config.toml.
This commit is contained in:
parent
3b8d77b496
commit
0f4ad67827
5 changed files with 72 additions and 20 deletions
|
|
@ -987,27 +987,31 @@ type EncoderProfile struct {
|
|||
// ResolveEncoderProfile mirrors the codec + preset selection inside
|
||||
// buildHLSFFmpegArgsAt so callers (registry, log lines, diagnostic
|
||||
// endpoints) can know what ffmpeg will be told to do without parsing argv.
|
||||
//
|
||||
// The configured preset is libx264-specific by vocabulary (ultrafast…
|
||||
// veryslow). Passing it through to NVENC / QSV would have ffmpeg reject
|
||||
// the argv (NVENC uses p1-p7, QSV uses its own subset). So vendor encoders
|
||||
// always use their hardcoded vendor preset and ignore configuredPreset.
|
||||
// VideoToolbox has no preset knob at all.
|
||||
func ResolveEncoderProfile(hw HWAccel, configuredPreset string) EncoderProfile {
|
||||
codec := hw.FFmpegVideoCodec("h264")
|
||||
preset := configuredPreset
|
||||
switch codec {
|
||||
case "libx264":
|
||||
preset := configuredPreset
|
||||
if preset == "" {
|
||||
preset = "superfast"
|
||||
}
|
||||
return EncoderProfile{Codec: codec, Preset: preset}
|
||||
case "h264_nvenc":
|
||||
if preset == "" {
|
||||
preset = "p3"
|
||||
}
|
||||
return EncoderProfile{Codec: codec, Preset: "p3"}
|
||||
case "h264_qsv":
|
||||
if preset == "" {
|
||||
preset = "veryfast"
|
||||
}
|
||||
return EncoderProfile{Codec: codec, Preset: "veryfast"}
|
||||
case "h264_videotoolbox":
|
||||
// No preset knob for VideoToolbox; the speed/quality dial is `-q:v`.
|
||||
preset = ""
|
||||
return EncoderProfile{Codec: codec, Preset: ""}
|
||||
}
|
||||
return EncoderProfile{Codec: codec, Preset: preset}
|
||||
// VAAPI + future codecs: no preset, vendor-specific knobs handled in argv.
|
||||
return EncoderProfile{Codec: codec, Preset: ""}
|
||||
}
|
||||
|
||||
// buildHLSFFmpegArgsAt returns the argv for an HLS encode that starts at the
|
||||
|
|
|
|||
|
|
@ -63,15 +63,23 @@ func TestResolveEncoderProfileDefaults(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestResolveEncoderProfileHonoursConfiguredPreset(t *testing.T) {
|
||||
// libx264 / NVENC / QSV all defer to the configured preset when set.
|
||||
// Only libx264 honours the configured preset — the libx264 vocabulary
|
||||
// (ultrafast…veryslow) doesn't apply to vendor encoders. NVENC has its
|
||||
// own p1-p7 scale; QSV uses a different subset; VideoToolbox has no
|
||||
// preset knob. Passing a libx264 preset to them would have ffmpeg reject
|
||||
// the argv, so ResolveEncoderProfile always falls back to the hardcoded
|
||||
// vendor preset for non-libx264 codecs.
|
||||
cases := []struct {
|
||||
hw HWAccel
|
||||
configured string
|
||||
wantPreset string
|
||||
}{
|
||||
{HWAccelNone, "ultrafast", "ultrafast"},
|
||||
{HWAccelNVENC, "p1", "p1"},
|
||||
{HWAccelQSV, "veryslow", "veryslow"},
|
||||
{HWAccelNone, "ultrafast", "ultrafast"}, // libx264 honours
|
||||
{HWAccelNone, "medium", "medium"}, // libx264 honours
|
||||
{HWAccelNVENC, "p1", "p3"}, // NVENC ignores, sticks to p3
|
||||
{HWAccelNVENC, "veryfast", "p3"}, // NVENC ignores libx264 vocab
|
||||
{HWAccelQSV, "veryslow", "veryfast"}, // QSV ignores, sticks to veryfast
|
||||
{HWAccelVideoToolbox, "veryfast", ""}, // VideoToolbox has no preset
|
||||
}
|
||||
for _, tc := range cases {
|
||||
got := ResolveEncoderProfile(tc.hw, tc.configured)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue