#import <AVFoundation/AVAsset.h>
#import <AVFoundation/AVAssetImageGenerator.h>
#import <AVFoundation/AVTime.h>
+ (UIImage *)getImageWithVideoUrl:(NSString *)urlString{
    
    //视频地址
    NSURL *url = nil;
    if ([urlString hasPrefix:@"http"]) {
        url = [NSURL URLWithString:urlString];
    }else{
        url = [NSURL fileURLWithPath:urlString];
    }
    
    AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:url options:nil];//
    
    //获取视频时长,单位:秒
    NSLog(@"%llu",urlAsset.duration.value/urlAsset.duration.timescale);
    
    AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:urlAsset];
    
    generator.appliesPreferredTrackTransform = YES;
    
    generator.maximumSize = CGSizeMake(1136, 640);
    
    NSError *error = nil;
    
    CGImageRef img = [generator copyCGImageAtTime:CMTimeMake(10, 10) actualTime:NULL error:&error];
    
    UIImage *image = [UIImage imageWithCGImage: img];
    
    return image;
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-17
  • 2021-11-17
  • 2022-01-22
  • 2022-12-23
  • 2022-01-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-03
  • 2021-11-02
  • 2021-07-18
  • 2022-12-23
相关资源
相似解决方案