我正在创建一个功能,我们模糊了视频特定的一部分。我有两个视图。一个是显示视频在videoview和其他视图显示模糊的地区,但模糊的地区没有放在正确的地方。
首先,我想模糊视频的一个特定区域。什么是正确的方法来做到这一点?
我试了这个代码:
let asset = AVAsset(url: videoURL!)
titleComposition = AVMutableVideoComposition(asset: asset) { [self] request in
let blurFilter = CIFilter(name: "CIGaussianBlur")
blurFilter?.setValue(request.sourceImage, forKey: kCIInputImageKey)
blurFilter?.setValue(100, forKey: "inputRadius")
let blurImage = blurFilter?.outputImage
DispatchQueue.main.async { [self] in
enter image description here
//blurImage?.applyingGaussianBlur(sigma: 0.8)
let resizedImaged = blurImage?.cropped(to:CGRect(origin: CGPoint(x: blurFrame.origin.x, y: blurFrame.origin.y), size: CGSize(width: blurFrame.width, height: blurFrame.height)))
print("blurView position: \(blurView.frame.origin)")
print("blurView size: \(blurView.frame.size)")
print("resizedImage position: \(String(describing: resizedImaged?.extent.origin))")
print("resizedImage size: \(String(describing: resizedImaged?.extent.size))")
let compositedImage = resizedImaged?.composited(over: request.sourceImage)
request.finish(with: compositedImage!, context: nil)
}
}
1条答案
按热度按时间ajsxfq5m1#
看看
CIMaskedVariableBlur
-它根据遮罩图像中的亮度级别应用模糊。https://developer.apple.com/library/archive/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/filter/ci/CIMaskedVariableBlur