如何解决无法对整个视频应用 CIFilter
我正在尝试对视频应用过滤器,然后将其显示在 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 举报,一经查实,本站将立刻删除。