码迷,mamicode.com
首页 > 其他好文 > 详细

视频取帧

时间:2016-04-25 14:49:24      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

///视频取帧

- (UIImage*) thumbnailImageForVideo:(NSURL *)videoURL atTime:(NSTimeInterval)time {

    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil] ;

    NSParameterAssert(asset);

    AVAssetImageGenerator *assetImageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset];

    assetImageGenerator.appliesPreferredTrackTransform = YES;

    assetImageGenerator.apertureMode = AVAssetImageGeneratorApertureModeEncodedPixels;

    //取帧

    CGImageRef thumbTemp = NULL;

    CMTime actualTime ;

    //    int32_t time = asset.duration.timescale;

    NSError *error = nil;

    thumbTemp = [assetImageGenerator copyCGImageAtTime:CMTimeMake(time, asset.duration.timescale) actualTime:&actualTime error:&error];

    NSLog(@"%lld",actualTime.value);

    UIImage *thumb = nil;

    if (!error)

    {

        thumb = [[UIImage alloc] initWithCGImage:thumbTemp];

    }

    CGImageRelease(thumbTemp);

    return thumb;

}

视频取帧

标签:

原文地址:http://www.cnblogs.com/xia0huihui/p/5430806.html

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