0

I am trying to add the black and white effect to a video in playback that uses the PBJVideoPlayer pod in swift. I have it set up so a user can tap a button in order to apply the filter. I suppose my issue comes because i am not sure what the analog for AVVIdeoComposition would be for the pod. Any insight would be appreciated.

@IBAction func filterTapped(sender: UIButton) {


    switch self.media! {
    case .Photo(let image): self.blackAndWhiteFilterForImage(image)

    case .Video(let url): self.createBlackAndWhiteFilterForVideo(url)

    }




}


func createBlackAndWhiteFilterForVideo(url: NSURL){

        //B&W Filter for Video

        let asset = AVAsset(URL: url)
        let filter = CIFilter(name: "CIPhotoEffectNoir")!
        let composition = AVVideoComposition(asset: asset, applyingCIFiltersWithHandler: { request in

            // Clamp to avoid blurring transparent pixels at the image edges
            let source = request.sourceImage.imageByClampingToExtent()
            filter.setValue(source, forKey: kCIInputImageKey)

            // Vary filter parameters based on video timing
            let seconds = CMTimeGetSeconds(request.compositionTime)
            filter.setValue(seconds * 10.0, forKey: kCIInputRadiusKey)

            // Crop the blurred output to the bounds of the original image
            let output = filter.outputImage!.imageByCroppingToRect(request.sourceImage.extent)

            // Provide the filter output to the composition
            request.finishWithImage(output, context: nil)


        })
       //Everything below this code is where I am unsure how to proceed 
        let playerItem = playerController.asset
    print(playerItem)

    /*

        playerItem.comp

        let player = AVPlayer(playerItem: playerItem)


        player.play()

    */


}
Onicha21
  • 141
  • 2
  • 11

1 Answers1

0

I've had issues applying any of the CIPhotoEffects to video. Other filters seem to work just fine.

Patrick Tescher
  • 3,387
  • 1
  • 18
  • 31