【问题标题】:Force Redraw of AVPlayerLayer when it is paused on iOS 13在 iOS 13 上暂停时强制重绘 AVPlayerLayer
【发布时间】:2019-08-21 04:02:28
【问题描述】:

我使用 CoreImage 将实时效果应用于使用 AVPlayer 播放的视频。问题是当播放器暂停时,如果您使用滑块调整过滤器参数,则不会应用过滤器。

  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)
    })

作为一种解决方法,我使用了在 iOS 12.4 之前有效的 this 答案,但在 iOS 13 beta 6 中不再有效。寻找适用于 iOS 13 的解决方案。

【问题讨论】:

  • 你试过player.seek(to: player.currentTime())吗?
  • 是的。也不行。
  • 嗯,棘手...您是否尝试过取消设置并重新设置playerItem

标签: ios avfoundation avplayer core-image cifilter


【解决方案1】:

在将此作为错误报告给 Apple 并获得一些有用的反馈后,我进行了修复:

player.currentItem?.videoComposition = player.currentItem?.videoComposition?.mutableCopy() as? AVVideoComposition

我得到的解释是:

当 AVPlayerItem 的 videoComposition 属性获得一个新实例,或者即使是同一个实例,该实例的某个属性已被修改时,AVPlayer 会重绘一个帧。

因此;只需复制现有实例即可通过创建“新”实例来强制重绘。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-28
    • 1970-01-01
    • 2015-11-19
    • 2020-03-28
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    • 2010-10-09
    相关资源
    最近更新 更多