NSString *url = [Utils applicationCachesDirectory:self.videourl];
url = [Utils applicationDocumentsDirectory:self.videourl];
NSURL *videoURL = [NSURL fileURLWithPath:url];
NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO]
forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:videoURL options:opts];
//NSLog(@"视频的路径是:%@", videoURL);
AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:urlAsset];
generator.appliesPreferredTrackTransform = YES;
generator.maximumSize = CGSizeMake(360.0f, 480.0f);
NSError *error = nil;
/*** Returns a CGImage for the asset at or near a specified time. */
/*** - (CGImageRef)copyCGImageAtTime:(CMTime)requestedTime actualTime:(CMTime *)actualTime error:(NSError **)outError */
CGImageRef cgImg = [generator copyCGImageAtTime: CMTimeMake(1, 1) actualTime:NULL error:&error];
url = [Utils applicationDocumentsDirectory:self.videourl];
NSURL *videoURL = [NSURL fileURLWithPath:url];
NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO]
forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:videoURL options:opts];
//NSLog(@"视频的路径是:%@", videoURL);
AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:urlAsset];
generator.appliesPreferredTrackTransform = YES;
generator.maximumSize = CGSizeMake(360.0f, 480.0f);
NSError *error = nil;
/*** Returns a CGImage for the asset at or near a specified time. */
/*** - (CGImageRef)copyCGImageAtTime:(CMTime)requestedTime actualTime:(CMTime *)actualTime error:(NSError **)outError */
CGImageRef cgImg = [generator copyCGImageAtTime: CMTimeMake(1, 1) actualTime:NULL error:&error];
本文介绍了一种在iOS应用中从视频中获取指定时间点截图的方法。使用AVFoundation框架中的AVURLAsset来加载视频,并通过AVAssetImageGenerator生成指定时间点的图片。

被折叠的 条评论
为什么被折叠?



