Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Chroma Key Blend filter with two videos and a movie writer makes OpenGL queue crash #773
I use GPUImage to blend two videos (one of them as a green background) and display the result on an iPhone screen (with a live video or a video from a file).
Here is the code:
self.movie = [[GPUImageMovie alloc] initWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"source" ofType:@"mov"]]]; self.greenMovie = [[GPUImageMovie alloc] initWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"greenscreen" ofType:@"mp4"]]]; GPUImageChromaKeyBlendFilter *filter = [[GPUImageChromaKeyBlendFilter alloc] init]; [self.greenMovie addTarget:filter]; [self.movie addTarget:filter]; GPUImageView *filterView = (GPUImageView *)self.view; [filter addTarget:filterView]; self.writeURL = [NSURL fileURLWithPath:[@"~/Library/Caches/movie.mov" stringByExpandingTildeInPath]]; unlink([[self.writeURL absoluteString] UTF8String]); self.writer = [[GPUImageMovieWriter alloc] initWithMovieURL:self.writeURL size:CGSizeMake(640, 320)]; [self.movie enableSynchronizedEncodingUsingMovieWriter:self.writer]; [filter addTarget:self.writer]; [self.writer startRecording]; [self.greenMovie startProcessing]; [self.movie startProcessing];
The stack of the queue that crashed after adding the writer:
Any idea or clue to get more information about the crash?
I am not sure this is related to memory: I also have another part of my code that does almost the same thing except that the source video is the camera of the iPhone. Everything works well too unless I enable the recording of the result.
In that case, I capture a video of 960x540 and the blended video is of 640x360. I display the video on screen.
There is a possibility that this is due to out-of-order timestamps. With two movie sources being blended, sometimes both timestamps from the two movies get passed into the movie writer, confusing it. That shouldn't cause a crash, just stuttering and perhaps an early termination of the movie. Still, its possible that it could be getting into an unstable state if that occurs. The two-input filter superclass has a bug in it regarding this, but I don't have a clean fix right now.