mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-16 06:19:21 +00:00
fix(engine): use supported VideoToolbox quality options (#3687)
This commit is contained in:
@@ -107,6 +107,26 @@ export function getGpuEncoderName(encoder: GpuEncoder, codec: "h264" | "h265"):
|
||||
}
|
||||
}
|
||||
|
||||
export function buildVideoToolboxRateControlArgs(input: {
|
||||
bitrate?: string;
|
||||
width: number;
|
||||
height: number;
|
||||
fps: number;
|
||||
quality: number;
|
||||
}): string[] {
|
||||
if (input.bitrate) return ["-b:v", input.bitrate, "-allow_sw", "1"];
|
||||
|
||||
// VideoToolbox rejects FFmpeg's generic qscale path on supported macOS
|
||||
// builds. Derive a bitrate from pixel rate instead: the three CRF-shaped
|
||||
// quality tiers map to roughly 5M / 10M / 12M at 1080p24.
|
||||
const bitsPerPixel = input.quality <= 15 ? 0.24 : input.quality <= 18 ? 0.16 : 0.08;
|
||||
const megabitsPerSecond = Math.max(
|
||||
1,
|
||||
Math.round((input.width * input.height * input.fps * bitsPerPixel) / 1_000_000),
|
||||
);
|
||||
return ["-b:v", `${megabitsPerSecond}M`, "-allow_sw", "1"];
|
||||
}
|
||||
|
||||
// Minimum probe dimensions must clear every GPU encoder's hardware minimum.
|
||||
// NVIDIA data-center SKUs (L4/T4/A10/A100) reject frames below ~257px on
|
||||
// either dimension with "Frame Dimension less than the minimum supported
|
||||
@@ -137,6 +157,17 @@ export function getProbeArgs(encoder: ConcreteGpuEncoder): string[] {
|
||||
|
||||
args.push("-c:v", getGpuEncoderName(encoder, "h264"));
|
||||
|
||||
if (encoder === "videotoolbox") {
|
||||
args.push(
|
||||
...buildVideoToolboxRateControlArgs({
|
||||
width: GPU_PROBE_WIDTH,
|
||||
height: GPU_PROBE_HEIGHT,
|
||||
fps: 1,
|
||||
quality: 23,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (encoder === "amf") {
|
||||
args.push("-rc", "cqp", "-qp_i", "28", "-qp_p", "28");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user