欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS將視頻錄像切成一張張縮略圖

 更新時(shí)間:2016年11月24日 10:06:05   作者:Hanrovey  
這篇文章主要為大家詳細(xì)介紹了iOS將視頻錄像切成一張張縮略圖的相關(guān)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了iOS視頻錄像切成縮略圖的具體代碼,供大家參考,具體內(nèi)容如下

記得導(dǎo)入系統(tǒng)庫(kù)

#import < MediaPlayer/MediaPlayer.h >

代碼:

/**
 * 獲取網(wǎng)絡(luò)視頻的全部縮略圖方法
 *
 * @param videoURL 視頻的鏈接地址
 *
 * @return 視頻截圖
 */
+ (UIImage *)ihefe_previewImageWithVideoURL:(NSURL *)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;
}

/**
 * 獲取本地視頻的全部縮略圖方法
 *
 * @param fileurl 視頻的鏈接地址
 *
 * @return 視頻截圖
 */
+ (UIImage *)ihefe_getScreenShotImageFromVideoURL:(NSString *)fileurl
{

 UIImage *shotImage;
 //視頻路徑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;
}

/**
 * 獲取視頻的某一幀縮略圖方法
 *
 * @param videoURL 視頻的鏈接地址 幀時(shí)間
 * @param time  幀時(shí)間
 *
 * @return 視頻截圖
 */
+ (UIImage*)ihefe_thumbnailImageForVideo:(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, 60) actualTime:NULL error:&thumbnailImageGenerationError];

 if (!thumbnailImageRef) NSLog(@"thumbnailImageGenerationError %@", thumbnailImageGenerationError);

 UIImage *thumbnailImage = thumbnailImageRef ? [[UIImage alloc] initWithCGImage:thumbnailImageRef] : nil;

 return thumbnailImage;
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論