美文网首页
iOS 获取视频的第一帧的图片

iOS 获取视频的第一帧的图片

作者: 学学学q | 来源:发表于2018-03-30 15:33 被阅读86次

#import <AVFoundation/AVAsset.h>
#import <AVFoundation/AVAssetImageGenerator.h>
#import <AVFoundation/AVTime.h>

// 获取视频第一帧  
- (UIImage*) getVideoPreViewImage:(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;  
    CMTime actualTime;  
    CGImageRef image = [assetGen copyCGImageAtTime:time actualTime:&actualTime error:&error];  
    UIImage *videoImage = [[UIImage alloc] initWithCGImage:image];  
    CGImageRelease(image);  
    return videoImage;  
} 

相关文章

网友评论

      本文标题:iOS 获取视频的第一帧的图片

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