Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

player background blur effect #66

Open
Trushangpatel3993 opened this issue Mar 4, 2021 · 2 comments
Open

player background blur effect #66

Trushangpatel3993 opened this issue Mar 4, 2021 · 2 comments

Comments

@Trushangpatel3993
Copy link

Currently, I am trying with this function but not getting proper resolution

open func newRenderedPixelBufferForRequest(request: AVAsynchronousVideoCompositionRequest) -> CVPixelBuffer? {

 guard let outputPixels = renderContext?.newPixelBuffer() else { return nil }
 guard let instruction = request.videoCompositionInstruction as? VideoCompositionInstruction else {
     return nil
  }
 var image = CIImage(cvPixelBuffer: outputPixels)

 // Background
 let backgroundImage = CIImage(color: instruction.backgroundColor).cropped(to: image.extent)
 image = backgroundImage.composited(over: image)

 if let destinationImage = instruction.apply(request: request) {
     image = destinationImage.composited(over: image)
 }
 VideoCompositor.ciContext.render(image, to: outputPixels)

return outputPixels
}

@Trushangpatel3993
Copy link
Author

Anyone can help me with this.

@Trushangpatel3993 Trushangpatel3993 changed the title How we can blur the background in a player player background blur effect Mar 7, 2021
@Alexey-Matjuk
Copy link

In my case I added blurred background of a first frame like this:

let timeline = Timeline()
...
let blurredFirstFrame: CIImage = ...
timeline.passingThroughVideoCompositionProvider = BackgroundComposition(backgroundImage: blurredFirstFrame)
import AVFoundation
import VFCabbage

final class BackgroundComposition: VideoCompositionProvider {

    let backgroundImage: CIImage

    init(backgroundImage: CIImage) {
        self.backgroundImage = backgroundImage
    }

    func applyEffect(
        to sourceImage: CIImage,
        at time: CMTime,
        renderSize: CGSize
    ) -> CIImage {
        sourceImage.composited(over: backgroundImage)
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants