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 >
Code:
/** * 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.