Raj Upadhyay Raj Upadhyay - 5 months ago 22
iOS Question

How to capture still image from custom video player screen in iOS?

I just create my own custom video player using

AVFoundation
library's AVPlayer* myPlayer. Now I want to capture images for bookmarks of video from running playing video on
UIButton
click
action
. On click
UIButton
it take snapshot of player screen and store in document directory.
Please suggest me how to do it?
Thank you in advance.

Answer
AVAsset *asset = [AVAsset assetWithURL:sourceURL];
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc]initWithAsset:asset];
CMTime time = CMTimeMake(1, 1);
CGImageRef imageRef = [imageGenerator copyCGImageAtTime:time actualTime:NULL error:NULL];
UIImage *thumbnail = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);  // CGImageRef won't be released by ARC

Reference Link :

Create a thumbnail or image of an AVPlayer at current time