swift 如何模糊视频特定区域

e3bfsja2  于 2023-03-16  发布在  Swift
关注(0)|答案(1)|浏览(107)

我正在创建一个功能,我们模糊了视频特定的一部分。我有两个视图。一个是显示视频在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)
    }
}

ajsxfq5m

ajsxfq5m1#

看看CIMaskedVariableBlur-它根据遮罩图像中的亮度级别应用模糊。
https://developer.apple.com/library/archive/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/filter/ci/CIMaskedVariableBlur

相关问题