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

iOS获取视频中的指定帧的两种方法

时间:2017-04-12 02:09:39      阅读:295      评论:0      收藏:0      [点我收藏+]

标签:key   encode   log   cgi   get   uiimage   amp   iap   pixel   

方法一 :AVFoundation

 1 #import <AVFoundation/AVFoundation.h>
 2 
 3 - (UIImage *)thumbnailImageForVideo:(NSURL *)videoURL atTime:(NSTimeInterval)time {
 4     AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
 5     NSParameterAssert(asset);
 6     AVAssetImageGenerator *assetImageGenerator =[[AVAssetImageGenerator alloc] initWithAsset:asset];
 7     assetImageGenerator.appliesPreferredTrackTransform = YES;
 8     assetImageGenerator.apertureMode =AVAssetImageGeneratorApertureModeEncodedPixels;
 9 
10     CGImageRef thumbnailImageRef = NULL;
11     CFTimeInterval thumbnailImageTime = time;
12     NSError *thumbnailImageGenerationError = nil;
13     thumbnailImageRef = [assetImageGenerator copyCGImageAtTime:CMTimeMake(thumbnailImageTime, 60)actualTime:NULL error:&thumbnailImageGenerationError];
14 
15     if(!thumbnailImageRef)
16         CXIMLog(@"thumbnailImageGenerationError %@",thumbnailImageGenerationError);
17 
18     UIImage *thumbnailImage = thumbnailImageRef ? [[UIImage alloc]initWithCGImage:thumbnailImageRef] : nil;
19     return thumbnailImage;
20 }

方法二:MPMoviePlayerController

1 #import <MediaPlayer/MediaPlayer.h>
2 
3 MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
4 moviePlayer.shouldAutoplay = NO;
5 UIImage *thumbnailImage = [moviePlayer thumbnailImageAtTime:time timeOption:MPMovieTimeOptionNearestKeyFrame];

 

iOS获取视频中的指定帧的两种方法

标签:key   encode   log   cgi   get   uiimage   amp   iap   pixel   

原文地址:http://www.cnblogs.com/wangtianze/p/6696999.html

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