Skip to content

fix(playback): scale QSV tone-map frames before OpenCL, not after - #2448

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
neurekadev:fix/qsv-tonemap-scale-before-opencl
Oct 14, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
neurekadev:fix/qsv-tonemap-scale-before-opencl

Conversation

@neurekadev

@neurekadev neurekadev commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Note

Stacked PR 1 of 2. Merge this before #2449 (PR 2 of 2).
#2449 is built on this branch's commit (f0156f3ea) and reuses the tone-map graph split it introduces. Changing this commit means rebuilding #2449. This branch now also carries a merge of main that resolves a test conflict with #2444; #2449 includes it.

Problem

Closes #2446
Related issue: #2447
Validation tasks: unblocks #1173 C3

QSV tone-mapped transcodes on Intel Arrow Lake come out corrupted during motion: blocks of the picture shift against their neighbours, often in a staircase. The cause is the scale_vaapi that downscales the tonemap_opencl output, a VAAPI read of an OpenCL surface that this hardware does not order correctly. This change resizes before tone mapping instead, so nothing between the tone mapper and the encoder reads the surface.

On the reporting deployment, Silo's own command corrupted 23 and 28 of the first 148 frames of a Dolby Vision 8.1 episode on two runs, and 27 of the first 722. With this change, no frame was corrupted in four 6-second runs or over the 30 seconds.

Approach

QSVFilter now takes the output height. HDR kinds resize in the scale_vaapi that already ran before hwmap to OpenCL. After the reverse map, the transcode graph ends with QSVInteropFilter(), whose scale_vaapi=format=nv12 is a passthrough, so the encoder is the only reader of the tone-mapped surface and holds it until the encode completes. SDR base layers do not use OpenCL and keep resizing after colour conversion, as before. This is also the order Jellyfin's Intel VAAPI graph uses, and the tone mapper now processes a 1080p frame instead of a 4K one.

Unchanged:

FFmpeg creates the OpenCL context with CL_CONTEXT_INTEROP_USER_SYNC=CL_FALSE, so the driver should order these accesses itself; this is a graph-level workaround for that not happening. scale_vaapi passes frames through untouched when the size, format and colour options don't change, which is the case after the reverse map; that behaviour is in FFmpeg 6.1 and later, and the image bundles 8.1.3.

Validation

  • Go build, gofmt, go vet, make lint-changed, make verify-playback-fixtures, make verify-local-paths: pass.
  • make test-go: every package passes except internal/librarymonitor (its remount test needs mount, which the sandbox denies) and internal/routeinventory (a Go export-data version mismatch in the local build cache). Both fail the same way on main.
  • New tests check that HDR graphs resize before tonemap_opencl, with hardware and software decode, and end in the passthrough interop with nothing else after the tone mapper. The playback test fails with the old order.
  • Hardware, Intel Arrow Lake (Arc 130T/140T iGPU), iHD 26.3.5, jellyfin-ffmpeg 8.1.3, inside Silo's image. Each graph was run with Silo's encoder settings and compared frame by frame against a software tone map of the same frames:
Graph Span Frames below SSIM 0.95
Before (2 runs) 6 s, 148 frames 23, 28
After (4 runs) 6 s, 148 frames 0 each
Before 30 s, 722 frames 27
After 30 s, 722 frames 0
After, software decode 6 s, 148 frames 0
  • Not tested on other Intel generations or with a real client session on this build.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/pr-2448/

Surface and build: transcoded H.264 from Silo's QSV graph on the author's Intel Arrow Lake host, build-1382 image with this branch's graph.

Risks

  • QSV HDR transcodes that scale now tone-map at the output resolution instead of tone-mapping at 4K and then scaling. Mean SSIM against a 4K tone map followed by a scale was 0.994 to 0.996 across the runs, about the same as a libx264 encode of the 4K-tone-mapped frames (0.997).
  • The hdr_to_sdr_tonemap recipe version stays at 1, as with earlier tone-map graph changes. Prepared downloads already transcoded through the old graph stay cached, and a node on an older build keeps producing the old graph until it is upgraded.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code in T3 Code
  • Tool(s): Claude Code, GitHub CLI, jellyfin-ffmpeg 8.1.3, PoCL
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated at the author's direction; the author has not yet reviewed the diff. The hardware runs were made on the author's server with their permission.
  • Adversarial review: A separate Claude Code agent (claude-opus-5-5) built all 120 graph combinations of source kind, resolution, decode mode and subtitle mode before and after the change, read FFmpeg's scale_vaapi passthrough and hwmap code, and checked every caller. It found no defect. Its suggestions led to the exact passthrough tail and its test, the note on QSVInteropFilter, the software-decode hardware run, and narrower comment wording.

