diff --git a/backend/transcode.py b/backend/transcode.py index 5e2059f..a59e851 100644 --- a/backend/transcode.py +++ b/backend/transcode.py @@ -93,14 +93,19 @@ async def transcode_abr(source: Path, out_dir: Path, on_status: Callable[..., Aw fc_parts.append(f"[v{i}]scale=w=-2:h={h}[v{i}out]") filter_complex = ";".join(fc_parts) - cmd: List[str] = ["nice", "-n", str(TRANSCODE_NICE), "ffmpeg", "-y", "-threads", str(TRANSCODE_THREADS), "-i", str(source), "-filter_complex", filter_complex] + # 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 + # budget lets them all run near-full-tilt simultaneously and still saturate the host. + per_variant_threads = max(1, TRANSCODE_THREADS // n) + + cmd: List[str] = ["nice", "-n", str(TRANSCODE_NICE), "ffmpeg", "-y", "-threads", str(per_variant_threads), "-i", str(source), "-filter_complex", filter_complex] for i, (_h, vb, maxr, buf, _ab) in enumerate(variants): cmd += [ "-map", f"[v{i}out]", f"-c:v:{i}", "libx264", f"-preset:v:{i}", "veryfast", - f"-threads:v:{i}", str(TRANSCODE_THREADS), + f"-threads:v:{i}", str(per_variant_threads), f"-profile:v:{i}", "main", f"-pix_fmt:v:{i}", "yuv420p", f"-b:v:{i}", vb,