Load a movie > Filtering > Save to Camera Roll

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

How can I load a movie from Camera Roll, filtering it and save it to Camera Roll again?
I'm trying to do this, but I have some problem:

- (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];
        sepiaFilter = [[GPUImageSepiaFilter alloc] init];
        [movieFile addTarget:sepiaFilter];
 
       //WHAT CAN I DO NEXT IF I'M USING ARC?
 
    }
}

Thank you, Brad.

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

Look at the SimpleVideoFileFilter, it shows how to do the filtering to another file. From there, it's easy to write that movie into the user's media library.

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

Thank you, Brad, great example! But I still have a question.
What can I use for saving a movie to camera roll: movieWriter or something else?

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

Once the movie has been recorded to disk, you can use code like the following to copy it into the user's media library:

UISaveVideoAtPathToSavedPhotosAlbum(pathToMovie, nil, NULL, NULL);

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

Thanks, Brad. I'm using the following code, but it still not working:

- (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;
        filter = [[GPUImageColorInvertFilter alloc] init];
        [movieFile addTarget:filter];
 
        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)];
        [filter addTarget:movieWriter];
 
        movieWriter.shouldPassthroughAudio = YES;
        movieFile.audioEncodingTarget = movieWriter;
        [movieFile enableSynchronizedEncodingUsingMovieWriter:movieWriter];
 
        [movieWriter startRecording];
        [movieFile startProcessing];
 
        [movieWriter setCompletionBlock:^{
            [filter removeTarget:movieWriter];
            [movieWriter finishRecording];
        }];
 
        if ( UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(pathToMovie))  //without it not working too
        {
            UISaveVideoAtPathToSavedPhotosAlbum(pathToMovie, nil, NULL, NULL);
            NSLog(@"Saving");
        }
 
    }
}

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

Your problem is that you're trying to save the movie to the library right after it starts recording, rather than when the movie is done. You need to place the movie saving code within the completion block.

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

Thank you, Brad!

Syndicate content