Ios 如何使用AVFoundation framework创建和添加Instagram等视频过滤器-Swift编程

Ios 如何使用AVFoundation framework创建和添加Instagram等视频过滤器-Swift编程,ios,swift,video,filter,instagram,Ios,Swift,Video,Filter,Instagram,我正在使用Swift编程开发AVFoundation框架。有人能帮我找到一些教程、链接或代码片段来应用类似Instagram的视频过滤器吗 我正在开发一款iOS视频制作软件,它可以录制视频,以后我可以对视频应用过滤器 提前谢谢 你应该看看苹果的RosyWriter示例项目。这是你想要实现的一个很好的例子 此外,您还可以查看GLImageProcessing示例项目 希望有帮助 自iOS 9.0以来,您可以使用AVVideoComposition将核心图像过滤器逐帧应用于视频 let filt

我正在使用Swift编程开发AVFoundation框架。有人能帮我找到一些教程、链接或代码片段来应用类似Instagram的视频过滤器吗

我正在开发一款iOS视频制作软件,它可以录制视频,以后我可以对视频应用过滤器


提前谢谢

你应该看看苹果的RosyWriter示例项目。这是你想要实现的一个很好的例子

此外,您还可以查看GLImageProcessing示例项目


希望有帮助

自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的精彩介绍:

您找到解决方案了吗?请分享你有什么办法可以在视频中添加过滤效果吗?有没有办法用你自己的过滤器代替苹果的?我有CALayer,我想在录制视频时将其覆盖在视频上。