问题描述
我正在尝试对视频应用过滤器,然后将其显示在 UIview 上。 但它只应用于一帧,并没有显示在整个视频上。
下面是我的
let filter = CIFilter(name: "CISepiaTone")!
let asset = AVAsset(url: videoURL)
let composition = AVVideoComposition(asset: asset,applyingCIFiltersWithHandler: { request in
// Clamp to avoid blurring transparent pixels at the image edges
let source = request.sourceImage.clampedToExtent()
filter.setValue(source,forKey: kCIInputimageKey)
// Crop the blurred output to the bounds of the original image
let output = filter.outputimage!.cropped(to: request.sourceImage.extent)
// Provide the filter output to the composition
request.finish(with: output,context: nil)
})
let playerItem = AVPlayerItem(asset: asset)
playerItem.videoComposition = composition
let player = AVPlayer(playerItem: playerItem)
let layer: AVPlayerLayer = AVPlayerLayer(player: player)
layer.backgroundColor = UIColor.white.cgColor
layer.frame = CGRect(x: 0,y: 0,width: videoView.frame.width,height: videoView.frame.height)
layer.videoGravity = AVLayerVideoGravity.resizeAspectFill
videoView.layer.sublayers?.forEach({$0.removeFromSuperlayer()})
videoView.layer.addSublayer(layer)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)