1
-(UIImage*)fFirstVideoFrame:(NSString*)path
{
MPMoviePlayerController*mp = [[MPMoviePlayerControlleralloc]
initWithContentURL:[NSURLfileURLWithPath:path]];
UIImage*img = [mpthumbnailImageAtTime:0.0
timeOption:MPMovieTimeOptionNearestKeyFrame];
[mpstop];
returnimg;
}
2
+(UIImage*)thumbnailImageRequest:(CGFloat)timeBySecond putStr:(NSString*)_urlStr{
//創(chuàng)建URL
NSURL*url=[NSURLfileURLWithPath:_urlStr];
//根據url創(chuàng)建AVURLAsset
AVURLAsset*urlAsset=[AVURLAssetassetWithURL:url];
//根據AVURLAsset創(chuàng)建AVAssetImageGenerator
AVAssetImageGenerator*imageGenerator=[AVAssetImageGeneratorassetImageGeneratorWithAsset:urlAsset];
/*截圖
* requestTime:縮略圖創(chuàng)建時間
* actualTime:縮略圖實際生成的時間
*/
NSError*error=nil;
CMTimetime=CMTimeMakeWithSeconds(timeBySecond,10);//CMTime是表示電影時間信息的結構體旗芬,第一個參數表示是視頻第幾秒,第二個參數表示每秒幀數.(如果要活的某一秒的第幾幀可以使用CMTimeMake方法)
CMTimeactualTime;
CGImageRefcgImage= [imageGeneratorcopyCGImageAtTime:timeactualTime:&actualTimeerror:&error];
if(error){
NSLog(@"截取視頻縮略圖時發(fā)生錯誤捆蜀,錯誤信息:%@",error.localizedDescription);
//return;
}
CMTimeShow(actualTime);
UIImage*image=[UIImageimageWithCGImage:cgImage];//轉化為UIImage
returnimage;
}