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

iOS 对视频抽帧。

时间:2014-12-19 15:42:57      阅读:454      评论:0      收藏:0      [点我收藏+]

标签:

这里有两种方法可以采用,

方法一:使用MPMoviePlayerController

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc]  initWithContentURL:videoURL];

moviePlayer.shouldAutoplay = NO; 
UIImage *thumbnail = [moviePlayer thumbnailImageAtTime:time timeOption:MPMovieTimeOptionNearestKeyFrame];

 

优点:操作简单,省事

缺点:不够轻量,抓取图片耗时。

 

方法二:使用AVAssetImageGenerator

+ (UIImage*) thumbnailImageForVideo :( NSURL *)videoURL atTime :( NSTimeInterval)time {
    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
    NSParameterAssert(asset);
    AVAssetImageGenerator *assetImageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
    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] : nil;

    return thumbnailImage;
}

 

iOS 对视频抽帧。

标签:

原文地址:http://www.cnblogs.com/sparks/p/4173882.html

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