Apply Core Image Filter to Video on OS X using Swift

﹥>﹥吖頭↗ 提交于 2019-12-06 14:58:43

Actually I figured it out.. This is a solution that requires OS X El Capitan or later..

let url = NSBundle.mainBundle().URLForResource("skies", withExtension: "mp4”)!


        let avAsset =  AVAsset(URL: url)
        
       
        
        let vidComp = AVVideoComposition(asset: avAsset,
            applyingCIFiltersWithHandler: {
            
            request in

            self.image = request.sourceImage.imageByClampingToExtent();
                
         
                
           self.image = (self.image!.imageByApplyingFilter("CIGaussianBlur”,  withInputParameters: [kCIInputRadiusKey: self.blurTestSlider.integerValue])
            
            self.image = self.image!.imageByCroppingToRect(request.sourceImage.extent)
                        
            request.finishWithImage(self.image!, context: self.context)
            
            })
        
        
        let playerItem = AVPlayerItem(asset: avAsset)
        playerItem.videoComposition = vidComp
         player = AVPlayer(playerItem: playerItem)
        
        
        dTMediaViewControllerA?.player = player
         dTMediaViewControllerA?.player.play()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!