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{
//创建URL
NSURL*url=[NSURLfileURLWithPath:_urlStr];
//根据url创建AVURLAsset
AVURLAsset*urlAsset=[AVURLAssetassetWithURL:url];
//根据AVURLAsset创建AVAssetImageGenerator
AVAssetImageGenerator*imageGenerator=[AVAssetImageGeneratorassetImageGeneratorWithAsset:urlAsset];
/*截图
* requestTime:缩略图创建时间
* actualTime:缩略图实际生成的时间
*/
NSError*error=nil;
CMTimetime=CMTimeMakeWithSeconds(timeBySecond,10);//CMTime是表示电影时间信息的结构体,第一个参数表示是视频第几秒,第二个参数表示每秒帧数.(如果要活的某一秒的第几帧可以使用CMTimeMake方法)
CMTimeactualTime;
CGImageRefcgImage= [imageGeneratorcopyCGImageAtTime:timeactualTime:&actualTimeerror:&error];
if(error){
NSLog(@"截取视频缩略图时发生错误,错误信息:%@",error.localizedDescription);
//return;
}
CMTimeShow(actualTime);
UIImage*image=[UIImageimageWithCGImage:cgImage];//转化为UIImage
returnimage;
}
网友评论