Blend two movie inputs, maintaining sync
It would be good to be able to have videos as inputs to the two input filters.... I'm trying to do something like...
GPUImageMovie *colourMovie; //init correctly etc... GPUImageMovie *reflectionMovie;
GPUImageScreenBlendFilter* reflectionFilter;
[colourMovie addTarget:reflectionFilter]; [reflectionMovie addTarget:reflectionFilter];
[reflectionFilter addTarget:self.viewer];
[colourMovie startProcessing]; [reflectionMovie startProcessing];
This sometimes works if I change the order in which the movies are started, but has threading sync issues as both movies are driving the processing.
I get an assert: Incomplete filter FBO: most of the time.
Is there any way to do this? Do I need to add some semaphores to the rendering?
There currently is a bug in the blend filters where they won't initialize their size properly if they get fed a frame from the second input before they get one from the first input. To work around this, you can use -forceProcessingAtSize: on the blend filter and manually specify a movie size before either of the movies start processing.
However, this won't address a more fundamental issue of different playback frame rates for the two movies, which will quickly cause them to fall out of sync. I haven't spent much time working on this, and I'd welcome any contributions you'd have to help fix this timing issue.
hi brad, my solution for this was
- create an AVComposition containing two tracks, one for each video.
- create a custom asset reader that read from the track with the earlier frame. (so that will contain 2 frames of the same timestamp from each track).
- create a custom blender which only process the frames if the two frames are with the same time stamp.
I updated the blend filters over the weekend to only process once a frame has been fed to them from both inputs. Do you still have this problem with the latest code from the repository?
Looks like you added the same fix I tried (except I broke still images) Much better. I have 6 video inputs to merge, so I've decided to pre-process and combine some of my videos into a tiled large video and use crop filters to extract the tiles, I still have to combine some different movie files and this is now working well on a latest gen iPod. cheers.
Unfortunately there is still a big problem, everything works fine if the device can keep up, but when I run it on my lower end devices the videos get out of sync. So if one video takes longer to decode than another the quicker video will race ahead. we need some way to block the asset readers until both frames have been received by the two input filter. I tried adding adding semaphores to sync up the two inputs but as they are both on the same queue they will create a deadlock. any ideas?
Keeping multiple GPUImageMovie instances in sync is going to require some sort of timing mechanism, and I don't have anything like that in place (which is why you can't play a movie at its original speed). You're welcome to work on this, but I'm not doing anything with movies right now, so I won't get to this for a while.
I just added a means of telling input movies to respect the original playback rate, which should address this. See the new playAtActualSpeed property on GPUImageMovie.
Is there any other way to handle timing in GPUImage right now other than playAtActualSpeed, if not can you direct us in the right direction to implement it?
@efesus This would need to be handled by the two-input filters, where it would need to properly order frames based on their timestamps, but nothing of the sort is currently implemented.
hi @efesus, I think this one might help you on this: GPUImage Video Merging: Timestamp Synchronization