+ (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 = [[MPMoviePlayerController alloc]initWithContentURL:videoURL]; moviePlayer.shouldAutoplay = NO;
UIImage *thumbnail = [moviePlayer thumbnailImageAtTime:time timeOption: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;
}
Ext: http://blog.sina.com.cn/s/blog_6d01cce301019xym.html