分享

IOS批量截取视频截图UIImagemp4IOSVideo

 wintelsui 2017-04-06
  • 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;

    }


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多