Text of developer.apple.com › forums › thread › 821582 as Styx crawled it on Nov 20, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

AVPictureInPictureController with … | Apple Developer Forums

AVPictureInPictureController with AVSampleBufferDisplayLayer: Video not scaled in PiP window on macOS Media Technologies General AVKit AVFoundation You’re now watching this thread. If you’ve opted in to email or web notifications, you’ll be notified when there’s activity. Click again to stop watching or visit your profile to manage watched threads and notifications. You’ve stopped watching this thread and will no longer receive emails or web notifications when there’s activity.

Click again to start watching. OliverS79 OP Created Apr ’26 Replies 3 Boosts 0 Views 1.4k Participants 1 AVPictureInPictureController with AVSampleBufferDisplayLayer: Video not scaled in PiP window on macOS Platform: macOS 26.4 (Tahoe) Framework: AVKit / AVFoundation Xcode: 26.4 Summary When using AVPictureInPictureController with ContentSource(sampleBufferDisplayLayer:playbackDelegate:) on macOS, the video content in the PiP window is not scaled to fit — it renders at 1:1 pixel resolution, showing only the bottom-left portion of the video (zoomed/cropped).

The same code works correctly on iOS. Setup let displayLayer = AVSampleBufferDisplayLayer() displayLayer.videoGravity = .resizeAspect // Host displayLayer as a sublayer of an NSView, enqueue CMSampleBuffers let source = AVPictureInPictureController.ContentSource( sampleBufferDisplayLayer: displayLayer, playbackDelegate: self ) let pip = AVPictureInPictureController(contentSource: source) pip.delegate = self The source display layer is 1280×720, matching the video stream resolution.

PiP starts successfully — isPictureInPicturePossible is true, the PiP button works, and the PIPPanel window appears. However, the video in the PiP window (~480×270) shows only the bottom-left 480×270 pixels of the 1280×720 content, rather than scaling the full frame to fit. Investigation Inspecting the PiP window hierarchy reveals: PIPPanel (480×270) └─ AVPictureInPictureSampleBufferDisplayLayerView └─ AVPictureInPictureSampleBufferDisplayLayerHostView (layer = CALayerHost) └─ AVPictureInPictureCALayerHostView The CALayerHost mirrors the source AVSampleBufferDisplayLayer at 1:1 pixel resolution.

Unlike AVPlayerLayer -based PiP (which works correctly on macOS), the sample buffer display layer path does not apply any scaling transform to the mirrored content. On iOS, PiP with AVSampleBufferDisplayLayer works correctly because the system reparents the layer into the PiP window, so standard layer scaling applies. On macOS, the system uses CALayerHost mirroring instead, and the scaling step is missing. What I tried (none fix the issue) Setting autoresizingMask on all PiP internal subviews — views resize correctly, but CALayerHost content remains at 1:1 pixel scale Applying CATransform3DMakeScale on the CALayerHost layer — creates a black rectangle artifact; the mirrored content does not transform Setting CALayerHost.bounds to the source layer size — no effect on rendering Reparenting the internal AVPictureInPictureCALayerHostView out of the host view — video disappears entirely Hiding the CALayerHost — PiP window goes white (confirming it is the sole video renderer) Resizing the source AVSampleBufferDisplayLayer to match the PiP window size — partially works (1:1 mirror of a smaller source fits), but causes visible lag during resize, affects the main window's "This video is playing in Picture in Picture" placeholder, and didTransitionToRenderSize stops being called after the initial resize Expected behavior The video content should be scaled to fit the PiP window, respecting the display layer's videoGravity setting ( .resizeAspect ), consistent with: iOS PiP with AVSampleBufferDisplayLayer (works correctly) macOS PiP with AVPlayerLayer (works correctly) Environment macOS 26.4 (Tahoe) Xcode 26.4 Apple Silicon (M-series) Retina display (contentsScale = 2.0) Video: H.264 1280×720, hardware decoded via VTDecompressionSession, enqueued as CMSampleBuffer Replies 3 Boosts 0 Views 1.4k Participants 1 OliverS79 OP Apr ’26 Additional finding: I looked at how IINA (open-source macOS media player, github.com/iina/iina) implements PiP.

