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

IOS从视频中获取截图

时间:2015-09-14 18:09:56      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

从视频中获取截图:

NSString *movpath =[[NSBundle mainBundle] pathForResource:@”iosxcode4″ ofType:@”mov”];

mpviemController =[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:movpath]];

MPMoviePlayerController *mp=[mpviemController moviePlayer];

UIImage *thumbImage=[mp thumbnailImageAtTime:second timeOption:MPMovieTimeOptionNearestKeyFrame];

NSData *imagedata =UIImagePNGRepresentation(thumbImage);

[imagedata writeToFile:@"iosxcode4.png" atomically:YES];

 

第二种方式 直接为UIImage写一个分类:

+(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;
}

 

IOS从视频中获取截图

标签:

原文地址:http://www.cnblogs.com/syios/p/4807849.html

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