🤖 Generated with Claude Code

Note

Scale QSV tone-map frames before OpenCL tone mapping

  • tonemap.QSVFilter in tonemap.go now takes a target-height parameter. HDR graphs resize before the OpenCL tone mapper; SDR graphs resize after VAAPI conversion; zero height leaves the source size unchanged.
  • The QSV hardware branch in transcode.go passes the requested target height into QSVFilter and drops its separate post-hoc scaling helper.
  • Other QSV graphs (CPU-tail, subtitle-overlay, preflight, probe) pass an explicit zero height, keeping their unscaled QSV conversion.
  • Adds tests in tonemap_test.go and transcode_args_test.go covering HDR-before-OpenCL ordering, SDR-after-conversion ordering, and zero-height omission for PQ, HLG, and Dolby Vision.
  • Risk: the post-tone-map VAAPI stage must stay a passthrough; QSVInteropFilter docs now state it must not resize or do color processing.

Macroscope summarized f3349b4.

QSV tone-mapped transcodes on Intel Arrow Lake came out with shifted
blocks during motion. The corruption appears when scale_vaapi resizes
the tonemap_opencl output, which it releases back to the tone mapper's
pool without waiting for the GPU. Resize before tone mapping and hand
the OpenCL output straight to the encoder, which holds each surface
until the encode completes.

Closes Silo-Server#2446

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-kody

silo-kody Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 592464a9-78ec-4c07-9684-68a9e696b1d7
📥 Commits

Reviewing files that changed from the base of the PR and between f0156f3 and f3349b4.

📒 Files selected for processing: 2
  • internal/tonemap/tonemap.go
  • internal/tonemap/tonemap_test.go
🚧 Files skipped from review as they are similar to previous changes: 1
  • internal/tonemap/tonemap.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

📝 Walkthrough

QSV tone mapping now accepts an output height. HDR input is scaled before OpenCL tone mapping, while SDR input is scaled after color conversion. Playback graphs pass the target height or zero, and tests cover scaling placement and graph ordering.

Changes: QSV tone-map scaling

Layer / File(s) Summary
QSV filter height and scaling
internal/tonemap/tonemap.go, internal/tonemap/preflight.go, internal/tonemap/probe.go, internal/tonemap/tonemap_test.go
QSVFilter now accepts an output height. HDR scaling occurs before OpenCL tone mapping; SDR scaling occurs after color conversion. Preflight and probe calls pass explicit heights, and tests cover scaled and unscaled graphs.
Playback graph integration
internal/playback/transcode.go, internal/playback/transcode_args_test.go
The scale-only QSV graph passes the target height to QSVFilter and adds QSVInteropFilter. Text-subtitle and bitmap-subtitle graphs pass zero. Tests check scaling before OpenCL tone mapping and verify the interop tail has no later VAAPI scaling.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: quick104

Merge Risk: ⚪ Minimal · up to f3349

The changed graphs place scaling at the intended stage and preserve that size through interop. No concrete merge-blocking issue was found.

