Speed up transcoding without overloading the VM, add bulk retry

- nice level 19 -> 10 (was the absolute lowest CPU priority) and cap
  ffmpeg to 6 threads on this 8-core host, leaving headroom for Mongo,
  the *arr stack, and the API itself instead of an unbounded encode.
- Add POST /transcode/queue/retry-failed to re-queue every failed/
  cancelled job at once; label the per-job Retry button with text
  (was icon-only) and clarify in the page copy that failed/cancelled
  jobs never delete the movie — retry just re-queues the same file.
This commit is contained in:
Myron Blair
2026-07-26 21:21:22 -05:00
parent c174ac60b1
commit 4e72f568f3
3 changed files with 33 additions and 6 deletions
+8 -2
View File
@@ -13,6 +13,11 @@ from typing import Optional, List, Tuple, Callable, Awaitable
logger = logging.getLogger("kino.transcode")
# Moderate priority (was 19, the absolute lowest) and a thread cap so an ABR encode can't
# starve the rest of the stack (Mongo, *arr apps, the API itself) on this 8-core host.
TRANSCODE_NICE = 10
TRANSCODE_THREADS = 6
async def probe_video(source: Path) -> Tuple[int, int]:
"""Return (width, height) using ffprobe; (0, 0) on failure."""
@@ -58,7 +63,7 @@ async def transcode_quick(source: Path, out_dir: Path, on_status: Callable[...,
return
out_dir.mkdir(parents=True, exist_ok=True)
cmd = [
"nice", "-n", "19",
"nice", "-n", str(TRANSCODE_NICE),
"ffmpeg", "-y", "-i", str(source),
"-c:v", "copy", "-c:a", "copy",
"-bsf:v", "h264_mp4toannexb",
@@ -88,13 +93,14 @@ 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", "19", "ffmpeg", "-y", "-i", str(source), "-filter_complex", filter_complex]
cmd: List[str] = ["nice", "-n", str(TRANSCODE_NICE), "ffmpeg", "-y", "-threads", str(TRANSCODE_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"-profile:v:{i}", "main",
f"-pix_fmt:v:{i}", "yuv420p",
f"-b:v:{i}", vb,