美文网首页iOS 常见问题汇总
ios 获取视频中的某一帧图片

ios 获取视频中的某一帧图片

作者: 飞行的理想 | 来源:发表于2019-02-11 11:43 被阅读36次

/**

 获取视频的 某一帧

 @paramcurrentTime 某一时刻单位 s

 @parampath 视频路径

 @returnreturn 返回image

 */

+ (UIImage*)getVideoImageWithTime:(Float64)currentTime videoPath:(NSURL*)path

{

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

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

    assetGen.appliesPreferredTrackTransform = YES;

    CMTime time = CMTimeMakeWithSeconds(0.0, 600);

    NSError*error =nil;

    CMTimeactualTime;

    CGImageRefimage = [assetGencopyCGImageAtTime:timeactualTime:&actualTimeerror:&error];

    UIImage *videoImage = [[UIImage alloc] initWithCGImage:image];

    CGImageRelease(image);

    returnvideoImage;

}

相关文章

网友评论

    本文标题:ios 获取视频中的某一帧图片

    本文链接:https://www.haomeiwen.com/subject/affqeqtx.html