Sunday, June 3, 2012

UIImage From Movie File

Simple utility method to create a image from video file. Specify the size of the image and the time interval.

UIImage *getImageFromMovieAtTime(AVURLAsset *videoAsset, CGSize imageSize,CMTime frameTime)
    NSError *error =nil;
    CMTime actualTime;
    AVAssetImageGenerator *imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:videoAsset];
    imageGenerator.appliesPreferredTrackTransform = YES;
    imageGenerator.maximumSize = imageSize;
    CGImageRef imageRef = [imageGenerator copyCGImageAtTime:frameTime actualTime:&actualTime error:&error];
    UIImage *movImage = [UIImage imageWithCGImage:imageRef];
    if(error || movImage == nil)
         DEBUGLOG(@"Error: %@",error);
    DEBUGLOG(@"imagesize: %@",NSStringFromCGSize(movImage.size));
 return movImage;
    UIImage *videoFrame = getImageFromMovieAtTime(videoAsset, CGSizeMake(width, height),kCMTimeZero);

No comments:

Post a Comment