Skip to content

perf(ltx23): cap PyAV libx264 encode threads at 12#20

Merged
Johan-de-R merged 1 commit into
deep-main-v1.1.1-videogenfrom
johan/ltx23-pyav-x264-threads
Jul 9, 2026
Merged

perf(ltx23): cap PyAV libx264 encode threads at 12#20
Johan-de-R merged 1 commit into
deep-main-v1.1.1-videogenfrom
johan/ltx23-pyav-x264-threads

Conversation

@Johan-de-R

Copy link
Copy Markdown

What

The PyAV single-pass save path (_save_video_with_audio_single_pass) — the one we actually run on B200 (no ffmpeg on PATH → the ffmpeg-pipe path never executes) — set no threads option, so libx264 auto-detected all ~288 node cores and thrashed. PR #8's -threads 32 cap only ever applied to the dead ffmpeg-pipe path.

This adds a thread cap (default 12, env FASTVIDEO_X264_THREADS_PYAV) to the PyAV libx264 stream, by extending the existing PyAV scenecut patch (renamed pyav-scenecut.patchpyav-x264-tuning.patch since it now tunes both).

Data (isolated encode-only sweep, di-slc-46 B200, 121f 1080p, conversion excluded, 6 reps, median)

threads time threads time
1 1.020s 10 0.419s ← best
4 0.530s 12 0.445s
8 0.439s 16 0.637s ← worse
default (288) ~1.65s total (thrash) 32 0.674s

More threads do not help: x264 slice-threading on a single 1080p stream saturates ~10–12, then slice/sync overhead makes it slower. 12 is fastest AND well under a fair share — no noisy-neighbor tradeoff (going higher is strictly dominated). Even the ffmpeg-path's 32 is past the knee.

Net effect on the save is modest (~0.1s in the interleaved total; the ~1.5s color conversion still dominates — separate, bigger fix coming), but it's free and correct.

Verification

patch --fuzz=0 re-verified against pristine fastvideo source (reversed the old scenecut patch, dry-ran + applied the new one): applies clean, produces both FASTVIDEO_X264_SCENECUT and FASTVIDEO_X264_THREADS_PYAV. Deploys with the next image rebuild.

🤖 Generated with Claude Code

…> x264-tuning)

The PyAV single-pass save path (the one we actually run on B200 — no ffmpeg on
PATH) set no `threads` option, so libx264 auto-detected all ~288 node cores and
thrashed. PR #8's -threads cap only ever applied to the dead ffmpeg-pipe path.

Isolated encode-only sweep (di-slc-46 B200, 121f 1080p, conversion excluded,
6 reps median):
  threads=1   1.020s      threads=10  0.419s  <- sweet spot
  threads=4   0.530s      threads=12  0.445s
  threads=8   0.439s      threads=16  0.637s  <- worse past here
  threads=default(288)    1.65s total (thrash)  threads=32  0.674s
More threads do NOT help: x264 slice-threading on a single 1080p stream
saturates ~10-12, then slice/sync overhead makes it slower. 12 = fastest AND
well under a fair share (no noisy-neighbor tradeoff).

Extends the existing PyAV scenecut patch (renamed pyav-scenecut -> pyav-x264-tuning
since it now does both). Env-configurable via FASTVIDEO_X264_THREADS_PYAV (no
rebuild to change). Verified: applies --fuzz=0 to pristine fastvideo source.

Deploys with the next image rebuild.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Johan-de-R Johan-de-R changed the title ltx23: cap PyAV libx264 encode threads at 12 perf(ltx23): cap PyAV libx264 encode threads at 12 Jul 9, 2026
@github-actions github-actions Bot added the perf label Jul 9, 2026
@Johan-de-R Johan-de-R merged commit 0984fd3 into deep-main-v1.1.1-videogen Jul 9, 2026
12 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant