How can I apply GPUImageMultiplyBlendFilter or GPUImageOverlayBlendFilter to a movie file?

6 replies [Last post]
sigurdasson
User offline. Last seen 9 years 25 weeks ago. Offline
Joined: 05/06/2012
Posts:

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.

Brad Larson
Brad Larson's picture
User offline. Last seen 4 years 50 weeks ago. Offline
Joined: 05/14/2008
Posts:

Do you start playing the movie at some point using [movieFile startProcessing];?

sigurdasson
User offline. Last seen 9 years 25 weeks ago. Offline
Joined: 05/06/2012
Posts:

Yes, the rest of the code comes from another topic: http://www.sunsetlakesoftware.com/forum/load-movie-filtering-save-camera...

sigurdasson
User offline. Last seen 9 years 25 weeks ago. Offline
Joined: 05/06/2012
Posts:

How can I interpret this line of code: smoothlyScaleOutput:YES ?

Brad Larson
Brad Larson's picture
User offline. Last seen 4 years 50 weeks ago. Offline
Joined: 05/14/2008
Posts:

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.

sigurdasson
User offline. Last seen 9 years 25 weeks ago. Offline
Joined: 05/06/2012
Posts:

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);
        }    
        }];
    }
}

jalleyne
User offline. Last seen 9 years 25 weeks ago. Offline
Joined: 06/11/2012
Posts:

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

Syndicate content