zoukankan      html  css  js  c++  java
  • iOS获取视频中的指定帧的两种方法

    方法一 :AVFoundation

     1 #import <AVFoundation/AVFoundation.h>
     2 
     3 - (UIImage *)thumbnailImageForVideo:(NSURL *)videoURL atTime:(NSTimeInterval)time {
     4     AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
     5     NSParameterAssert(asset);
     6     AVAssetImageGenerator *assetImageGenerator =[[AVAssetImageGenerator alloc] initWithAsset:asset];
     7     assetImageGenerator.appliesPreferredTrackTransform = YES;
     8     assetImageGenerator.apertureMode =AVAssetImageGeneratorApertureModeEncodedPixels;
     9 
    10     CGImageRef thumbnailImageRef = NULL;
    11     CFTimeInterval thumbnailImageTime = time;
    12     NSError *thumbnailImageGenerationError = nil;
    13     thumbnailImageRef = [assetImageGenerator copyCGImageAtTime:CMTimeMake(thumbnailImageTime, 60)actualTime:NULL error:&thumbnailImageGenerationError];
    14 
    15     if(!thumbnailImageRef)
    16         CXIMLog(@"thumbnailImageGenerationError %@",thumbnailImageGenerationError);
    17 
    18     UIImage *thumbnailImage = thumbnailImageRef ? [[UIImage alloc]initWithCGImage:thumbnailImageRef] : nil;
    19     return thumbnailImage;
    20 }

    方法二:MPMoviePlayerController

    1 #import <MediaPlayer/MediaPlayer.h>
    2 
    3 MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
    4 moviePlayer.shouldAutoplay = NO;
    5 UIImage *thumbnailImage = [moviePlayer thumbnailImageAtTime:time timeOption:MPMovieTimeOptionNearestKeyFrame];
  • 相关阅读:
    hdu1159 LCS模板题
    RabbitMQ入门
    Dubbo
    SpringMVC
    MySQL的再理解
    ElasticSearch
    redis入门学习
    Swagger
    SSM整合
    MybatisPlus
  • 原文地址:https://www.cnblogs.com/wangtianze/p/6696999.html
Copyright © 2011-2022 走看看