使用PhotoEffectNoir过滤器在swift中使用PBJVideoPlayer pod播放视频

时间:2016-10-15 18:17:13

标签: ios swift avfoundation pbjvision

我正在尝试将黑白效果添加到播放中使用swift中的PBJVideoPlayer pod的视频中。我已将其设置为用户可以点按按钮以应用过滤器。我想我的问题是因为我不确定AVVIdeoComposition的模拟对于pod来说是什么。任何见解都将不胜感激。

@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()

    */


}

1 个答案:

答案 0 :(得分:0)

我在将任何CIPhotoEffect应用于视频方面遇到了问题。其他过滤器似乎工作正常。