Repository navigation
[diffusion] video: let requests choose the libx264 preset - #41797
Merged
Merged
Conversation
The MP4 encoder preset was a module constant (fast), so neither users nor benchmarks could change it: a latency-bound deployment could not trade file size for encode time, and a comparison could not pin the same encoder settings on every system. Requests now take x264_preset: in a JSON body, as a multipart form field, and as --x264-preset for sglang generate. It reaches all three libx264 call sites (the direct CUDA pipe, the single-pass video and audio encode, and the imageio fallback). Unset keeps fast, unknown values are rejected with HTTP 400, and grouped outputs must share it like output_compression. The HTTP /generate fallback save now also passes output_compression, which it used to drop. Co-Authored-By: Claude Opus 5.5 <[email protected]>
mickqian
requested review from
AgainstEntropy,
BBuf,
HaiShaw,
kevin-mii,
ping1jing2 and
yichiche
as code owners
September 30, 2026 01:25
Contributor
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
mickqian
requested review from
JustinTong0323,
niehen6174,
sogalin,
wisclmy0611 and
zijiexia
as code owners
September 30, 2026 01:25
Collaborator
Author
|
/tag-and-rerun-ci |
The WebUI save now forwards request.x264_preset, which the fake request in the lifecycle test did not have. Give it a non-default preset and check that it reaches save_outputs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 4, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The libx264 preset for MP4 output is a module constant (
X264_PRESET = "fast", from #38657), so it cannot be changed from a request, a CLI flag or an environment variable. Only CRF can be set, throughoutput_compression/output_quality. Two use cases need the preset:fast, while other engines are commonly run atultrafast.Modifications
SamplingParams.x264_preset(Noneby default, which keepsfast), validated against the libx264 preset list. Unknown values raise, so the video API answers them with HTTP 400.sglang generatetakes--x264-preset./v1/videosacceptsx264_presetin JSON bodies and as a multipart form field.save_outputscaller: the GPU worker (single and grouped outputs), the HTTP server's generate fallback,DiffGeneratorand the H3 web UI. Grouped outputs must share it, likeoutput_compression.output_compression, which it used to drop. With the default quality this changes nothing: both give CRF 25.Accuracy Tests
The default is unchanged, so existing outputs are byte-identical.
test_video_encode_preset.py::test_request_preset_reaches_the_encoder: real encodes withultrafastandslowthrough both save paths (a host tensor goes through imageio, a CUDA tensor through the direct pipe). libx264 writes the options it resolved into the file, and the test compares the preset-derived ones against a reference encode by ffmpeg.test_output_saving.py::test_x264_preset_reaches_every_video_save_path: the preset reaches the parallel direct save, the serial direct save, the imageio fallback and the single-pass audio encode.test_unknown_preset_is_rejected.-presetfast"x264_preset": "ultrafast"ultrafastx264_preset=slowslowsglang generate --x264-preset ultrafastultrafast"x264_preset": "lightspeed"Speed Tests
Direct save of a 1344×768, 121-frame, 24 fps clip (MiniMax-H3's 5 s output size) on H200 with a 192-core x86 host and 24 x264 threads, all at CRF 25. The content is a Wan output resized to that size. The time covers the whole save step: GPU conversion, pipe and encode. PSNR is measured against the source frames.
ultrafastsuperfastveryfastfasterfast(default)mediumRelative to
fast,ultrafastsaves 0.23 s per 5 s clip on this host, and at the same CRF gives 1.6 dB lower PSNR at 26% higher bitrate. This is one clip; the default staysfast.🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ❌ Run #36704766112
Latest PR Test (Extra): ❌ Run #36704765823
Latest PR Test (AMD ROCm 10): ❌ Run #36704766192