• 获取视频第一帧的方法


    旧方法:在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];
  • 相关阅读:
    Anniversary party(树形DP入门)
    Neither shaken nor stirred(DFS理解+vector存图)
    统计单词数
    洛谷---三连击
    Educational Codeforces Round 68 (Rated for Div. 2)---B
    HDU-1201--18岁生日
    HDU-盐水的故事
    Flower(规律+逆向思维)
    The puzzle
    XOR Clique(按位异或)
  • 原文地址:https://www.cnblogs.com/pengyunjing/p/5996889.html
Copyright © 2020-2023  润新知