苹果文档给出了一个将 CIFilter 应用到 AVAsset 的示例:
let filter = CIFilter(name: "CIGaussianBlur")!
let composition = AVVideoComposition(asset: asset, applyingCIFiltersWithHandler: { request in
// Clamp to avoid blurring transparent pixels at the image edges
let source = request.sourceImage.clampingToExtent()
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!.cropping(to: request.sourceImage.extent)
// Provide the filter output to the composition
request.finish(with: output, context: nil)
})
这在某些视频上效果很好(使用AAC编解码器的视频似乎更具性能),而在其他视频上,CPU使用率飙升,视频处理从未完成。是否有一种方法将其移至GPU以加速处理/减少CPU占用?我在iOS中看到这个问题,但OS X上没有
CIContext contextWithEAGLContext:
。我对AVFoundation /视频处理不熟悉,在OS X上是否有相应的功能?注意:我不希望实时进行此操作,我只想使用GPU应用滤镜并将文件导出到文件系统。