我正在使用Swift编程处理AVFoundation框架。有人可以帮我找一些教程或链接或代码片段来应用类似于Instagram的视频过滤器。
我正在使用iOS视频创建器类型的应用程序来录制视频,之后我可以将过滤器应用于视频。
提前致谢。
答案 0 :(得分:0)
您应该查看Apple的示例项目RosyWriter。它是你想要实现的一个很好的例子。
此外,您还可以查看GLImageProcessing示例项目。
https://developer.apple.com/library/ios/samplecode/GLImageProcessing/Introduction/Intro.html
希望有所帮助!
答案 1 :(得分:0)
从iOS 9.0开始,您可以使用AVVideoComposition逐帧应用核心图像过滤器。
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.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)
// Clamp to avoid blurring transparent pixels at the image edges
let source = request.sourceImage.clampedToExtent()
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!.cropped(to: request.sourceImage.extent)
request.finish(with: output, context: nil)
})
现在我们可以使用之前创建的资产创建AVPlayerItem并使用AVPlayer
播放它let playerItem = AVPlayerItem(asset: asset)
playerItem.videoComposition = composition
let player = AVPlayer(playerItem: playerItem)
player.play()
核心图像过滤器逐帧实时添加。您还可以使用AVAssetExportSession类导出视频。
这里是WWDC 2015的精彩介绍: https://developer.apple.com/videos/play/wwdc2015/510/?time=1222