我正在开发一个应用程序,其中包括功能,以播放视频与每帧动画。你可以看到一个example这样的功能。
我已经尝试将CAKeyFrameAnimation
添加到AVSynchronizedLayer
的子层,并将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)
}
1条答案
按热度按时间46scxncf1#
我的看法是
将AVPlayer层属性(AVPlayerLayer类)添加到UIView层的子层,然后操作视图动画。
例如,
然后
给予animations to video查看