iOS get thumbnail method for local video and web URL videowords 222 read 612 Comments 0 likes
First of all, add avfoundation and coremedia.framework two frames
- First local video get thumbnail image
NSString *path = @"www.51ios.net/本地路径"MPMoviePlayerController *51iosMPMovie = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:path]]; UIImage *img = [51iosMPMovie thumbnailImageAtTime:0.0timeOption:MPMovieTimeOptionNearestKeyFrame];此处的img就是时间在0.0的缩略图
- The second way to get a thumbnail image of a network video
NSString *videoURL = @"http://www.51ios.net/archives/784"MPMoviePlayerController *51iosMPMovie = [[MPMoviePlayerController alloc]initWithContentURL:videoURL]; 51iosMPMovie.shouldAutoplay = NO;UIImage *thumbnail = [51iosMPMovie thumbnailImageAtTime:time timeOption:MPMovieTimeOptionNearestKeyFrame];此处的thumbnail就是网络视频的缩略图
- The third station method is realized with Avfoundation
+(UIImage *) Getthumbnailimage: (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 copy Cgimageattime:time Actualtime:&actualtime error:&error]; uiimage *thumb = [[uiimage alloc] Initwithcgimage:image"; cgimagerelease (image); return thumb;}
iOS gets thumbnail methods for local video and network URL video