zoukankan      html  css  js  c++  java
  • iOS-获取视频中的指定帧

    方法一 :AVFoundation

    #import <AVFoundation/AVFoundation.h>
    
    - (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)
            CXIMLog(@"thumbnailImageGenerationError %@",thumbnailImageGenerationError);
        
        UIImage *thumbnailImage = thumbnailImageRef ? [[UIImage alloc]initWithCGImage:thumbnailImageRef] : nil;
        return thumbnailImage;
    }
    

    方法二:MPMoviePlayerController

    #import <MediaPlayer/MediaPlayer.h>
    
    MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
    moviePlayer.shouldAutoplay = NO;
    UIImage *thumbnailImage = [moviePlayer thumbnailImageAtTime:time timeOption:MPMovieTimeOptionNearestKeyFrame];
    
  • 相关阅读:
    宏观经济指标
    Poloniex API 文档
    雪球释老毛推荐的投资者书单
    数字货币开源项目——貔貅
    数字货币量化分析报告_20170905_P
    数字货币量化分析报告_2017-09-05
    数字货币量化分析报告_2017-09-04
    ICO成本价
    Python3使用Print输出带颜色字体
    Ta-lib函数功能列表
  • 原文地址:https://www.cnblogs.com/lancely/p/5782811.html
Copyright © 2011-2022 走看看