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.87k stars 609 forks source link

Correct way to reuse a still filter .. #220

Open smhk opened 6 years ago

smhk commented 6 years ago

I'm filtering an image like this ..

filter = ...
pInput = PictureInput( ... )
pInput! --> filter
filter --> pOutput
pOutput.imageAvailableCallback = {image in
   DispatchQueue.main.async { ... }
}
pInput!.processImage(synchronously:true)

I want to reuse the filter and pipeline. I am just changing the input each time.

I have found that the following works:

pInput!.removeAllTargets()
pInput = PictureInput(image: ...next image )
pInput! --> filter
pOutput.imageAvailableCallback = {image in
   DispatchQueue.main.async { .. same as above .. }
pInput!.processImage(synchronously:true)
  1. imageAvailableCallback definitely goes to nil each time. You have to reset it (to the same thing) each time. Am I doing something wrong?

  2. It seems you do have to removeAllTargets from the input. This seems strange, since you're completely remaking input with pInput = PictureInput(image: ...next image ). (How would it even 'remember' what the target is?) Am I doing something wrong?

thanks !