Use bitrate-based quality presets for video encoding

Qualitative presets made Mediabunny use quantizer (CRF-like) encoding, but
hardware H.264 encoders commonly ignore the per-frame quantizer and fall
back to a very low default bitrate, producing files far smaller than the
preset implies. Passing preferBitrate makes the preset map to an explicit
bitrate so hardware and software paths agree.
This commit is contained in:
2026-09-17 20:45:47 -05:00
parent fed1e8bb5a
commit 038773e79e
+7 -1
View File
@@ -156,7 +156,13 @@ export async function optimizeVideo(
const outputWidth = even( const outputWidth = even(
Math.round(sourceWidth * (outputHeight / sourceHeight)), Math.round(sourceWidth * (outputHeight / sourceHeight)),
); );
const quality = new Quality(options.qualityLevel); // Prefer bitrate-based encoding: hardware encoders often ignore the
// per-frame quantizer that qualitative presets would otherwise use, which
// made results inconsistent (and sometimes tiny).
const quality = new Quality({
quality: options.qualityLevel,
preferBitrate: true,
});
const candidates: VideoCodec[] = const candidates: VideoCodec[] =
options.codec === "auto" ? CODEC_CANDIDATES[container] : [options.codec]; options.codec === "auto" ? CODEC_CANDIDATES[container] : [options.codec];
const preferences: ("prefer-hardware" | "no-preference")[] = const preferences: ("prefer-hardware" | "no-preference")[] =