Skip to content

feat(player): native PGS subtitle rendering via libpgs - #129

Merged
Quick104 merged 5 commits into
mainfrom
claude/amazing-cartwright-e6a71b
Jun 11, 2026
Merged

Quick104 merged 5 commits into
mainfrom
claude/amazing-cartwright-e6a71b

Conversation

@Quick104

@Quick104 Quick104 commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #34.

Problem

Files with PGS (Blu-ray bitmap) subtitle tracks showed "no available subtitles" in the web player. The backend filtered all bitmap codecs out of subtitle_urls because they can't be converted to text, and the only existing path for them was transcode burn-in.

Approach

Render PGS natively client-side — no burn-in, no transcode session — the same way Jellyfin does, using libpgs ([email protected], MIT):

  • Server: PGS tracks are now included in /playback/start subtitle_urls with a .sup URL. The subtitle endpoint streams the track losslessly (ffmpeg -c:s copy -f sup) with per-chunk flush, on the API server and the proxy-node path alike. DVD/DVB bitmap tracks stay hidden (still burn-in only).
  • Client: new usePGSSubtitles hook mirrors the JASSUB/ASS pattern. libpgs fetches the .sup in a worker (URL is already self-authenticating via ?token=), decodes display sets progressively as bytes arrive, and draws onto a canvas over the video. Stream-origin and the delay control flow through the renderer's timeOffset setter without recreating it.
  • Auto-select: text tracks now beat bitmap tracks within the same source tier; a PGS track still wins when it's the only language match, and forced-PGS auto-select now works.
  • Refactor: assSubtitles.ts → subtitleCodecs.ts, consolidating the codec sets (incl. the duplicated bitmap list in SubtitleTranslateModal).

Notable side fixes

  • Pre-existing ASS truncation bug: the streaming extractor applied its -t window cap unconditionally, silently cutting embedded ASS extracts off at the default 600s window even though the client fetches the full track once. ASS and PGS are now both exempt from seek/duration windowing.
  • Likely ASS delay-sign inversion (not bundled here): JASSUB renders at currentTime + timeOffset, so the existing +delay in useASSSubtitles probably makes a positive delay show subtitles earlier, contradicting the VTT path. The PGS hook uses the correct sign; the ASS audit/fix is tracked separately.

Non-goals

  • jellycompat unchanged — third-party Jellyfin clients keep burn-in behavior (NeedsBurnIn semantics untouched).
  • DVD/DVB rendering, OCR/translation of PGS, sidecar .sup scanning.

Risks / follow-ups

  • Native clients: subtitle_urls now contains PGS entries (codec: "hdmv_pgs_subtitle" / "pgs"). silo-android / silo-apple should filter or adopt by codec; worst case is a listed-but-unrenderable track. Needs client follow-up.
  • No extraction cache yet: each PGS selection re-demuxes the container (I/O-bound, streams progressively, but heavy for large files on network storage). Follow-up: cache extracted .sup keyed by (file_id, track).
  • Manual playback matrix pending (needs a real PGS file on a dev server): direct/remux/transcode sync, seek-ahead during extraction, track switching, delay direction, PiP, proxy-node path.

Verification

  • Go: new tests for IsPGS, streamExtractArgs windowing exemptions, buildSubtitleURLs PGS inclusion/dvd-dvb exclusion and index offsets; go test ./internal/playback ./internal/api/handlers green; go vet/gofmt clean.
  • Web: new tests for usePGSSubtitles lifecycle (create/dispose/offset math), codec helpers, auto-select bitmap deprioritization; full suite green (1028 tests); ESLint 0 errors; prettier clean; Vite build emits libpgs as a lazy chunk + hashed worker asset.

AI use

Implemented end-to-end with Claude Code (planning, code, tests, this PR).

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for Blu-ray PGS bitmap subtitles, including extraction, streaming, and client-side rendering in the video player.
    • Enhanced subtitle auto-selection to prioritize text-based subtitles over bitmap formats when both are available for the same language.
  • Tests

    • Added comprehensive test coverage for subtitle codec detection, extraction, and rendering logic.

Quick104 and others added 5 commits June 10, 2026 20:11
PGS (Blu-ray bitmap) subtitle tracks can be copied losslessly into a .sup
elementary stream for client-side rendering, so they no longer have to be
burned in. streamExtractOutput maps PGS to (copy, sup), and the seek/-t
windowing now skips PGS like ASS: both formats are fetched once and
consumed whole by their client-side renderers.

This also fixes a pre-existing truncation bug: the -t duration cap was
applied unconditionally, cutting embedded ASS extracts off at the default
600s window even though the ASS client fetches the full track.

