zoukankan      html  css  js  c++  java
  • iOS 对视频抽帧。

    这里有两种方法可以采用,

    方法一:使用MPMoviePlayerController

    MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc]  initWithContentURL:videoURL];
    
    moviePlayer.shouldAutoplay = NO; 
    UIImage *thumbnail = [moviePlayer thumbnailImageAtTime:time timeOption:MPMovieTimeOptionNearestKeyFrame];
    

    优点:操作简单,省事

    缺点:不够轻量,抓取图片耗时。

    方法二:使用AVAssetImageGenerator

    + (UIImage*) thumbnailImageForVideo :( NSURL *)videoURL atTime :( NSTimeInterval)time {
        AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
        NSParameterAssert(asset);
        AVAssetImageGenerator *assetImageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
        assetImageGenerator.appliesPreferredTrackTransform = YES;
        assetImageGenerator.apertureMode = AVAssetImageGeneratorApertureModeEncodedPixels;
    
        CGImageRef thumbnailImageRef = NULL;
        CFTimeInterval thumbnailImageTime = time;
        NSError *thumbnailImageGenerationError = nil;
        thumbnailImageRef = [assetImageGenerator copyCGImageAtTime:CMTimeMake(thumbnailImageTime, 60) actualTime:NULL error:&thumbnailImageGenerationError];
    
        if (!thumbnailImageRef)
            NSLog(@"thumbnailImageGenerationError %@", thumbnailImageGenerationError);
    
        UIImage *thumbnailImage = thumbnailImageRef ? [[UIImage alloc] initWithCGImage:thumbnailImageRef] : nil;
    
        return thumbnailImage;
    }
    
  • 相关阅读:
    获取服务结合随机算法
    服务发现
    使用第三方库来支持平滑重启
    简易配置中心Confd入手
    8、SQL基础整理(约束)
    7、SQL基础整理(子查询)
    6、SQL基础整理(日期时间数据类型,转换函数)
    5、SQL基础整理(字符串函数)
    4、SQL基础整理(规范函数)
    3、SQL基础整理(分组)
  • 原文地址:https://www.cnblogs.com/sparks/p/4173882.html
Copyright © 2011-2022 走看看