priore

Capture a screenshot from mov video types

Apr 23rd, 2015
723
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import <AVFoundation/AVFoundation.h>
  2.  
  3. AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:self];
  4. CMTime duration = self.duration;
  5. CGFloat durationInSeconds = duration.value / duration.timescale;
  6. CMTime time = CMTimeMakeWithSeconds(durationInSeconds * 0.5, (int)duration.value);
  7. CGImageRef imageRef = [imageGenerator copyCGImageAtTime:time actualTime:NULL error:NULL];
  8. UIImage *screenshot = [UIImage imageWithCGImage:imageRef];
  9. CGImageRelease(imageRef);
RAW Paste Data