diff --git a/backend/transcode.py b/backend/transcode.py index 6ecf201..79a5668 100644 --- a/backend/transcode.py +++ b/backend/transcode.py @@ -64,13 +64,16 @@ ALL_VARIANTS = [ def variants_for_source(src_height: int) -> List[Tuple[int, str, str, str, str]]: - """Pick variants ≤ source height. Always include at least one (smallest).""" + """Pick up to 2 variants ≤ source height (the two highest applicable renditions — + ALL_VARIANTS is ordered highest-to-lowest, so slicing keeps the best pair). Capped at 2 + instead of the full ladder to roughly halve ABR encode time on this host's aging CPU, while + still giving a real high/low adaptive-bitrate pair for most connections.""" if src_height <= 0: return [ALL_VARIANTS[2]] # safe default 480p chosen = [v for v in ALL_VARIANTS if v[0] <= src_height] if not chosen: chosen = [ALL_VARIANTS[-1]] - return chosen + return chosen[:2] async def transcode_audio_fix(source: Path, out_dir: Path, on_status: Callable[..., Awaitable]) -> None: @@ -133,7 +136,7 @@ async def transcode_abr(source: Path, out_dir: Path, on_status: Callable[..., Aw filter_complex = ";".join(fc_parts) # Per-variant thread count, not the full cap each — x264 threads are set per encoder - # instance, so giving every one of the (up to 4) variants the full TRANSCODE_THREADS + # instance, so giving every one of the (up to 2) variants the full TRANSCODE_THREADS # budget lets them all run near-full-tilt simultaneously and still saturate the host. per_variant_threads = max(1, TRANSCODE_THREADS // n) @@ -143,7 +146,7 @@ async def transcode_abr(source: Path, out_dir: Path, on_status: Callable[..., Aw cmd += [ "-map", f"[v{i}out]", f"-c:v:{i}", "libx264", - f"-preset:v:{i}", "veryfast", + f"-preset:v:{i}", "superfast", f"-threads:v:{i}", str(per_variant_threads), f"-profile:v:{i}", "main", f"-pix_fmt:v:{i}", "yuv420p",