Skip to content

fix(avfoundation): pass the pixel aspect ratio to the display layer - #5

Open
morganp wants to merge 1 commit into
streamyfin:avfoundation-ao-tvosfrom
morganp:fix/pixel-aspect-ratio
Open

morganp wants to merge 1 commit into
streamyfin:avfoundation-ao-tvosfrom
morganp:fix/pixel-aspect-ratio

Conversation

@morganp

@morganp morganp commented Oct 29, 2026 •

Copy link
Copy Markdown

Description

Anamorphic video plays squashed on iOS. A 720x480 DVD style rip flagged 16:9 is drawn at its stored 3:2 shape, because the avfoundation video output builds each sample buffer from the decoded pixels alone and never tells AVSampleBufferDisplayLayer how wide a pixel is.

This attaches kCVImageBufferPixelAspectRatioKey (from the frame's p_w and p_h) to the pixel buffer before the format description is created, on both the plain path and the composited subtitle path. The layer then stretches the frame to its display aspect, so fit, fill and picture in picture follow without any app change. Frames with square pixels, or no pixel aspect, are left alone.

Reported in the app repo: streamyfin/streamyfin#2369 (Swiftfin shows the same file correctly, Streamyfin does not).

The change is one helper, set_pixel_aspect(), and two calls, all inside 0004-avfoundation-video-output.patch. I also corrected the new file hunk header (+1,1311) to match.

How it was tested

  • The edited patch applies cleanly after patches 0001 to 0003 on a fresh mpv v0.41.0 checkout.
  • The helper compiled and run on its own sets HorizontalSpacing=32, VerticalSpacing=27 on a real CVPixelBuffer.
  • A local iOS only build of MPVKit with this patch, linked into Streamyfin and installed on an iPad Air (M2). Six generated test clips (NTSC and PAL, 16:9 and 4:3 anamorphic, a square pixel control, and an interlaced MPEG-2 .mkv) all show a round circle and a square box. Before the patch the anamorphic ones were squashed.
  • On the same iPad build: zoom to fill, picture in picture and external subtitles on the anamorphic clips all look right (round circle, correct shape, subtitles inside the picture).

Not verified

  • A full CI build of this branch, including tvOS (my build was iOS only, and the combine script stops at the missing tvOS slice).
  • Subtitle placement was only checked by eye. The app side subtitle canvas still reads the stored video size, so a precise check on a very different aspect may be worth a follow up.
  • Anything other than iOS on the iPad: other devices, tvOS and Mac Catalyst.
  • Real DVD rips. Only generated clips were used.
  • Whether interlaced sources still show combing. That is a separate issue.

Using this needs a new release tag and a podspec bump in the app, so this does not close the app issue by itself.

AI assisted: drafted and tested with Claude Code.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BsaHcCXUsC4JTpKgBe2AgJ

Anamorphic sources store non-square pixels (a 720x480 DVD rip flagged
16:9). The video output built each sample buffer from the stored size
alone, so AVSampleBufferDisplayLayer drew them squeezed. Attach
kCVImageBufferPixelAspectRatioKey from the frame's p_w and p_h, on both
the plain and the composited path. Square pixel frames are left alone.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BsaHcCXUsC4JTpKgBe2AgJ
@coderabbitai

coderabbitai Bot commented Oct 29, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: c341709f-e4b6-4030-9117-9c6df1b15276

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • 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.

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.

1 participant