您的位置:首页 > 移动开发 > IOS开发

ios根据视频地址获取某一帧的图像

2012-12-18 00:54 253 查看

http://blog.fuckbugs.me/category/ios/

 //CatchImage.h #import <Foundation/Foundation.h> @interface CatchImage : NSObject /* *videoURL:视频地址(本地/网络) *time      :第N帧 */+ (UIImage*) thumbnailImageForVideo:(NSURL *)videoURL atTime:(NSTimeInterval)time;@end //CatchImage.m #import "CatchImage.h"#import <AVFoundation/AVFoundation.h>#import <AVFoundation/AVAssetImageGenerator.h>#import <AVFoundation/AVAsset.h> @implementation CatchImage + (UIImage*) thumbnailImageForVideo:(NSURL *)videoURL atTime:(NSTimeInterval)time {        AVURLAsset *asset = [[[AVURLAsset alloc] initWithURL:videoURL options:nil]autorelease];    NSParameterAssert(asset);    AVAssetImageGenerator *assetImageGenerator =[[[AVAssetImageGenerator alloc] initWithAsset:asset]autorelease];    assetImageGenerator.appliesPreferredTrackTransform = YES;    assetImageGenerator.apertureMode =AVAssetImageGeneratorApertureModeEncodedPixels;        CGImageRef thumbnailImageRef = NULL;    CFTimeInterval thumbnailImageTime = time;    NSError *thumbnailImageGenerationError = nil;    thumbnailImageRef = [assetImageGenerator copyCGImageAtTime:CMTimeMake(thumbnailImageTime, 60)actualTime:NULL error:&thumbnailImageGenerationError];        if(!thumbnailImageRef)        NSLog(@"thumbnailImageGenerationError %@",thumbnailImageGenerationError);        UIImage*thumbnailImage = thumbnailImageRef ? [[[UIImage alloc]initWithCGImage:thumbnailImageRef] autorelease] : nil;        return thumbnailImage;}@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: