AVCaptionRenderer

Has anybody successfully used AVCaptionRenderer for anything?

I am attempting to preview what AVMutableCaptions will look like by using AVCaptionRenderer. I am able to render an image with the caption (very small in the lower left corner), but changes to text properties are not having any effect.

I have tried the following: setBackgroundColor - No effect. setFontStyle - No Effect. textAlignment - No effect.

I'm beginning to think that AVCaptionRender isn't what I think it's for. The documentation is sparse, the mention in the WWDC video is brief, and I can't find any sample code.

The video mentions reaching out here for help adopting these APIs, so here I am.

WWDC Video Mention: https://developer.apple.com/videos/play/wwdc2021-10146/?time=943

Are you mutating the caption after you've already passed it to the renderer, or are you mutating the caption and then sending it to the renderer again?

To answer your question: I am instantiating AVMutableCaption, modifying it and then supplying it to the AVCaptionRenderer. I am just using a playground right now, so each run is a new caption and renderer. The caption is not modified or used after renderer.

I was able to get backgroundColor and fontStyle to work.

  1. AVCaptionRenderer - Modifying the render bounds has very unexpected results. I expect that the text is rendered in the supplied bounds. Instead the text seems to always be rendered at (0,0).
  2. AVMutableCaption.setFontWeight has no effect.
  3. AVMutableCaption.setDecoration(.lineThrough, ...) has no effect.
  4. AVMutableCaption.textAlignment has no effect.
  5. Changing the AVMutableCaption.region causes the text to not render at all.

I can supply some playgrounds that demonstrate these problems if you like.

AVCaptionRenderer is probably the most sparsely documented API I have ever seen. I can't imagine that it is actually being used by anybody in it's current state.

AVCaptionRenderer
 
 
Q