I'm trying to generate a UIImage from a video frame captured by GPUImage. I've done a lot of AVFoundation video work, but i'm new to using GPUImage. I've subclassed GPUImageVideoCamera and added this method, but the UIImage is always nil. If anyone can tell me where i've gone so horribly wrong, i'd be very appreciative!
- (void)processVideoSampleBuffer:( CMSampleBufferRef )sampleBuffer
{ [super processVideoSampleBuffer:sampleBuffer]; // to let GPUImage do it's processing first
if (!self.thumbnailGenerated)
{
CMTime timestamp = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
NSLog(@"%f", (float)timestamp.value / timestamp.timescale);
self.thumbnailGenerated = YES;
dispatch_sync(dispatch_get_main_queue(), ^
{
// generate a preview frame from the last filter in the camera filter chain
UIImage *thumbnailImage = [UIImage imageWithCGImage:[[self.targets lastObject] newCGImageFromCurrentlyProcessedOutput]];
NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Thumbnail.png"];
[UIImagePNGRepresentation(thumbnailImage) writeToFile:pathToMovie atomically:YES];
});
}
}