AVVideoCompositionCoreAnimationTool with Core Animation layer as track input

I am using a

AVVideoCoreAnimationTool

to render titles on top of a video composition.


I used to use

+videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:inLayer:

to instantiate the animation tool.


However, I now need to use a custom compositor to render the video composition. I want to use

videoCompositionCoreAnimationToolWithAdditionalLayer:asTrackID:

so that I have access to an asset track with the titles in my compositor.


However, I can't get titles to render when adding the core animation layer as a track.

In my custom compositor I have access to the track, i.e. I can get a pixelBuffer for the trackID I have assigned for the Core Animation layer when instantiating the animation tool. But these pixel buffers are empty.


- (void)startVideoCompositionRequest:(AVAsynchronousVideoCompositionRequest *)request
{
     CMPersistentTrackID titleTrackID = ...
     CVPixelBufferRef titlePixelBuffer = [request sourceFrameByTrackID:titleTrackID];
     //titlePixelBuffer is valid pixel buffer but never contains any pixel data
}


When I set up the core animation tool the same way, but don't use a custom compositor, the title layer also isn't rendered.

If I set up the animation tool using

+videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:inLayer:

and don't use a custom compositor the title layer is rendered as it should.


Is there anything I'm missing?

(I am also adding the sourceTrackID of the title track to the composition's AVVideoCompositionInstruction instances)

I was able to get this to work with the code below:


-(AVVideoCompositionCoreAnimationTool *) createAnimationToolForSize:(CGSize) size {
  
    CATextLayer *titleLayer = [CATextLayer layer];
    titleLayer.string = @"Text goes here";
    titleLayer.font = (__bridge CFTypeRef)(@"Helvetica");
    titleLayer.fontSize = size.height / 20;
    titleLayer.cornerRadius = size.height / 50;
    titleLayer.foregroundColor = [UIColor blackColor].CGColor;
    titleLayer.backgroundColor = [UIColor whiteColor].CGColor;
    titleLayer.frame = CGRectMake(size.width/4, size.height/4, size.width/2, size.height/2 );
    titleLayer.opacity = .5;   
    return [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithAdditionalLayer:titleLayer asTrackID:5];
}

_videoComposition.animationTool = [self createAnimationToolForSize:CGSizeMake(1280, 720)];


In my customcompositorclass, I correctly get the pixel buffers from that track and can display the text.

I have meet problem same with your correctly, Have you solved this problem? Any help will be appreciate very much.

AVVideoCompositionCoreAnimationTool with Core Animation layer as track input
 
 
Q