IOS get thumbnails of local videos(2012-10-10 20:06:27)
reproduced
Tags: video thumbnails local gossip |
Category: iOS |
+ (UIImage *) GetImage: (NSString *) Videourl
{
Avurlasset *asset = [[Avurlasset alloc] Initwithurl:[nsurl Fileurlwithpath:videourl] options:nil];
Avassetimagegenerator *gen = [[Avassetimagegenerator alloc] initwithasset:asset];
Gen.appliespreferredtracktransform = YES;
Cmtime time = cmtimemakewithseconds (0.0, 600);
Nserror *error = nil;
Cmtime Actualtime;
Cgimageref image = [Gen Copycgimageattime:time actualtime:&actualtime error:&error];
UIImage *thumb = [[UIImage alloc] initwithcgimage:image];
Cgimagerelease (image);
return thumb;
}
Need to add avfoundation and Coremedia.framework
The other way.
MPMoviePlayerController *MoviePlayer= [[MPMoviePlayerControllerAlloc]Initwithcontenturl:videourl]; MoviePlayer. Shouldautoplay = NO;
UIImage *thumbnail = [movieplayer thumbnailimageattime: Timetimeoption: Mpmovietimeoptionnearestkeyframe];
It's the same thing.
+ (UIImage *) Ffirstvideoframe: (NSString *) path
{
MPMoviePlayerController *MP = [[MPMoviePlayerController alloc]
Initwithcontenturl:[nsurl Fileurlwithpath:path]];
UIImage *img = [MP thumbnailimageattime:0.0
Timeoption:mpmovietimeoptionnearestkeyframe];
[MP stop];
[MP release];
return img;
}
IOS get thumbnails of local videos