zoukankan      html  css  js  c++  java
  • 得到视频的第一帧

    - (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;
    }
    

      然后调用该方法即可,你可以使用本地视频测试

        UIImageView *iimage = [[UIImageView alloc]initWithFrame:self.view.bounds];
        [self.view addSubview:iimage];
    
        NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"pixelmator.mov"];
        NSURL *url = [NSURL fileURLWithPath:path];
    
      iimage.image =  [self thumbnailImageForVideo:url atTime:300];
    

      

  • 相关阅读:
    cakephp异常机制
    你的效率是整理出来的——张一驰
    eclipse常用总结
    cakephp写Lib要点
    代码整洁之道-马丁-第3章 函数
    PHP静态方法如何编写
    编程常用工具
    代码大全(第二版)
    PHP实现AES对称加密
    【pytest】(三) pytest运行多个文件
  • 原文地址:https://www.cnblogs.com/lidarui/p/6911504.html
Copyright © 2011-2022 走看看