码迷,mamicode.com
首页 > 移动开发 > 详细

IOS批量截取视频截图 UIImage mp4 IOS Video

时间:2016-04-09 15:04:15      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:


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批量截取视频截图 UIImage mp4 IOS Video

标签:

原文地址:http://www.cnblogs.com/lcchuguo/p/5371491.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!