Skip to content

fix(player): keep subtitles over the picture on baked-in letterbox sources - #107

Closed
RXWatcher wants to merge 2 commits into
Silo-Server:mainfrom
RXWatcher:feat/letterbox-subtitle-inset
Closed

RXWatcher wants to merge 2 commits into
Silo-Server:mainfrom
RXWatcher:feat/letterbox-subtitle-inset

Conversation

@RXWatcher

@RXWatcher RXWatcher commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A 2.39:1 image mastered inside a 1920x1080 frame — routine on WEB-DL sources — is a 16:9 video as far as the container, the decoder, and AVPlayerLayer are all concerned. videoRect therefore covers the full height of the frame, and a bottom-anchored subtitle renders inside the baked-in black bar rather than over the picture. On a TV that reads as subtitles floating in the void below the image.

Nothing in the file's metadata reveals this; only the pixels do.

Approach

The server measures the bars with cropdetect (sampled across the runtime, intersected so a fade-to-black can't be mistaken for a bar) and publishes them as fractions of the frame height on the playback session response — letterbox_top_fraction / letterbox_bottom_fraction. Server side: Silo-Server/silo-server#483 — this PR needs it to land first, and degrades to today's behaviour without it.

This PR decodes those fractions and insets the displayed video rect by them before the subtitle overlay is keyed to it:

  • tvOS — the overlay stays full-frame and the inset rect becomes the libass margin, so font scale still tracks the picture and the "Bottom" position preset renders below the image into the bar as designed.
  • iOS / macOS — the inset rect becomes the overlay frame directly.

BakedLetterbox and VideoDisplayRect.pictureRect(in:letterbox:gravity:) live alongside the existing SubtitleVideoInsets geometry in VideoDisplayRect.swift; both AVPlayer-backed and CoreMedia-backed surfaces on all three platforms go through them.

Deliberate limits

  • Only .resizeAspect. The fill/zoom gravities crop the frame by an amount this code cannot see, so the bars that survive on screen are smaller than the fractions describe — insetting by the full amount would push cues into the picture, which is worse than the bug being fixed. Those modes keep today's behaviour. Handling them properly needs the presentation size at the inset site; worth doing as a follow-up if anyone plays letterboxed content zoomed.
  • Fractions are clamped client-side too (2%–25% per edge, non-finite refused), independently of the server's own sanitising. A bad measurement must not be able to place subtitles mid-picture.
  • Absent fields decode to zero, so a server without the change behaves exactly as before.

Alignment

Matches the Android client, which consumes the same fractions off the v3 plan's source descriptor and applies them via SubtitleManager.letterbox. Apple does not speak protocol v3, which is why the server publishes the same measurement on the v2 session response.

Testing

  • xcodebuild build green on all three schemes: Silo (iOS Simulator), SiloTV (tvOS Simulator), SiloMac (macOS).
  • 5 new unit tests in VideoDisplayRectTests.swift covering the inset geometry, the fill-gravity carve-out, asymmetric bars, and the clamping — passing alongside the existing suite.
  • End-to-end verified on the Android TV client against a server build with the measurement live: a 2.39:1 title measured 12.78% per edge (matching (1080 − 1920/2.39) / 2 / 1080) and cues moved onto the picture. The Apple side of this change has not yet been run on a device or simulator against a live server — it is the same measurement and the same arithmetic, but that verification is still outstanding.

AI-use disclosure

Written by Claude Opus 5 (Claude Code) working with @RXWatcher, who reviewed the change, directed the approach, and ran the on-device verification described above.

…urces

A 2.39:1 image mastered inside a 1920x1080 frame is a 16:9 video to
every layer of the stack, so `AVPlayerLayer.videoRect` (and the
CoreMedia equivalent) covers the full height and a bottom-anchored cue
renders inside the black bar instead of over the image. Nothing in the
container reveals the bars — only the pixels do — so the server measures
them with cropdetect and publishes fractions of the frame height on the
playback session response.

Decode those, and inset the displayed video rect by them before the
subtitle overlay is keyed to it. On tvOS that is the libass margin the
"Bottom" preset positions against; on iOS/macOS it is the overlay frame
itself.

Only applied under `.resizeAspect`. The fill/zoom gravities crop the
frame by an amount this code cannot see, so the bars that survive on
screen are smaller than the fractions describe and insetting by the full
amount would push cues into the picture — worse than the problem being
fixed. Those modes keep today's behaviour.

Fractions are clamped client-side as well as server-side: a bad
measurement must not be able to place subtitles mid-picture, and a bar
under 2% is rounding noise rather than a letterbox.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Db4dSxN9tH8yN7uUP549tK
@coderabbitai

coderabbitai Bot commented Jul 26, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@RXWatcher, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 53 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c9437c10-db48-43a6-a7e0-ccb9b9fa5744

📥 Commits

Reviewing files that changed from the base of the PR and between 91b5020 and ffe8804.

📒 Files selected for processing (7)
  • iosApp/iosApp/Networking/Models.swift
  • iosApp/iosApp/Screens/Player/AVPlayerRoute/AVPlayerSurface.swift
  • iosApp/iosApp/Screens/Player/CoreMedia/PlayerSurface.swift
  • iosApp/iosApp/Screens/Player/PlayerView.swift
  • iosApp/iosApp/Screens/Player/PlayerViewModel.swift
  • iosApp/iosApp/macOS/AVPlayerSurface.swift
  • iosApp/iosApp/macOS/PlayerSurface.swift
📝 Walkthrough

Walkthrough

Changes

Baked-in top and bottom letterbox fractions are decoded from playback sessions, stored in PlayerViewModel, and passed through iOS and macOS player surfaces. Subtitle overlays now use an adjusted picture rectangle for aspect-fit playback, with tests covering detection and geometry behavior.

Baked letterbox geometry and session contract

Layer / File(s) Summary
Letterbox model and picture rectangle
iosApp/iosApp/Screens/Player/Subtitles/VideoDisplayRect.swift, iosApp/Tests/VideoDisplayRectTests.swift
BakedLetterbox sanitizes fractions and VideoDisplayRect.pictureRect removes detected top and bottom bars for aspect-fit playback; tests cover gravity, invalid measurements, and asymmetric bars.
Playback session decoding
iosApp/iosApp/Networking/Models.swift
PlaybackSessionResponse decodes top and bottom letterbox fractions, defaulting missing values to zero.

Player state and rendering wiring

Layer / File(s) Summary
Session state propagation
iosApp/iosApp/Screens/Player/PlayerViewModel.swift, iosApp/iosApp/Screens/Player/PlayerView.swift, iosApp/iosApp/macOS/PlayerView.swift
The view model captures letterbox values during initial loads and transcode restarts, and both platform view builders pass them to their rendering surfaces.
iOS surface layout
iosApp/iosApp/Screens/Player/AVPlayerRoute/AVPlayerSurface.swift, iosApp/iosApp/Screens/Player/CoreMedia/PlayerSurface.swift
iOS surface views invalidate layout when baked letterbox values change and position subtitle overlays using the adjusted picture rectangle.
macOS surface layout
iosApp/iosApp/macOS/AVPlayerSurface.swift, iosApp/iosApp/macOS/PlayerSurface.swift
macOS surface views apply baked letterbox values and calculate subtitle overlay frames from the adjusted picture rectangle.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant PlaybackSessionResponse
  participant PlayerViewModel
  participant PlayerView
  participant PlayerSurface
  participant VideoDisplayRect
  participant SubtitleOverlay

  PlaybackSessionResponse->>PlayerViewModel: decode letterboxTopFraction and letterboxBottomFraction
  PlayerViewModel->>PlayerView: publish bakedLetterbox
  PlayerView->>PlayerSurface: pass bakedLetterbox
  PlayerSurface->>VideoDisplayRect: calculate pictureRect
  VideoDisplayRect-->>PlayerSurface: return adjusted picture rectangle
  PlayerSurface->>SubtitleOverlay: position overlay within picture rectangle
Loading

Possibly related issues

  • Silo-Server/silo-android issue 32 — Addresses subtitle overlay sizing from the displayed video rectangle, including baked letterboxing in this pull request.

Possibly related PRs

Suggested reviewers: quick104

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.08% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: subtitle positioning for baked-in letterbox playback sources.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@iosApp/iosApp/Screens/Player/PlayerViewModel.swift`:
- Around line 2995-2998: Convert both PlaybackSessionResponse letterbox fraction
values to CGFloat when constructing BakedLetterbox at
iosApp/iosApp/Screens/Player/PlayerViewModel.swift:2995-2998 and 4088-4091,
covering the fresh-load and transcode-restart call sites. Update the topFraction
and bottomFraction arguments without changing other behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bc8f45e7-17ad-4e57-8182-4c887e536ca1

📥 Commits

Reviewing files that changed from the base of the PR and between 8db35a8 and 91b5020.

📒 Files selected for processing (10)
  • iosApp/Tests/VideoDisplayRectTests.swift
  • iosApp/iosApp/Networking/Models.swift
  • iosApp/iosApp/Screens/Player/AVPlayerRoute/AVPlayerSurface.swift
  • iosApp/iosApp/Screens/Player/CoreMedia/PlayerSurface.swift
  • iosApp/iosApp/Screens/Player/PlayerView.swift
  • iosApp/iosApp/Screens/Player/PlayerViewModel.swift
  • iosApp/iosApp/Screens/Player/Subtitles/VideoDisplayRect.swift
  • iosApp/iosApp/macOS/AVPlayerSurface.swift
  • iosApp/iosApp/macOS/PlayerSurface.swift
  • iosApp/iosApp/macOS/PlayerView.swift

…itle-inset

# Conflicts:
#	iosApp/iosApp/Screens/Player/AVPlayerRoute/AVPlayerSurface.swift
#	iosApp/iosApp/macOS/AVPlayerSurface.swift
#	iosApp/iosApp/macOS/PlayerSurface.swift
@Quick104

Copy link
Copy Markdown
Contributor

Closing with Silo-Server/silo-server#483. This implementation depends on server-provided static fractions; we want the Apple clients to own detection and layout based on the media they actually render. The client-side geometry and subtitle-placement problem remains valid, but it should be reimplemented without a server-contract dependency and validated across protocol V3 and legacy playback, AVPlayer and CoreMedia, iOS, macOS and tvOS, changing-aspect content, and HDR or protected playback surfaces.

@Quick104 Quick104 closed this Aug 20, 2026
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.

2 participants