亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

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

記得導入系統(tǒng)庫

#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 視頻的鏈接地址 幀時間
 * @param time  幀時間
 *
 * @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;
}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論