Extract the ffmpeg argument construction into streamExtractArgs for
testability, following the buildFFmpegArgs pattern.

Co-Authored-By: Claude Fable 5 <[email protected]>
PGS tracks were filtered out of /playback/start subtitle_urls entirely,
so the web player showed no subtitles for PGS-only files (#34). Include
them with a .sup URL extension; DVD/DVB bitmap tracks stay hidden since
they still have no non-burn-in delivery path.

HandleSubtitle streams the full PGS track as application/octet-stream.
The seek/duration window is forced to zero for sup: subtitleSeekPosition
falls back to the session's last reported position even without a
?position= query, which would otherwise start the extract mid-file. The
proxy-node subtitle handler gets the same sup branch, streaming ffmpeg
output directly instead of buffering like its text paths.

Co-Authored-By: Claude Fable 5 <[email protected]>
…ecs.ts

Rename assSubtitles.ts to subtitleCodecs.ts — the module already labeled
every codec, not just ASS — and add isPGSCodec/isBitmapCodec. Replace the
duplicated BITMAP_CODECS set in SubtitleTranslateModal with the shared
helper so codec lists live in one place.

Co-Authored-By: Claude Fable 5 <[email protected]>
Render PGS subtitle tracks client-side instead of leaving them
unavailable (#34). usePGSSubtitles mirrors the JASSUB hook: when a PGS
track is active it lazy-loads libpgs, which fetches the .sup stream in a
worker, decodes display sets progressively as bytes arrive, and draws
them onto a canvas positioned over the video.

The renderer looks up the display set at currentTime + timeOffset, so
the HLS stream origin adds and the user-facing delay subtracts — a
positive delay shows subtitles later, matching VTT semantics. Offset
changes apply through the timeOffset setter without recreating the
renderer; track switches, PiP detach, and unmount dispose it.

Co-Authored-By: Claude Fable 5 <[email protected]>
With PGS tracks now listed, an earlier PGS track would win auto-select
over a later same-language SRT/ASS track. Deprioritize bitmap codecs
within the same source tier — text is lighter to render and styleable —
while a PGS track still wins when it is the only language match, and
forced-PGS auto-select now works.

Co-Authored-By: Claude Fable 5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR enables end-to-end PGS bitmap subtitle support: the backend detects PGS codecs, streams them as SUP files via ffmpeg, and serves them through new API routes; the frontend adds a libpgs-based rendering hook, integrates it into VideoPlayer, and refines subtitle auto-selection to prefer text tracks when available.

Changes

PGS Bitmap Subtitle Support

Layer / File(s) Summary
PGS Codec Detection Infrastructure
internal/playback/subtitles.go, web/src/player/utils/subtitleCodecs.ts, internal/playback/subtitle_stream_test.go, web/src/player/utils/subtitleCodecs.test.ts
Introduced shared codec classification: IsPGS function in Go backend and isPGSCodec/isBitmapCodec helpers in frontend to centrally detect PGS and bitmap-based subtitle codecs case-insensitively.
Backend FFmpeg Subtitle Streaming Pipeline
internal/playback/subtitle_stream.go, internal/playback/subtitle_stream_test.go
Refactored ffmpeg argument construction into streamExtractArgs helper: disables time windowing (-ss/-t) for whole-track codecs like PGS/ASS, updated streamExtractOutput to map PGS to SUP format and ASS/SSA to ASS format, with comprehensive test coverage for codec-specific behavior.
Subtitle URL Generation & Codec Filtering
internal/api/handlers/playback.go, internal/api/handlers/playback_subtitle_urls_test.go
Extended subtitleURLExt to map PGS codecs to .sup extension; refined burn-in filtering in buildSubtitleURLs to allow PGS tracks (while excluding non-PGS bitmap codecs that require burn-in), ensuring PGS entries do not include font bundle URLs, validated by new test cases.
API & Proxy Handlers for PGS Extraction
internal/api/handlers/stream.go, internal/proxy/server.go
Narrowed bitmap-extraction rejection to exclude PGS from the "cannot extract as text" check in HandleSubtitle; refactored streamEmbeddedSubtitle to derive output format via switch on codec, compute seek/duration only for VTT, and set correct Content-Type headers; added proxy handleSubtitle branch for sup format requests streaming PGS via ffmpeg.
Frontend PGS Renderer Hook & Lifecycle Management
web/package.json, web/src/player/hooks/usePGSSubtitles.ts, web/src/player/hooks/usePGSSubtitles.test.tsx
Added libpgs dependency; implemented usePGSSubtitles hook for client-side bitmap rendering: lazily imports libpgs, instantiates PgsRenderer bound to video element and current .sup URL, computes timeOffset from stream origin and user delay, updates timing in-place without recreation, manages lifecycle (creation/disposal/track switching), and reports isActive to suppress text overlay; comprehensive test suite validates renderer instantiation, timing, switching, and cleanup.
VideoPlayer & Subtitle Pipeline Integration
web/src/player/components/VideoPlayer.tsx, web/src/player/hooks/useSubtitleTracks.ts, web/src/player/hooks/useASSSubtitles.ts, web/src/player/components/SubtitleMenu.tsx, web/src/player/components/SubtitleTranslateModal.tsx
Integrated usePGSSubtitles hook into VideoPlayer and extended overlay suppression when PGS rendering is active; updated useSubtitleTracks to skip PGS codecs (alongside ASS/SSA) from text-cue pipeline; consolidated codec detection imports across components (SubtitleMenu, SubtitleTranslateModal, useASSSubtitles) to use centralized subtitleCodecs utilities; updated isTranslatableSource to use shared isBitmapCodec helper.
Subtitle Track Auto-Selection Refinement
web/src/player/utils/subtitleSort.ts, web/src/player/utils/subtitleSort.test.ts
Introduced trackPriority helper that combines existing source-tier ordering with bitmap-vs-text weighting: within the same source tier, non-bitmap (text) tracks are preferred over bitmap (PGS) unless language match requires bitmap; updated preferred-track selection functions (language-only and signature-aware) to use new priority calculation; new test suite validates preference rules and forced subtitle behavior.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

  • Silo-Server/silo-server#28: Both PRs modify subtitle URL generation/metadata in internal/api/handlers/playback.go's buildSubtitleURLs (main PR adjusting codec inclusion and ensuring PGS tracks don't get font_bundle_url, retrieved PR adding font_bundle_url for embedded ASS/SSA plus related font endpoints), so the changes are code-level related.
🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat(player): native PGS subtitle rendering via libpgs' clearly and concisely describes the main feature being implemented across the changeset.
Linked Issues check ✅ Passed All objectives from issue #34 are met: PGS subtitles are now exposed in /playback/start subtitle_urls, streamed via the subtitle endpoint, and rendered client-side via usePGSSubtitles hook for full visibility in the player.
Out of Scope Changes check ✅ Passed All changes directly support PGS subtitle rendering; server-side extraction/streaming, client-side rendering, codec utilities, and auto-select improvements are all within scope.
Description check ✅ Passed The PR objectives provide comprehensive context on implementation details, design decisions, and known limitations, enabling informed review of all changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/amazing-cartwright-e6a71b

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

@Quick104
Quick104 merged this pull request into main Jun 11, 2026
1 check was pending
@Quick104
Quick104 deleted the claude/amazing-cartwright-e6a71b branch June 11, 2026 00:18
Quick104 added a commit that referenced this pull request Jun 11, 2026
* feat(playback): add IsPGS helper and sup streaming extract path

PGS (Blu-ray bitmap) subtitle tracks can be copied losslessly into a .sup
elementary stream for client-side rendering, so they no longer have to be
burned in. streamExtractOutput maps PGS to (copy, sup), and the seek/-t
windowing now skips PGS like ASS: both formats are fetched once and
consumed whole by their client-side renderers.

This also fixes a pre-existing truncation bug: the -t duration cap was
applied unconditionally, cutting embedded ASS extracts off at the default
600s window even though the ASS client fetches the full track.

Extract the ffmpeg argument construction into streamExtractArgs for
testability, following the buildFFmpegArgs pattern.

Co-Authored-By: Claude Fable 5 <[email protected]>

* feat(api): expose PGS subtitle tracks as .sup stream URLs

PGS tracks were filtered out of /playback/start subtitle_urls entirely,
so the web player showed no subtitles for PGS-only files (#34). Include
them with a .sup URL extension; DVD/DVB bitmap tracks stay hidden since
they still have no non-burn-in delivery path.

HandleSubtitle streams the full PGS track as application/octet-stream.
The seek/duration window is forced to zero for sup: subtitleSeekPosition
falls back to the session's last reported position even without a
?position= query, which would otherwise start the extract mid-file. The
proxy-node subtitle handler gets the same sup branch, streaming ffmpeg
output directly instead of buffering like its text paths.

Co-Authored-By: Claude Fable 5 <[email protected]>

* refactor(player): consolidate subtitle codec helpers into subtitleCodecs.ts

Rename assSubtitles.ts to subtitleCodecs.ts — the module already labeled
every codec, not just ASS — and add isPGSCodec/isBitmapCodec. Replace the
duplicated BITMAP_CODECS set in SubtitleTranslateModal with the shared
helper so codec lists live in one place.

Co-Authored-By: Claude Fable 5 <[email protected]>

* feat(player): native PGS subtitle rendering via libpgs

Render PGS subtitle tracks client-side instead of leaving them
unavailable (#34). usePGSSubtitles mirrors the JASSUB hook: when a PGS
track is active it lazy-loads libpgs, which fetches the .sup stream in a
worker, decodes display sets progressively as bytes arrive, and draws
them onto a canvas positioned over the video.

The renderer looks up the display set at currentTime + timeOffset, so
the HLS stream origin adds and the user-facing delay subtracts — a
positive delay shows subtitles later, matching VTT semantics. Offset
changes apply through the timeOffset setter without recreating the
renderer; track switches, PiP detach, and unmount dispose it.

Co-Authored-By: Claude Fable 5 <[email protected]>

* feat(player): prefer text over bitmap tracks in subtitle auto-select

With PGS tracks now listed, an earlier PGS track would win auto-select
over a later same-language SRT/ASS track. Deprioritize bitmap codecs
within the same source tier — text is lighter to render and styleable —
while a PGS track still wins when it is the only language match, and
forced-PGS auto-select now works.

Co-Authored-By: Claude Fable 5 <[email protected]>

---------

Co-authored-by: Claude Fable 5 <[email protected]>
Quick104 added a commit that referenced this pull request Jun 17, 2026
* feat(playback): add IsPGS helper and sup streaming extract path

PGS (Blu-ray bitmap) subtitle tracks can be copied losslessly into a .sup
elementary stream for client-side rendering, so they no longer have to be
burned in. streamExtractOutput maps PGS to (copy, sup), and the seek/-t
windowing now skips PGS like ASS: both formats are fetched once and
consumed whole by their client-side renderers.

This also fixes a pre-existing truncation bug: the -t duration cap was
applied unconditionally, cutting embedded ASS extracts off at the default
600s window even though the ASS client fetches the full track.

Extract the ffmpeg argument construction into streamExtractArgs for
testability, following the buildFFmpegArgs pattern.

Co-Authored-By: Claude Fable 5 <[email protected]>

* feat(api): expose PGS subtitle tracks as .sup stream URLs

PGS tracks were filtered out of /playback/start subtitle_urls entirely,
so the web player showed no subtitles for PGS-only files (#34). Include
them with a .sup URL extension; DVD/DVB bitmap tracks stay hidden since
they still have no non-burn-in delivery path.

HandleSubtitle streams the full PGS track as application/octet-stream.
The seek/duration window is forced to zero for sup: subtitleSeekPosition
falls back to the session's last reported position even without a
?position= query, which would otherwise start the extract mid-file. The
proxy-node subtitle handler gets the same sup branch, streaming ffmpeg
output directly instead of buffering like its text paths.

Co-Authored-By: Claude Fable 5 <[email protected]>

* refactor(player): consolidate subtitle codec helpers into subtitleCodecs.ts

Rename assSubtitles.ts to subtitleCodecs.ts — the module already labeled
every codec, not just ASS — and add isPGSCodec/isBitmapCodec. Replace the
duplicated BITMAP_CODECS set in SubtitleTranslateModal with the shared
helper so codec lists live in one place.

Co-Authored-By: Claude Fable 5 <[email protected]>

* feat(player): native PGS subtitle rendering via libpgs

Render PGS subtitle tracks client-side instead of leaving them
unavailable (#34). usePGSSubtitles mirrors the JASSUB hook: when a PGS
track is active it lazy-loads libpgs, which fetches the .sup stream in a
worker, decodes display sets progressively as bytes arrive, and draws
them onto a canvas positioned over the video.

The renderer looks up the display set at currentTime + timeOffset, so
the HLS stream origin adds and the user-facing delay subtracts — a
positive delay shows subtitles later, matching VTT semantics. Offset
changes apply through the timeOffset setter without recreating the
renderer; track switches, PiP detach, and unmount dispose it.

Co-Authored-By: Claude Fable 5 <[email protected]>

* feat(player): prefer text over bitmap tracks in subtitle auto-select

With PGS tracks now listed, an earlier PGS track would win auto-select
over a later same-language SRT/ASS track. Deprioritize bitmap codecs
within the same source tier — text is lighter to render and styleable —
while a PGS track still wins when it is the only language match, and
forced-PGS auto-select now works.

Co-Authored-By: Claude Fable 5 <[email protected]>

---------

Co-authored-by: Claude Fable 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

None yet

Development

Successfully merging this pull request may close these issues.

PGS subtitles not working with webplayer

1 participant