IOS cut video footage into a thumbnail _ios

Source: Internet
Author: User
Tags generator

This example for you to share the iOS video clips into thumbnails of specific code, for your reference, the specific content as follows

Remember to import system library

#import < Mediaplayer/mediaplayer.h >


/** * Access to all thumbnail methods for network video * * @param videourl video link Address * * @return Video screenshot/+ (UIImage *) Ihefe_previewimagewithvideourl: (N

 sURL *) Videourl {avasset *asset = [Avasset Assetwithurl:videourl];
 Avassetimagegenerator *generator = [Avassetimagegenerator assetimagegeneratorwithasset:asset];

 Generator.appliespreferredtracktransform = YES;
 Cgimageref img = [Generator copycgimageattime:cmtimemake (1, Asset.duration.timescale) actualtime:null Error:nil];

 UIImage *image = [UIImage imagewithcgimage:img];
 Cgimagerelease (IMG);
return image; /** * Get all thumbnail methods for local video * * @param fileurl video link Address * * @return Video screenshot/+ (UIImage *) ihefe_getscreenshotimagefromvide
 Ourl: (NSString *) FileURL {uiimage *shotimage;

 Video path URL Nsurl *fileurl = [Nsurl Urlwithstring:fileurl];

 Avurlasset *asset = [[Avurlasset alloc] Initwithurl:fileurl 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];

 Shotimage = [[UIImage alloc] initwithcgimage:image];

 Cgimagerelease (image);
return shotimage; /** * Get a frame thumbnail method of video * * @param videourl video link Address frame time * @param time frame * * @return Video screenshot/+ (uiimage*) Ihefe_thu Mbnailimageforvideo: (Nsurl *) Videourl attime: (nstimeinterval) Time {avurlasset *asset = [[Avurlasset alloc] InitWithURL
 : Videourl Options:nil];
 Nsparameterassert (asset);
 Avassetimagegenerator *assetimagegenerator = [[Avassetimagegenerator alloc] initwithasset:asset];
 Assetimagegenerator.appliespreferredtracktransform = YES;

 Assetimagegenerator.aperturemode = Avassetimagegeneratoraperturemodeencodedpixels;
 Cgimageref thumbnailimageref = NULL;
 Cftimeinterval thumbnailimagetime = time;
 Nserror *thumbnailimagegenerationerror = nil; Thumbnailimageref = [Assetimagegenerator copycgimageattime:cmtimemake (Thumbnailimagetime) Actualtime:null error:&thumbnailimagegenerationerror];

 if (!thumbnailimageref) NSLog (@ "Thumbnailimagegenerationerror%@", thumbnailimagegenerationerror); UIImage *thumbnailimage = thumbnailimageref?

 [[UIImage alloc] initwithcgimage:thumbnailimageref]: nil;
return thumbnailimage;


The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.