how to blur specific area of video

76 Views Asked by At

I am creating a function where we blur a video specific part. I have two views. One is for show video in videoview and other view shows the area of blur but area of blur is not placed at the right place.

First of all, I want to blur a specific area of video. What is the right way to do this?

I tried this code:

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

enter image description here

1

There are 1 best solutions below

0
On