BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.24k stars 4.61k forks source link

Changing/initializing filters after calling [GPUImageMovie startProcessing] #1178

Open mattwiechec opened 11 years ago

mattwiechec commented 11 years ago

Since upgrading to the latest version of GPUImage today I'm having issues changing filters on the fly.

If I have already called [startProcessing] I cannot alloc/init a new filter (ie. filter = [[GPUImageSepiaFilter alloc] init]) or call [removeAllTargets]/[addTarget] when a loaded video is running. The changes only take effect after the video loops.

The current workaround is to call [endProcessing], make the changes, then call [startProcessing] again. The downside to this is that the video restarts from the beginning.

My previous version of GPUImage did not have this issue. Can anyone shed some light on this? What has changed?

Edit: Interestingly this is not an issue in the supplied example project SimpleVideoFileFilter, but when duplicating the code to a new project the issue shows up.

Edit 2: Perhaps SimpleVideoFileFilter is using an old static lib? Modifying FilterShowcase to run a video and trying to change filters on the fly produces the issue mentioned above.

kbola commented 11 years ago

This also happened to me yesterday.

In addition to what is described above: 1) Parameter changes are not happening in real-time during playback. 2) Removing targets / [filter alloc] blocks the app (no touch events registered etc) until playback is finished.

Cheers!

balabs commented 11 years ago

@kbola I'm facing the same issue if you manage to solve this please post here.

plenilune commented 11 years ago

Same issue here. Main thread is being blocked somewhere, but I could not find it using Instruments.

balabs commented 11 years ago

My solution for blocked main thread and GUI was this: in file GPUIUmageMovie.m find the method

there is if condition

if (synchronizedMovieWriter != nil)
{

// HERE GOES CODE IF - TRUE } else { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{

// HERE GOES ALL CODE FROM IF - FALSE });

}

Those are some of my changes that worked for me.

Here is the whole method from my code:

kirill-c commented 10 years ago

balabs, thanks a lot

mikemuzza commented 10 years ago

For anyone still relying on this hack, I found it will make the video playback at inconsistent rates on iOS 8. Generally slow and stuttered.

The problem it patched seems to be resolved in the latest version of GPUImage. Removing the dispatch_async wrapper in the else statement fixed the video playback for me.

seosgithub commented 10 years ago

Hmm, maybe try changing "DISPATCH_QUEUE_PRIORITY_BACKGROUND" to "DISPATCH_QUEUE_PRIORITY_HIGH" or "DISPATCH_QUEUE_PRIORITY_LOW"? Background priority is not really meant for anything except IO "Items dispatched to the queue run at background priority; the queue is scheduled for execution after all high priority queues have been scheduled and the system runs items on a thread whose priority is set for background status. Such a thread has the lowest priority and any disk I/O is throttled to minimize the impact on the system" https://developer.apple.com/library/ios/documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html#//apple_ref/c/macro/DISPATCH_QUEUE_PRIORITY_BACKGROUND