I'm trying to add an image to every frame of a video using the GPUImage library, but can't get it to work. For some reason, the processed video only includes the original video, without the image overlay. What am I doing wrong?
GPUImagePicture *overlay = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:@"overlayimage"] smoothlyScaleOutput:YES];
GPUImageMovie *movie = [[GPUImageMovie alloc] initWithURL:[THE URL TO THE VIDEO ASSET]];
movie.delegate = self;
movie.runBenchmark = YES;
movie.playAtActualSpeed = YES;
self.movieView = [[GPUImageView alloc] initWithFrame:self.bounds];
self.movieView.fillMode = kGPUImageFillModePreserveAspectRatio;
GPUImageAlphaBlendFilter *filter = [[GPUImageAlphaBlendFilter alloc] init];
[movie addTarget:filter atTextureLocation:0];
[overlay addTarget:filter atTextureLocation:1];
Here's the solution, if anyone runs into the same problem: You have to retain the GPUImagePicture, GPUImageMovie and GPUImageView objects, for example by storing them in properties. Otherwise they will be released under ARC at the end of the method or the runloop.
Two things you can try:
Don't call processImage on overlay until AFTER you've targeted the alpha blend filter. I'd try it right before, or right after you call startProcessing on movie.
Don't worry about specifying the textureLocation's when your targeting the AlphaBlendFilter. you can just call addTarget and let the blend sort it out.
Those are off the top of my head, I'll actually test them out after work tonight.