BradLarson / GPUImage2

GPUImage 2 is a BSD-licensed Swift framework for GPU-accelerated video and image processing.
BSD 3-Clause "New" or "Revised" License
4.85k stars 605 forks source link

Warning: tried to add target beyond target's input capacity --> Pipeline.swift #195

Closed pdcarroll closed 6 years ago

pdcarroll commented 6 years ago

I have an application that plays a set of videos (via local file URLs). Each video uses the same GPUImage filters. Once a video playback has ended, it plays the next video from the set.

movieInput?.removeAllTargets()
movieInput = try MovieInput(url: movieURL, playAtActualSpeed: true)
movieInput --> greyscaleFilter --> invertFilter --> renderView
movieInput.start()

playbackTimer = Timer.scheduledTimer(
    timeInterval: CMTimeGetSeconds(movieAsset.duration),
    target: self,
    selector: #selector(handlePlaybackFinished),
    userInfo: nil,
    repeats: false
)

My issue is that, starting with the second video playback, I receive this warning:

Warning: tried to add target beyond target's input capacity --> Pipeline.swift: addTarget(_:atTargetIndex:): 43

I tried creating a new MovieInput for each playback and also tried creating a new RenderView for each playback, but still receive the warning. Anyone run into this before?

BradLarson commented 6 years ago

You're fully rebuilding the filter chain for each of your movie inputs. While removeAllTargets() disconnects the previous movie from the filter chain, you're then trying to reconnect greyscaleFilte, invertFilter, and renderView to each other when they're already connected. That should be what's throwing the error.

Try connecting them only once on the first movie you play, then merely swapping out the movie input as it changes.

pdcarroll commented 6 years ago

That makes sense. I went ahead and re-factored my code to load/unload a separate view controller for each video that encapsulates the GPUImage filters. It's a little cleaner and it solves this issue.

Thanks, Brad!