ios - CFBasicAnimation 中带有自定义键的动画在导出视频时不起作用

标签 ios video export

我有 FrameChangeAnimation 类,它需要多个 Sprite 表和持续时间。假设我有 3 个 Sprite 表,每个 Sprite 表包含 16 个字符 block ,然后我给出“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];

最佳答案

根据 AVVideoCompositionCoreAnimationTool 类的文档,

“任何动画都将在视频时间轴上解释,而不是实时解释,因此您应该:

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

关于ios - CFBasicAnimation 中带有自定义键的动画在导出视频时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10448482/

相关文章:

ios - 如何在不重置 SCNNode 位置的情况下重置 SCNNode 的 SCNPhysicsBody?

javascript - 为视频添加静音按钮

java - 错误的类格式将包从 Java 7 构建到 Java 8

Android结合两个视频覆盖另一个

PHP/FFMPEG - 为什么我的视频转换会导致空文件?

Mysql导出数据的问题

export - 是否有用于从问题跟踪器导出问题的标准文件格式?

iphone - 如何更改 XCode xib 中的堆叠顺序或对象?

objective-c - Objective-C 语言中需要的句法理解

ios - CGImageDestinationCreateWithURL 的问题