zoukankan      html  css  js  c++  java
  • IOS从视频中获取截图

    从视频中获取截图:

    NSString *movpath =[[NSBundle mainBundle] pathForResource:@”iosxcode4″ ofType:@”mov”];

    mpviemController =[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:movpath]];

    MPMoviePlayerController *mp=[mpviemController moviePlayer];

    UIImage *thumbImage=[mp thumbnailImageAtTime:second timeOption:MPMovieTimeOptionNearestKeyFrame];

    NSData *imagedata =UIImagePNGRepresentation(thumbImage);

    [imagedata writeToFile:@"iosxcode4.png" atomically:YES];

     

    第二种方式 直接为UIImage写一个分类:

    +(UIImage *)getImage:(NSString *)videoURL
    {
        AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:videoURL] options:nil];
        AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:asset];
        gen.appliesPreferredTrackTransform = YES;
        CMTime time = CMTimeMakeWithSeconds(0.0, 600);
        NSError *error = nil;
        CMTime actualTime;
        CGImageRef image = [gen copyCGImageAtTime:time actualTime:&actualTime error:&error];
        UIImage *thumb = [[UIImage alloc] initWithCGImage:image];
        CGImageRelease(image);
        return thumb;
    }

     

  • 相关阅读:
    mysql数据增删改查
    Python中的逻辑运算
    Python的格式化输出
    Python变量的命名规则
    解释型语言和编译型语言的比较?
    SQLAlchemy
    ansible
    算法
    数据分析
    scrapy之日志等级
  • 原文地址:https://www.cnblogs.com/syios/p/4807849.html
Copyright © 2011-2022 走看看