Add text layer to video at specific time

I want to add a text layer to the video during the last 4 seconds of the video. This is what I have so far:

// 1 - Set up the watermark text layer
    CATextLayer *waterMarkText = [[CATextLayer alloc] init];
    [waterMarkText setFont:@"Helvetica-Neue"];
    [waterMarkText setFontSize:30];
    [waterMarkText setFrame:CGRectMake(0, 0, self.size.width, 80)];
    [waterMarkText setString:@"made with Videofy"];
    [waterMarkText setAlignmentMode:kCAAlignmentRight];
    [waterMarkText setForegroundColor:[[UIColor whiteColor] CGColor]];

//Fade In the watermark
    CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];

    fadeInAnimation.duration = 2;
    fadeInAnimation.fromValue = [NSNumber numberWithFloat:0.0];
    fadeInAnimation.toValue = [NSNumber numberWithFloat:1.0];
    fadeInAnimation.beginTime = videoDuration - 4;
    fadeInAnimation.removedOnCompletion = NO;
    [overlayLayer addAnimation:fadeInAnimation forKey:@"animateOpacity"];

      

The animation is added to the final video, but the watermark is displayed from the very beginning of the video. How do I set the opacity to 0 before the animation starts?

(I tried to set the opacity of the Text watermark to 0, but it seems to override the animation.)

+3


source to share





All Articles