iOS get thumbnail method for local video and web URL video

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.