视频开发--取出第一帧

如何取得第一帧

AVFoundationframework 

 

 CoreMediaframework

+ (UIImage*) thumbnailImageForVideo:(NSURL *)videoURLatTime:(NSTimeInterval)time {
 
    AVURLAsset*asset = [[[AVURLAsset alloc] initWithURL:videoURL options:nil]autorelease];
      NSParameterAssert(asset);
      AVAssetImageGenerator *assetImageGenerator =[[[AVAssetImageGenerator alloc] initWithAsset:asset]autorelease];
      assetImageGenerator.appliesPreferredTrackTra nsform = YES;
      assetImageGenerator.apertureMode =AVAssetImageGeneratorApe rtureModeEncodedPixels;

      CGImageRefthumbnailImageRef = NULL;
      CFTimeInterval thumbnailImageTime = time;
      NSError*thumbnailImageGeneration Error = nil;
      thumbnailImageRef = [assetImageGeneratorcopyCGImageAtTime:CMTimeMake(thumbnailImageTime, 60)actualTime:NULLerror:&thumbnailImageGeneration Error];

      if(!thumbnailImageRef)
              NSLog(@"thumbnailImageGeneration Error %@",thumbnailImageGeneration Error);

      UIImage*thumbnailImage = thumbnailImageRef ? [[[UIImage alloc]initWithCGImage:thumbnailImageRef] autorelease] : nil;

      returnthumbnailImage;


你可能感兴趣的:(视频开发--取出第一帧)