I try to read some frames from a video. The video is 640 x 480 but the images I get are only 480 x 360. Is there a way to get images of the original size?
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString * mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
[self readMovieFrames:[info objectForKey:UIImagePickerControllerMediaURL]];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)readMovieFrames:(NSURL *)url
{
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url];
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:playerItem.asset];
imageGenerator.requestedTimeToleranceAfter = kCMTimeZero;
imageGenerator.requestedTimeToleranceBefore = kCMTimeZero;
imageGenerator.appliesPreferredTrackTransform = YES;
//…
CGImageRef imageRef = [imageGenerator copyCGImageAtTime:requestTime actualTime:&actualTime error:&error];
UIImage *img = [UIImage imageWithCGImage:imageRef];
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
CGImageRelease(imageRef);
}
Either use
imageGenerator.maximumSize = CGSizeZero;
to get an unscaled image or define a bounding box of 640px, aspect ratio remains
imageGenerator.maximumSize = CGSizeMake(640, 640);
Hope that helps!