是否可以在Swift3 iOS的视频文件中添加滤镜效果

时间:2018-03-12 12:19:25

标签: ios swift video avfoundation cifilter

我正在用Swift3语言开发视频编辑类应用程序我在哪里合并多个视频..设置自定义背景声音,WaterMark和Fade In&使用AVFoundation框架淡出效果到最终合并视频。

现在我的问题是我需要在视频中添加Warm, cold, sepia/vintage等过滤效果...这是否可以使用内置库在Swift iOS中添加此类效果?我在谷歌搜索过但无法找到合适的解决方案:

RGB range for cold and warm colors?

http://flexmonkey.blogspot.in/2016/04/loading-filtering-saving-videos-in-swift.html

How to create and add video filter like Instagram using AVFoundation framework - Swift programming

https://developer.apple.com/library/content/samplecode/RosyWriter/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011110

请告诉我。谢谢!

编辑:

我尝试使用下面的代码,但它不起作用。

let filter = CIFilter(name: "CISepiaTone")!
        let composition = AVVideoComposition(asset: firstAsset, applyingCIFiltersWithHandler: { request in


            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)


            let output = filter.outputImage!.cropping(to: request.sourceImage.extent)

            // Provide the filter output to the composition
            request.finish(with: output, context: nil)
        })

0 个答案:

没有答案