They use Apple's private PIP.framework (PIPViewController), which physically reparents the video view into the PiP window — and their PiP works perfectly. This confirms the root cause: PiP works when the view/layer is reparented (private PIPViewController on macOS, public API on iOS), but fails when using CALayerHost mirroring (the public AVPictureInPictureController + AVSampleBufferDisplayLayer path on macOS). The fix would be either: Reparent the AVSampleBufferDisplayLayer into the PiP window (as iOS already does), or Apply a scaling transform to the CALayerHost mirror content to fit the PiP window bounds Add comment OliverS79 OP Apr ’26 Update — Private PIP.framework also affected I tested an alternative approach using Apple's private PIP.framework (PIPViewController), which physically reparents the source NSView into the PiP window — unlike AVPictureInPictureController, which mirrors via CALayerHost.

The result is identical: the PiP window shows only the bottom-left portion of the video at 1:1 pixel resolution, without scaling to fit the window bounds. This confirms the issue is with AVSampleBufferDisplayLayer itself, not with how the PiP window is created. The layer does not honour its videoGravity or respond to frame/bounds changes when hosted inside a PiP window on macOS. The same layer scales correctly in regular windows and works correctly on iOS.

For reference, apps like IINA that use PIPViewController with Metal/OpenGL rendering views work fine — the problem is specific to AVSampleBufferDisplayLayer. This affects any macOS app using AVSampleBufferDisplayLayer for custom streaming (IPTV, HLS demuxers, hardware-decoded pipelines via VTDecompressionSession) that wants to support Picture in Picture. Filed as FB22411168 . Add comment OliverS79 OP Apr ’26 Update — Working workaround found After extensive debugging, I found a two-part workaround that gives fully functional PiP with AVSampleBufferDisplayLayer on macOS.

Root cause analysis The PiP window actually contains TWO stacked rendering paths: PIPPanel (contentView: 484×272) └─ AVPictureInPictureSampleBufferDisplayLayerView (1280×720) └─ AVPictureInPictureSampleBufferDisplayLayerHostView (layer = CALayerHost, contentsScale = 1.0) ├─ AVSampleBufferDisplayLayerContentLayer (734×413) ← correctly scaled video └─ AVPictureInPictureCALayerHostView (1600×900) ← broken overlay The "good" path (AVSampleBufferDisplayLayerContentLayer) renders the video correctly scaled to the PiP window size.

The "bad" path (AVPictureInPictureCALayerHostView) is drawn ON TOP and is the source of all the visual problems. Inspecting its properties reveals: hasContents = false, sublayers = 0 — it contains no actual video content backgroundColor = solid black (CGColor gray=0, alpha=1) transform = [m11=0.8, m22=0.8, m33=0.8] — Apple applies a scale transform, but since there's no content, it just draws a scaled black rectangle contentsScale = 2.0 (while its parent CALayerHost has contentsScale = 1.0 — a retina mismatch) This view appears to be a leftover from the AVPlayerLayer PiP code path where the CALayerHost mirror is the primary renderer.

For AVSampleBufferDisplayLayer, the mirroring is never set up (0 sublayers, no contents), but the view is still displayed with its black background. Workaround (two parts) Part A — Resize the source window to match PiP content size: The "good" content layer also copies pixels at 1:1 resolution. If the source window is larger than the PiP window, only the bottom-left corner is visible. Fix: resize the player window to match the PiP content dimensions (hidden with alphaValue = 0), and track PiP window resizes via NSView.frameDidChangeNotification to stay in sync. func pictureInPictureControllerDidStartPictureInPicture(_ pip: AVPictureInPictureController) { guard let windo

The rest of this page is on the live site.