码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 获取本地视频的缩略图

时间:2015-09-24 15:59:37      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

iOS 获取本地视频的缩略图

(2012-10-10 20:06:27)
标签:

视频

缩略图

本地

杂谈

分类: ios

+(UIImage *)getImage:(NSString *)videoURL

{

    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:videoURL] options:nil];

    AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:asset];

    gen.appliesPreferredTrackTransform = YES;

    CMTime time = CMTimeMakeWithSeconds(0.0, 600);

    NSError *error = nil;

    CMTime actualTime;    

    CGImageRef image = [gen copyCGImageAtTime:time actualTime:&actualTime error:&error];

    UIImage *thumb = [[UIImage alloc] initWithCGImage:image];

    CGImageRelease(image);

    return thumb;

 

}

需要添加AVFoundation和CoreMedia.framework

另外一种那个方法

 

 

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc]
                                       initWithContentURL:videoURL];
moviePlayer.shouldAutoplay = NO; 
UIImage *thumbnail = [moviePlayer thumbnailImageAtTime:time
                     timeOption:MPMovieTimeOptionNearestKeyFrame];
//这个也一样

+(UIImage *)fFirstVideoFrame:(NSString *)path
{
    MPMoviePlayerController *mp = [[MPMoviePlayerController alloc]
                                   initWithContentURL:[NSURL fileURLWithPath:path]];
    UIImage *img = [mp thumbnailImageAtTime:0.0
                                 timeOption:MPMovieTimeOptionNearestKeyFrame];
    [mp stop];
    [mp release];
    return img;
}

iOS 获取本地视频的缩略图

标签:

原文地址:http://www.cnblogs.com/transcendent/p/4835282.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!