我使用 CoreImage 将实时效果应用于使用 AVPlayer 播放的视频。问题是当播放器暂停时,如果您使用 slider 调整过滤器参数,则不会应用过滤器。
let videoComposition = AVMutableVideoComposition(asset: asset, applyingCIFiltersWithHandler: {[weak self] request in
// Clamp to avoid blurring transparent pixels at the image edges
let source = request.sourceImage.clampedToExtent()
let output:CIImage
if let filteredOutput = self?.runFilters(source, filters: array)?.cropped(to: request.sourceImage.extent) {
output = filteredOutput
} else {
output = source
}
// Provide the filter output to the composition
request.finish(with: output, context: nil)
})
作为解决方法,我使用了 this在 iOS 12.4 之前有效的答案,但在 iOS 13 beta 6 中不再适用。寻找适用于 iOS 13 的解决方案。
最佳答案
在将此作为错误报告给 Apple 并获得一些有用的反馈后,我有一个修复程序:
player.currentItem?.videoComposition = player.currentItem?.videoComposition?.mutableCopy() as? AVVideoComposition
我得到的解释是:
AVPlayer redraws a frame when AVPlayerItem’s videoComposition property gets a new instance or, even if it is the same instance, a property of the instance has been modified.
因此;可以通过简单地复制现有实例来创建"new"实例来强制重绘。
关于ios - 在 iOS 13 上暂停时强制重绘 AVPlayerLayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57459354/