打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
IOS批量截取视频截图UIImagemp4IOSVideo
  • 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 = [[AVURLAssetalloc] initWithURL:[NSURLfileURLWithPath:videoURL] options:nil];

    AVAssetImageGenerator *gen = [[AVAssetImageGeneratoralloc] 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 = [[UIImagealloc] initWithCGImage:image];

    CGImageRelease(image);

    return thumb;

    }


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
iOS 获取视频第一帧图片
iOS 获取视频的任意一帧
iOS开发图片加载的内存问题及优化方案
IOS
保存UIImage到文件
ios截屏代码[转]
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服