本地存储的视频文件,通过某些方法获取该视频的首帧图片,或是某个时间的图片,或是该视图不同时间段的多张图片。
获取视频第一帧的图片,示例代码如下:
+ (UIImage *)videoThumbnailWithFilePath:(NSString *)filePath
{
if (filePath == nil || filePath.length <= 0) {
return nil;
}
NSURL *url = [NSURL fileURLWithPath:filePath];
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:nil];
AVAssetImageGenerator *assetGen = [[AVAssetImageGenerator alloc] initWithAsset:asset];
assetGen.appliesPreferredTrackTransform = YES;
CMTime time = CMTimeMakeWithSeconds(0.0, 600);
NSError *error = nil;
CMTime actualTime;
CGImageRef image = [assetGen copyCGImageAtTime:time actualTime:&actualTime error:&error];
UIImage *videoImage = [[UIImage alloc] initWithCGImage:image];
CGImageRelease(image);
return videoImage;
}
需要导入头文件’#import <AVFoundation/AVFoundati