0

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

HangarRash
  • 7,314
  • 5
  • 5
  • 32

1 Answers1

0

Take a look at CIMaskedVariableBlur - it applies blur based on the brightness levels in a mask image.

https://developer.apple.com/library/archive/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/filter/ci/CIMaskedVariableBlur

Flex Monkey
  • 3,583
  • 17
  • 19