获取视频第一帧的方法

旧方法:在iOS7.0以后过期了,但是还是可以用。

    NSURL *url = [NSURL fileURLWithPath:@"/Users/apple/Desktop/视频/IMG_0412.mp4"];
    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url] ;
    UIImage  *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
    UIImageView *imageV = [[UIImageView alloc] initWithImage:thumbnail];
    imageV.frame = CGRectMake(20, 200, 200, 180);
    [self.view addSubview:imageV];

新方法:要导入头文件 :#import <AVFoundation/AVFoundation.h>

    AVURLAsset *asset1 = [[AVURLAsset alloc] initWithURL:url options:nil];
    AVAssetImageGenerator *generate1 = [[AVAssetImageGenerator alloc] initWithAsset:asset1];
    generate1.appliesPreferredTrackTransform = YES;
    NSError *err = NULL;
    CMTime time = CMTimeMake(1, 2);
    CGImageRef oneRef = [generate1 copyCGImageAtTime:time actualTime:NULL error:&err];
    UIImage *one = [[UIImage alloc] initWithCGImage:oneRef];
    UIImageView *imageV = [[UIImageView alloc] initWithImage:one];
    imageV.frame = CGRectMake(20, 200, 200, 180);
    [self.view addSubview:imageV];
原文地址:https://www.cnblogs.com/pengyunjing/p/5996889.html