Video Thumbnails
There is no easy way to retrieve a thumbnail of a video, unlike still photos. This section illustrates two methods of grabbing raw image data from an image picker.
Video Thumbnails Using the UIImagePicker
One way to grab a video frame for creating a thumbnail is to drop down to the underlying Quartz framework to capture an image of the picker itself. To do so, add the following highlighted code to the image picker delegate described previously in this chapter:
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
if( [info objectForKey:@"UIImagePickerControllerMediaType"] ==
kUTTypeMovie ) {
CGSize pickerSize = CGSizeMake(picker.view.bounds.size.width,
picker.view.bounds.size.height-100);
UIGraphicsBeginImageContext(pickerSize);
[picker.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *thumbnail = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
imageView.image = thumbnail;
} else {
imageView.image = image;
}
[self dismissModalViewControllerAnimated:YES];
}Since picker.view.layer is part
of the UIView parent class and is of
type CALayer, the compiler doesn’t
know about renderInContext: method
unless you import the QuartzCore header file. Add the following to the
implementation file:
#import <QuartzCore/QuartzCore.h>Video Thumbnails Using AVFoundation
Another method to obtain a thumbnail that will result in a better
image is to use the AVFoundation framework. ...