Add a text overlay with AVMutableVideoComposition to a specific timerange

前端 未结 2 557
失恋的感觉
失恋的感觉 2020-12-05 21:57

I have found a few examples that show how to add a text overlay on a video.

Ray\'s Tutorial - http://www.raywenderlich.com/30200/avfoundation-tutorial-adding-overlay

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-05 22:41

    I figured out what I needed to do. It wasn't anything special really. It just required a better understanding of what was all possible.

    Basically all I had to do was add a basic opacity animation to the layer with text in it.

    // My original code for creating the text layer
    CATextLayer *titleLayer = [CATextLayer layer];
    .
    .
    .
    [titleLayer displayIfNeeded];
    
    // the code for the opacity animation which then removes the text
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    [animation setDuration:0];
    [animation setFromValue:[NSNumber numberWithFloat:1.0]];
    [animation setToValue:[NSNumber numberWithFloat:0.0]];
    [animation setBeginTime:1];
    [animation setRemovedOnCompletion:NO];
    [animation setFillMode:kCAFillModeForwards];
    [titleLayer addAnimation:animation forKey:@"animateOpacity"];
    

提交回复
热议问题