Repository navigation
fix(playback): composite bitmap subtitle burn-in on the GPU for QSV/VAAPI - #465
Merged
Merged
Conversation
…AAPI Bitmap subtitle burn-in (PGS/VOBSUB/DVB) ran the whole video through a GPU->CPU->GPU roundtrip: every decoded frame was hwdownload'd to system memory, the subtitle bitmap composited with the software overlay filter, then hwupload'd back for the encoder. On a 1080p source that pins the encode below realtime (~0.68x measured), so the client can never build a buffer and rides the produced-head edge indefinitely; the same roundtrip also intermittently crashes the QSV buffer path with SIGBUS. Composite on the GPU instead via overlay_vaapi for QSV and VAAPI: the decoded video never leaves its VAAPI surface and only the small, low-frequency subtitle bitmap is uploaded. Measured ~7x realtime and crash-free on the same file. The libass text path is unchanged (it must stay on CPU), and NVENC/CPU keep the software overlay because overlay_cuda is unverified on the bundled ffmpeg. Adds QSV and NVENC bitmap burn-in tests and updates the VAAPI test to the GPU graph.
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughBitmap subtitle burn-in now uses GPU composition for QSV and VAAPI, while NVENC and CPU encoding retain software overlay paths. Tests cover the updated VAAPI, QSV, and NVENC filter graphs. ChangesBitmap subtitle burn-in
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant TranscodeArgs
participant FilterGraph
participant HardwareEncoder
TranscodeArgs->>FilterGraph: Select graph from opts.HWAccel
FilterGraph->>HardwareEncoder: Send overlay_vaapi graph for QSV/VAAPI
FilterGraph->>HardwareEncoder: Send hwdownload/overlay graph for NVENC
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
This was referenced Oct 14, 2026
Closed
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.
Single commit: move bitmap subtitle burn-in off the CPU and onto the GPU for QSV/VAAPI.
Problem
Movies with burned-in bitmap subtitles buffer forever and sometimes crash the stream.
On the live server, a viewer watching a 1080p movie with PGS ("image") subtitles burned in — e.g. A.I. Artificial Intelligence — never builds up a play buffer. The player sits right at the live edge: it asks for the next 2-second chunk, the server delivers it a beat late, the player asks for the next one, and so on for minutes on end. Any tiny hiccup turns into a visible stall/rebuffer. In the server logs this showed up as a session requesting one segment at a time, each arriving ~1.5–2.5s old against a 3.5s timeout, plus repeated transcode restarts and, on some runs, an outright
ffmpegcrash (bus error (core dumped)) that froze playback for up to a minute while it recovered.This only affects bitmap subtitles (PGS/VOBSUB/DVB) that are burned into the video during a transcode. Text subtitles (SRT/ASS) and direct/remux playback are unaffected.
The root cause is throughput: with the subtitle burn-in running on the CPU, the transcode encodes slower than realtime, so it can physically never get ahead of the viewer.
Measured on the exact file/hardware (
jellyfin-ffmpeg 7.1.4, Intel QSV, 25s sample, seek to 10:00):hwdownload → software overlay → hwupload → qsvbus error (core dumped)on 2 of 3 runsoverlay_vaapi → h264_vaapioverlay_vaapi → hwmap qsv → h264_qsv(the QSV drop-in)Below 1.0× is starvation by definition; the fix takes it to ~7×, i.e. from "can never keep up" to "roughly 7 seconds of headroom produced per second of playback."
Solution
fix(playback): composite bitmap subtitle burn-in on the GPU for QSV/VAAPI
The burn-in graph is built in
appendBitmapSubtitleBurnInArgs(internal/playback/transcode.go:727). Previously every hardware path (qsv/vaapi/nvenc) used the same skeleton it inherited from the text path: pull the entire decoded video frame off the GPU to system RAM (hwdownload,format=yuv420p), composite the subtitle with the softwareoverlayfilter, convert, and push the whole frame back to the GPU (hwupload/hwmap). For a 1080p source that's ~70+ MB/s of full-frame PCIe traffic plus a per-frame CPU composite — purely to stamp on a subtitle bitmap that only changes every few seconds. That roundtrip is both the throughput wall and the source of the SIGBUS instability (the container's/dev/shmis only 64M, which the large QSV surface churn tips over).The fix keeps the video on the GPU and uploads only the small subtitle bitmap:
qsvScaleFilterhelper, whose tail (scale_vaapi=…,hwmap=derive_device=qsv,format=qsv) maps the composited VAAPI surface to QSV forh264_qsv.vaapiScaleFilter; the frames stay on VAAPI straight intoh264_vaapi, so no cross-device map is needed.eof_action=passis carried over (verified supported byoverlay_vaapi) so the video keeps flowing after the subtitle stream ends.Deliberately not changed:
appendSubtitleBurnInArgs) stays on CPU — libass is a software renderer with no GPU equivalent.overlay_cudaexists in the build but I have no NVIDIA hardware to verify it on, and shipping an unverified hardware filtergraph could break working (if slow) NVIDIA burn-in. Left as a follow-up.Tests: updated the VAAPI assertion to the GPU graph and added QSV and NVENC cases (
internal/playback/transcode_args_test.go), locking in that QSV/VAAPI composite on the GPU with nohwdownload, and that NVENC still takes the CPU roundtrip.Risk / follow-ups
overlay_cudaon real NVIDIA hardware and switch it over.overlay_vaapicomposites at 0,0, identical to the prior softwareoverlay; PGS is authored at the video resolution in practice, so no positioning regression is expected, but it's worth an eyeball on a title with an oddly-authored PGS track.ffmpegruns on one Intel iHD/QSV host (the production box). Other VAAPI drivers (AMD/older Intel) should be smoke-tested before assuming universal behavior./dev/shmat 64M is small; the fix removes the pressure that was tipping it into SIGBUS, but the low limit is worth revisiting separately.ffmpegbenchmarks).Verification
gofmt -l— clean on both files.go vet ./internal/playback/— clean.go test ./internal/playback/...— pass (ok … 6.096s); all 9 burn-in tests pass, including the 3 new/updated ones.ffmpegbenchmarks on the production host against the actual starving file produced the table above (before: 0.68× + SIGBUS; after: 7.3–7.7×, stable), witheof_action=passand a 720p downscale target both exercised.AI-use disclosure
TargetResolutionis empty, so an un-scaled 1080p→1080p burn-in still produces a valid graph; (3)eof_action=passis actually accepted byoverlay_vaapi(confirmed via-h filter); (4) NVENC/text/CPU paths are untouched and still covered by tests. Open risk left explicit above:overlay_cuda(NVENC) is unverified and intentionally left on the slow path rather than shipped blind.Summary by CodeRabbit
Performance Improvements
Bug Fixes