Pre-merge checks: Passed 5
Passed Passed checks: 5 passed
Check name Status Explanation
Linked Issues check Passed The changes meet the coding requirements in [#2446]. QSV HDR graphs pass the target height to QSVFilter and resize before tonemap_opencl. The post-tone-map path uses QSVInteropFilter() without a…
Out of Scope Changes check Passed The changed files support the linked fix. The QSVFilter interface and its callers implement the graph-order change. The tests verify the required filter order and preserved graph variants. No unrela…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 6 files.
Description check Passed The description clearly explains the QSV tone-map ordering change, its motivation, implementation, validation, risks, and scope.
Title check Passed The title clearly and concisely summarizes the main change: scaling QSV tone-map frames before OpenCL processing.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@silo-triage silo-triage Bot added bug Something isn't working evidence-required Needs before-and-after evidence before the Evidence check passes go Pull requests that update go code impact: playback Can't play, stalls, or wrong media priority: P2 Limited scope, workaround exists, or polish labels Oct 14, 2026
@silo-triage

silo-triage Bot commented Oct 14, 2026

Copy link
Copy Markdown

Please publish the before-and-after captures of the same affected frame to the private Evidence page and add its link under Evidence, identifying the build or commit for each capture. The comparison table reports fewer corrupted frames, but the PR currently has no visual artifact showing the playback change.

Comment thread internal/playback/transcode.go Resolved
@neurekadev

Copy link
Copy Markdown
Contributor Author

Published the before-and-after captures of frame 95 (full frame and an enlarged crop) at https://evidence.siloserver.org/r/silo-server/pr-2448/ and linked it under Evidence. Each capture names its commit: main 6144c45 before, this branch f0156f3 after, both run in the build-1382 image on the Arrow Lake host.

Resolve the tonemap_test.go conflict with Silo-Server#2444 by keeping both tests and
passing QSVFilter's new height argument in the source-peak test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of f0156f3. The graph change itself checks out; one merge blocker.

Medium: the branch conflicts with main. #2444 merged a new test, TestSoftwareAndQSVToneMapsPinTheSourcePeak, into internal/tonemap/tonemap_test.go at the same spot as TestQSVFilterScalesHDRBeforeOpenCL, and it calls QSVFilter(kind) with the old one-argument signature. GitHub can't merge the PR until that's resolved, and a plain textual resolution wouldn't compile. The fix keeps both tests and passes 0 as the height in #2444's test. I'm pushing a merge of main that does this, so there's no need to change it yourself. #2449 gets the same merge on top.

Quick104 added a commit to neurekadev/silo-server that referenced this pull request Oct 14, 2026
Brings in Silo-Server#2448's branch merged with main, which resolves the
tonemap_test.go conflict with Silo-Server#2444.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Quick104

Copy link
Copy Markdown
Contributor

Review summary

Reviewed f0156f3; current head f3349b4 adds only a merge of main.

Addressed

Checked, no change needed

  • The scale_vaapi=format=nv12 in QSVInteropFilter after the reverse map passes frames through: FFmpeg's VAAPI scaler skips processing when size, format and colour options are unchanged, so the encoder is the only reader of the tone-mapped surface.
  • Every QSVFilter caller: hardware and software decode, every source kind, empty and invalid target resolutions, SDR base layers, text and bitmap subtitles, preflight and probe. The QSV read+write map, format=qsv and the reverse map's extra_hw_frames=16 are all still present.

Remaining

  • Needs your call: the hdr_to_sdr_tonemap recipe stays at version 1, so QSV downloads prepared with the corrupt graph stay cached and older nodes keep building it until they upgrade. The existing thread on transcode.go covers the trade-off.
  • Only Arrow Lake was tested on hardware. The graph change reaches every Intel generation that does QSV HDR tone mapping, including N100-class boxes. A run on one older generation (Alder Lake-N or Tiger Lake) would close this.

Validated features: no passed case reaches this code. The PR body now reads Validation tasks: unblocks #1173 C3: C3 (QSV HDR-to-SDR) hasn't been run, and the corruption this fixes would fail it on Arrow Lake.

User manual: unaffected. The playback page doesn't describe the filter graph.

Apple/Android: no client change. Server-side transcode graph only; jellycompat uses the same graph.

Cross-provider round: GPT-6.1-Sol (xhigh), one round over both PRs. It found nothing, and its FFmpeg source checks confirmed the passthrough and the reverse-map behaviour.

Fit: 9/10 · Readiness: 8/10 — conditional (assuming CI is green)

  • Fit: it fixes visible corruption in hardware HDR transcoding by ordering the graph the way Jellyfin's Intel graph does, and it cuts tone-map work on downscaled streams, which helps low-power Intel hosts.
  • Readiness: the change is small, tested at the graph level and measured on hardware. It loses points because only one Intel generation was tested, and the recipe version decision is still open.

@Quick104
Quick104 merged commit 009b47d into Silo-Server:main Oct 14, 2026
16 checks passed
Quick104 added a commit to neurekadev/silo-server that referenced this pull request Oct 14, 2026
main now carries Silo-Server#2448 as squash commit 009b47d, whose tree matches
f3349b4 already on this branch, so this branch's tree is unchanged.

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

bug Something isn't working evidence-required Needs before-and-after evidence before the Evidence check passes go Pull requests that update go code impact: playback Can't play, stalls, or wrong media priority: P2 Limited scope, workaround exists, or polish

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] QSV tone-mapped transcodes corrupt frames when a VAAPI filter reads the OpenCL output

2 participants