添加多个过滤器,以一个单一的视频

时间:2019-01-30 09:44:15

标签: ios swift gpuimage

我正在尝试使用GPUImage2在保存的视频上反复添加滤镜,但是当我应用第二个滤镜时,它会出现以下错误:

  

警告:试图将目标添加到目标的输入容量之外-> Pipeline.swift:addTarget(_:atTargetIndex :):43

和所选择的过滤器不适用。我试图施加任何新的过滤器,但没有作品之前去除过滤器和movieInput目标。

这是我的代码:

var renderView = RenderView()
var movieInput:MovieInput!
var selectedFilter:ImageProcessingOperation!

func startVideoWithFilter(filter:ImageProcessingOperation){
    let bundleURL = Bundle.main.resourceURL!
    let movieURL = URL(string:"fileName.mp4", relativeTo:bundleURL)!

    filter.removeAllTargets()
    selectedFilter.removeAllTargets()

    if movieInput != nil{
        movieInput.removeAllTargets()
    }

    do {
        movieInput = try MovieInput(asset: AVAsset(url: movieURL), playAtActualSpeed: true, loop: true)
        movieInput.addTarget(filter)
        filter.addTarget(renderView)
        movieInput.runBenchmark = true
        movieInput.start()
    } catch {
        print("Couldn't process movie with error: \(error)")
    }

}

1 个答案:

答案 0 :(得分:0)

let vignetteFilter = Vignette()
let toonFilter = ToonFilter()

do {
    movieInput = try MovieInput(asset: AVAsset(url: movieURL), playAtActualSpeed: true, loop: true)
    movieInput --> vignetteFilter --> toonFilter --> renderView
    movieInput.runBenchmark = true
    movieInput.start()
} catch {
    print("Couldn't process movie with error: \(error)")
}