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];
  • 相关阅读:
    使用 Spring data redis 结合 Spring cache 缓存数据配置
    Spring Web Flow 笔记
    Linux 定时实行一次任务命令
    css js 优化工具
    arch Failed to load module "intel"
    go 冒泡排序
    go (break goto continue)
    VirtualBox,Kernel driver not installed (rc=-1908)
    go运算符
    go iota
  • 原文地址:https://www.cnblogs.com/wangtianze/p/6696999.html
Copyright © 2011-2022 走看看