I want to get thumbnail images of every frame from video and then save this images in Mutable Array of images.
I want to use this images to play as a animation.
NSURL* assetURL = [self.asset valueForProperty:ALAssetPropertyAssetURL];
NSDictionary* assetOptions = nil;
AVAsset* myAsset = [[AVURLAsset alloc] initWithURL:assetURL options:assetOptions];
self.imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:myAsset];
int duration = CMTimeGetSeconds([myAsset duration]);
for(int i = 0; i<duration; i++)
{
CGImageRef imgRef = [self.imageGenerator copyCGImageAtTime:CMTimeMake(i, duration) actualTime:NULL error:nil];
UIImage* thumbnail = [[UIImage alloc] initWithCGImage:imgRef scale:UIViewContentModeScaleAspectFit orientation:UIImageOrientationUp];
[thumbnailImages addObject:thumbnail];
}
I am using above code to get thumbnail images but the problem is if there is a 2 seconds video i am only getting 2 thumbnails but i want 20 thumbnails (10 thumbnail per second).
So, how to use CMTimeMake to get thumbnails for every .1 second
Code form reference site : Thumbnail image from Video
Objective - C
Swift
@Kirit Modi solution in Swift 3 with some small changes:
Following code for the getting the thumb image from video at
0.41