2

我有 FrameChangeAnimation 类,它需要多个精灵表和持续时间。所以假设我有 3 个 spritesheet,每个包含 16 个字符块,然后我给 '3' 秒作为持续时间。在将 FrameChangeAnimation 实例作为 CALayer 返回后,我将其附加到屏幕上,并且播放流畅 [16 帧/秒]

现在我想将此动画导出为视频。问题是,当我这次附加 CABasicAnimation 时,持续时间。“持续时间”参数不起作用,所有帧都在一秒钟内播放。

    GTAnimation *an = [[GTAnimation alloc] initWithFrame:CGRectMake(0, 0, videoSize.width, videoSize.height) withFileName:@"Host_Angry_" withSeconds:3.5];

    CALayer *animationLayer = [CALayer layer];
    animationLayer.bounds = CGRectMake(0, 0, videoSize.width, videoSize.height);
    [animationLayer addSublayer:an.animLayer];

    CABasicAnimation *fadeAnimation = [CABasicAnimation animationWithKeyPath:@"currentFrame"];
    fadeAnimation.fromValue = [NSNumber numberWithFloat:1.0];
    fadeAnimation.toValue = [NSNumber numberWithFloat:45.0];
    fadeAnimation.additive = NO;
    fadeAnimation.removedOnCompletion = NO;
    fadeAnimation.beginTime = 0.0;
    fadeAnimation.duration = 3.5;
    fadeAnimation.repeatCount = HUGE_VAL;
    fadeAnimation.fillMode = kCAFillModeBoth;
    [an.animLayer addAnimation:fadeAnimation forKey:@"currentFrame"];

    CALayer *parentLayer = [CALayer layer];
    CALayer *videoLayer = [CALayer layer];

    videoLayer.bounds = CGRectMake(0, 0, videoSize.width, videoSize.height);
    [parentLayer addSublayer:videoLayer];
    [parentLayer addSublayer:animationLayer];
    videoLayer.anchorPoint =  CGPointMake(0.5, 0.5);
    videoLayer.position = CGPointMake(CGRectGetMidX(parentLayer.bounds), CGRectGetMidY(parentLayer.bounds));
    animationLayer.anchorPoint =  CGPointMake(0.5, 0.5);
    animationLayer.position = CGPointMake(CGRectGetMidX(parentLayer.bounds), CGRectGetMidY(parentLayer.bounds));
    videoComposition.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
4

2 回答 2

4

根据 AVVideoCompositionCoreAnimationTool 类的文档,

“任何动画都会在视频的时间线上进行解释,而不是实时的,所以你应该:

将动画的 beginTime 属性设置为 1e-100 而不是 0(CoreAnimation 用 CACurrentMediaTime 替换);

于 2012-06-16T23:47:51.077 回答
1

使用 AVCoreAnimationBeginTimeAtZero 而不是做 fadeAnimation.begintime = 0.0;

fadeAnimation = AVCoreAnimationBeginTimeAtZero;
于 2013-12-23T11:46:25.913 回答