gpt4 book ai didi

ios - AVPlayer 帧动画

转载 作者:行者123 更新时间:2023-12-05 00:22:25 26 4
gpt4 key购买 nike

我正在开发一个应用程序,其中包括使用每帧动画播放视频的功能。
您可以看到 example这样的功能。

我已经尝试添加 CAKeyFrameAnimationAVSynchronizedLayer 的子层并拥有 some troubles用它。

我也已经尝试使用 AVAssetExportSession 预渲染视频,并且运行良好。但这很慢。渲染此类视频最多需要 3 分钟。

也许还有其他方法可以做到这一点?

更新:

这就是我使用 AVSynchronizedLayer 实现动画的方式:

let fullScreenAnimationLayer = CALayer()
fullScreenAnimationLayer.frame = videoRect
fullScreenAnimationLayer.geometryFlipped = true

values: [NSValue] = [], times: [NSNumber] = []

// fill values array with positions of face center for each frame
values.append(NSValue(CATransform3D: t))

// fill times with corresoinding time for each frame
times.append(NSNumber(double: (Double(j) / fps) / videoDuration)) // where fps = 25 (according to video file fps)

...

let transform = CAKeyframeAnimation(keyPath: "transform")
transform.duration = videoDuration
transform.calculationMode = kCAAnimationDiscrete
transform.beginTime = AVCoreAnimationBeginTimeAtZero
transform.values = values
transform.keyTimes = times
transform.removedOnCompletion = false
transform.fillMode = kCAFillModeForwards
fullScreenAnimationLayer.addAnimation(transform, forKey: "a_transform")

...

if let syncLayer = AVSynchronizedLayer(playerItem: player.currentItem) {
syncLayer.frame = CGRect(origin: CGPointZero, size: videoView.bounds.size)
syncLayer.addSublayer(fullScreenAnimationLayer)
videoView.layer.addSublayer(syncLayer)
}

最佳答案

以下是我的看法,
将 AVPlayer 层属性(AVPlayerLayer 类)添加到 UIView 层的子层,然后操作 View 动画。
例如,

AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:blahURL options:nil];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:urlAsset];
AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
playerLayer.frame = yourFrame;

UIView *videoView = [UIView new];
[videoView addSublayer:playerLayer];
然后
给videoView动画

关于ios - AVPlayer 帧动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32121361/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com