Is there any quick, easy way to apply CIFilterto videos? Before he mentioned, I looked at GPUImage - it looks like very powerful magic code, but it really went too far for what I'm trying to do.
Essentially, I would like
- Take a video file, say, saved in
/tmp/myVideoFile.mp4 - Apply
CIFilterto this video file - Save the video file in another (or the same) place, say
/tmp/anotherVideoFile.mp4
I was able to apply CIFilter to a video that plays very easily and quickly with AVPlayerItemVideoOutput
let player = AVPlayer(playerItem: AVPlayerItem(asset: video))
let output = AVPlayerItemVideoOutput(pixelBufferAttributes: nil)
player.currentItem?.addOutput(self.output)
player.play()
let displayLink = CADisplayLink(target: self, selector: #selector(self.displayLinkDidRefresh(_:)))
displayLink.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSRunLoopCommonModes)
func displayLinkDidRefresh(link: CADisplayLink){
let itemTime = output.itemTimeForHostTime(CACurrentMediaTime())
if output.hasNewPixelBufferForItemTime(itemTime){
if let pixelBuffer = output.copyPixelBufferForItemTime(itemTime, itemTimeForDisplay: nil){
let image = CIImage(CVPixelBuffer: pixelBuffer)
}
}
}
, . , , AVPlayer, , . , , .
- :
var newVideo = AVMutableAsset()
var originalVideo = AVAsset(url: NSURL(urlString: "/example/location.mp4"))
originalVideo.getAllFrames(){(pixelBuffer: CVPixelBuffer) -> Void in
let image = CIImage(CVPixelBuffer: pixelBuffer)
.imageByApplyingFilter("Filter", withInputParameters: [:])
newVideo.addFrame(image)
}
newVideo.exportTo(url: NSURL(urlString: "/this/isAnother/example.mp4"))
( , GPUImage iOS 7), , ? , , AVAsset, CIFilter, .