How can I apply GPUImageMultiplyBlendFilter or GPUImageOverlayBlendFilter to a movie file?
How can I apply GPUImageMultiplyBlendFilter or GPUImageOverlayBlendFilter to a movie file (GPUImageMovie)?
I use this, but the output is only plain black screen:
//.... movieFile = [[GPUImageMovie alloc] initWithURL:videoURL]; movieFile.runBenchmark = YES; overlayFilter = [[GPUImageOverlayBlendFilter alloc] init]; UIImage *overlayImage = [UIImage imageNamed:@"overlay.png"]; overlayPicture = [[GPUImagePicture alloc] initWithImage:overlayImage smoothlyScaleOutput:YES]; [overlayPicture addTarget:overlayFilter]; [overlayPicture processImage]; [movieFile addTarget:overlayFilter]; //....
Thank you.
Yes, the rest of the code comes from another topic: http://www.sunsetlakesoftware.com/forum/load-movie-filtering-save-camera...
How can I interpret this line of code: smoothlyScaleOutput:YES ?
The smoothlyScaleOutput: option for a photo tells the framework to use trilinear filtering when downsampling the photo. That is, for large photos that you're shrinking down, it will produce a much smoother output. If you don't need to shrink a photo, you can turn that off for better performance and a slightly sharper picture.
Ok Brad, but I still can't apply a filter to a movie file. The output movie file is a movie with a black screen.
Here's the code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [picker dismissModalViewControllerAnimated:YES]; NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType]; if ([mediaType isEqualToString:@"public.movie"]){ NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL]; movieFile = [[GPUImageMovie alloc] initWithURL:videoURL]; movieFile.runBenchmark = YES; overlayFilter = [[GPUImageOverlayBlendFilter alloc] init]; UIImage *overlayImage = [UIImage imageNamed:@"overlay.png"]; overlayPicture = [[GPUImagePicture alloc] initWithImage:overlayImage smoothlyScaleOutput:YES]; [overlayPicture addTarget:overlayFilter]; [overlayPicture processImage]; [movieFile addTarget:overlayFilter]; NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.m4v"]; unlink([pathToMovie UTF8String]); NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie]; movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(640.0, 480.0)]; [overlayFilter addTarget:movieWriter]; movieWriter.shouldPassthroughAudio = YES; movieFile.audioEncodingTarget = movieWriter; [movieFile enableSynchronizedEncodingUsingMovieWriter:movieWriter]; [movieWriter startRecording]; [movieFile startProcessing]; [movieWriter setCompletionBlock:^{ [overlayFilter removeTarget:movieWriter]; [movieWriter finishRecording]; if ( UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(pathToMovie)) { UISaveVideoAtPathToSavedPhotosAlbum(pathToMovie, nil, NULL, NULL); } }]; } }
Hey sigurdasson, were you able to figure this out? ive been trying for a few days now and i either get a black screen or the original video depending on how i apply the filter targets.
Brad, if you could help us out this would be greatly appreciated. My code is similar to what sigurdasson has posted above.
Thanks
Do you start playing the movie at some point using [movieFile startProcessing];?