IOS获取视频缩略图

来源:互联网 发布:生产数据追溯 编辑:程序博客网 时间:2024/05/01 07:25

添加

#import <CoreMedia/CoreMedia.h>
#import <AVFoundation/AVFoundation.h>

- (UIImage *)getImage:(NSString *)videoURL{    NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];        NSURL *url = [[[NSURL alloc] initFileURLWithPath:videoURL] autorelease];        AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:url options:opts];        AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:urlAsset];    generator.appliesPreferredTrackTransform = YES;    generator.maximumSize = CGSizeMake(600, 450);        NSError *error = nil;    CGImageRef img = [generator copyCGImageAtTime:CMTimeMake(30, 10) actualTime:NULL error:&error];    UIImage *image = [UIImage imageWithCGImage: img];        return image;}




原创粉丝点击