Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a thumbnail from a video url or data in iOS

I am trying to acquire a thumbnail (of the first frame) from a video taken from iphone 3GS camera so I can display it. How to do this?

like image 972
Daniel Avatar asked Aug 28 '09 14:08

Daniel


People also ask

What is a thumbnail URL?

The local file URL of the thumbnail image for the item.


1 Answers

-(UIImage *)generateThumbImage : (NSString *)filepath {     NSURL *url = [NSURL fileURLWithPath:filepath];      AVAsset *asset = [AVAsset assetWithURL:url];     AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc]initWithAsset:asset];     imageGenerator.appliesPreferredTrackTransform = YES;     CMTime time = [asset duration];     time.value = 0;     CGImageRef imageRef = [imageGenerator copyCGImageAtTime:time actualTime:NULL error:NULL];     UIImage *thumbnail = [UIImage imageWithCGImage:imageRef];     CGImageRelease(imageRef);  // CGImageRef won't be released by ARC      return thumbnail; } 

you can get the frame using the time.value suppose you want to 1 second frame then use the

time.value = 1000 //Time in milliseconds 
like image 115
Diken Shah Avatar answered Sep 20 '22 04:09

Diken Shah