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

GPUImageMovieComposition plays slow and hangs on startProcessing #1339

Open bejayoharen opened 10 years ago

bejayoharen commented 10 years ago

Hi there,

I had some code that created a movie composition and played it back in an AVPlayer/AVPlayerItem beautifully. I wanted to add some video processing, so I used GPUImageMovieComposition/GPUImageView. It plays back, but REALLY slowly (maybe ten times slower).

I also noticed that the startProcessing method doesn't return until the playback is complete which seems to be contrary to the documentation -- I thought this was an asynchronous method call, not a call that blocks. This means I can't stop playback -- I have to wait.

I may be doing something wrong (maybe startProcessing needs to go in a new thread), but I assume this is a bug, so I am reporting.

bejayoharen commented 10 years ago

I also just tried doing this:

[[GPUImageMovie alloc] initWithPlayerItem:....];

with a player item created with the composition, but ultimately couldn't get anything to play

joshuafeldman commented 10 years ago

I was actually just trying to accomplish the same thing. So far I have discovered that it is indeed a bug in GPUImage or just something that isn't documented well enough.

I am able to create a AVPlayerItem from a AVMutableComposition and AVMutableVideoComposition and add a AVPlayerItemVideoOutput to it. Than using AVPlayerItemOutputPullDelegate I can run the display link and using the callback from a CADisplayLink output the buffer to the OpenGL view.

But for some reason when I wire it up to GPUImage it does not playback. My initial suspicion is that it might be thread related...but I am not quite sure.

I will try and remember to comment an answer when / if I get to that point.

joshuafeldman commented 10 years ago

So I take back my previous comment. The issue was that GPUImageMovie created the CADisplayLink in the current runloop. So when you call -startProcessing you need to be in the main UI runloop otherwise the display link is never fired for the screen. This was actually happening way up in the chain of execution for me. It was a programming error where I forgot to bring a method call back to the main queue.

This is definitely not an issue and can be closed.