IOS批量截取视频截图
//生成截图
NSString *path = [NSHomeDirectory() stringByAppendingString:@"/Documents"];
NSLog(@"path %@", path);
for (int i = 0; i<[mItems count]; i++) {
NSMutableDictionary *info = (NSMutableDictionary *)mItems[i]; //视频信息
NSString *mediaPath;
mediaPath = [[NSBundle mainBundle] pathForResource:[info objectForKey:@"mediaName"]
ofType:[info objectForKey:@"type"]];
UIImage *image = [self getImage:mediaPath];
[UIImageJPEGRepresentation(image, 1) writeToFile:[path stringByAppendingPathComponent:[NSString stringWithFormat:@"file%d.jpg", i]] atomically:YES];
}
// 获取指定位置的视频的截屏
-(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(20.5, 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设备上批量从视频中截取图片的方法。通过遍历视频列表,使用AVURLAsset和AVAssetImageGenerator从指定路径的视频文件中在特定时间点截取图片,并将这些图片保存为JPG格式。
9274

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



