This is a follow-up to a previous but only marginally related question
I'm using the GPUImage library to apply filters to still photos and videos in my camera app. Almost everything is working nicely. One remaining issue that I have not been able to resolve is as follows:
- I capture a GPUImageMovie
- I write it to the file system
- I read it from the file system and apply a new filter
- I write it to a different URL in the filesystem
What is saved to that new URL is a video with the correct duration but no movement. When I hit play, it's just a still image, I think the first frame of the video. This happens anytime I apply any filter to a video that I retrieve from the filesystem. Applying a filter to live recording video works just fine. My code is below.
Can anyone tell me how I can modify this to save the entire original video with a filter applied?
- (void)applyProcessingToVideoAtIndexPath:(NSIndexPath *)indexPath withFilter:(GPUImageFilter *)selectedFilter
{
NSArray *urls = [self.videoURLsByIndexPaths objectForKey:self.indexPathForDisplayedImage];
NSURL *url = [urls lastObject];
self.editedMovie = [[GPUImageMovie alloc] initWithURL:url];
assert(!!self.editedMovie);
[self.editedMovie addTarget:selectedFilter]; // apply the user-selected filter to the file
NSURL *movieURL = [self generatedMovieURL];
// A different movie writer than the one I was using for live video capture.
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(640.0, 640.0)];
[selectedFilter addTarget:movieWriter];
movieWriter.shouldPassthroughAudio = YES;
self.editedMovie.audioEncodingTarget = movieWriter;
[self.editedMovie enableSynchronizedEncodingUsingMovieWriter:movieWriter];
[movieWriter startRecording];
[self.editedMovie startProcessing];
__weak GPUImageMovieWriter *weakWriter = movieWriter;
__weak CreateContentViewController *weakSelf = self;
[movieWriter setCompletionBlock:^{
[selectedFilter removeTarget:weakWriter];
[weakWriter finishRecordingWithCompletionHandler:^{
NSArray *urls = [weakSelf.videoURLsByIndexPaths objectForKey:weakSelf.indexPathForDisplayedImage];
urls = [urls arrayByAddingObject:movieURL];
NSMutableDictionary *mutableVideoURLs = [weakSelf.videoURLsByIndexPaths mutableCopy];
[mutableVideoURLs setObject:urls forKey:weakSelf.indexPathForDisplayedImage];
weakSelf.videoURLsByIndexPaths = mutableVideoURLs;
dispatch_sync(dispatch_get_main_queue(), ^{
[self.filmRoll reloadData];
[weakSelf showPlayerLayerForURL:movieURL onTopOfImageView:weakSelf.displayedImageView];
});
}];
}];
}