Skip to content

obs-ffmpeg: Fix SVT-AV1 rate-control options - #27

Closed
icp4u wants to merge 1 commit into
obs-rust:masterfrom
icp4u:fix/upstream-13849-svt-av1
Closed

icp4u wants to merge 1 commit into
obs-rust:masterfrom
icp4u:fix/upstream-13849-svt-av1

Conversation

@icp4u

@icp4u icp4u commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Selecting CBR for SVT-AV1 could silently configure VBR because OBS passed
its private parameter dictionary to the nonexistent svtav1_opts AVOption.
Use svtav1-params and remove obsolete bias-pct and the redundant,
incorrectly scaled tbr. FFmpeg receives the target bitrate through bit_rate.

Apply custom options first, then fill in missing OBS defaults while keeping
explicit user values. For example, svtav1-params=tune=0 now retains CBR and
low-delay prediction; rc=1:pred-struct=2 still explicitly overrides them.
If dictionary retrieval, merging, or assignment fails, free partial state,
log the failure, set the localized encoder error, and fail initialization.
The merged svtav1-params string is now logged after the encoder settings
block, so a log shows exactly what SVT received next to any SVT error.

References: obsproject/obs-studio#13849

Behavior change: selecting CBR now enables the intended low-delay prediction
instead of the accidental VBR/random-access configuration. SVT disables TPL
in low-delay mode, which can affect quality at the same bitrate. No quality
comparison or guarantee of perfectly flat instantaneous bitrate is claimed.

Because CBR now really applies, custom SVT tuning that needs random-access
prediction or CRF is no longer silently accepted under CBR. With SVT 4.2.0,
svtav1-params=tune=2 (SSIM) makes the encoder fail to open ("Tune SSIM only
supports CRF rate control mode"), and tune=0 (VQ) is forced to PSNR by
SVT in low-delay mode. Before, these worked only because CBR was silently
VBR. Users who need such tuning should select VBR or CQP.

Add eight headless cmocka tests covering CBR/VBR/CQP, unrelated custom tuning,
explicit overrides, AOM behavior, error reporting and factory cleanup, and
an eight-frame real SVT encode. The smoke test uses the exact production
dictionary without adding an lp parameter. Existing C tests, public headers,
and exported signatures are unchanged.

Validation:

  • Original baseline: five of seven tests failed before the initial fix.
  • Review regression: two of eight tests failed against the first patch.
  • Revised suite: all eight pass with ASan/UBSan/LSan.
  • Smoke encode: 128x128, eight frames, SVT 4.2.0 (host) and 2.3.0 (Docker).
    Both report CBR / 6000 Kbps with low-delay prediction.
  • ./lint and ./unittest pass; Linux CTest passes 7/7 OFF and 7/7 ON.
  • Export comparison: IDENTICAL (1752 symbols).
  • Windows/macOS target lists are updated but those platforms were not run.
  • FFmpeg builds lacking libsvtav1 explicitly skip the new test. Both Linux
    configurations ran all eight cases without skips.

Thanks to liying-official for the report and to Jia-ben00 (#13901) and
lnuxe (#13959) for the prior analysis in their closed upstream proposals:
obsproject/obs-studio#13901
obsproject/obs-studio#13959

Prepared with assistance from Codex (GPT-6). Claude Opus reviewed the initial
patch; its feedback is addressed in this revision. Human review is pending.

@zackees

zackees commented Oct 9, 2026

Copy link
Copy Markdown
Member

Thanks @icp4u, this fix is correct. It's merged as #63, rebased onto current master with your authorship kept. I split it into a test commit and a fix commit, and registered the test through the cmocka-tests aggregate target, which replaced the per-script target lists and caused this PR's conflict. The fix itself is unchanged.

@zackees zackees closed this Oct 9, 2026
zackees pushed a commit to nathan-v/obs-studio that referenced this pull request Oct 10, 2026
Configure the AV1 encoder through the production av1_update() with real
FFmpeg options and check what reaches svtav1-params: CBR must deliver
rc=2 with pred-struct=1, without the obsolete bias-pct or a tbr in the
wrong units; VBR, CQP, custom options and AOM keep their behaviour; an
option failure fails initialization. A small synthetic encode runs the
corrected CBR configuration. Skips (77) without libsvtav1.

Rebased from obs-rust#27 onto the cmocka-tests aggregate target.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants