image - iOS - How to get thumbnail from video without play? -
i'm trying thumbnail video , show in tableview. here code:
- (uiimage *)imagefromvideourl:(nsurl *)contenturl { avasset *asset = [avasset assetwithurl:contenturl]; // thumbnail @ start of video cmtime thumbnailtime = [asset duration]; thumbnailtime.value = 25; // image video @ given time avassetimagegenerator *imagegenerator = [[avassetimagegenerator alloc] initwithasset:asset]; cgimageref imageref = [imagegenerator copycgimageattime:thumbnailtime actualtime:null error:null]; uiimage *thumbnail = [uiimage imagewithcgimage:imageref]; cgimagerelease(imageref); return thumbnail; }
but image allways return black. what's wrong?
nsurl *videourl = [nsurl fileurlwithpath:filepath];// filepath video file path avurlasset *asset = [[avurlasset alloc] initwithurl:videourl options:nil]; avassetimagegenerator *generateimg = [[avassetimagegenerator alloc] initwithasset:asset]; nserror *error = null; cmtime time = cmtimemake(1, 1); cgimageref refimg = [generateimg copycgimageattime:time actualtime:null error:&error]; nslog(@"error==%@, refimage==%@", error, refimg); uiimage *frameimage= [[uiimage alloc] initwithcgimage:refimg]; return frameimage;
Comments
Post a Comment