0
我想要的是,當用戶從圖庫中選擇視頻時,我想獲取視頻的縮略圖。因此,是否可以獲取視頻的縮略圖圖像而無需將其上傳到服務器?如何在沒有網絡呼叫服務器的情況下生成視頻縮略圖iOS?
我想要的是,當用戶從圖庫中選擇視頻時,我想獲取視頻的縮略圖。因此,是否可以獲取視頻的縮略圖圖像而無需將其上傳到服務器?如何在沒有網絡呼叫服務器的情況下生成視頻縮略圖iOS?
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL *urlvideo = [info objectForKey:UIImagePickerControllerMediaURL];
__block NSData *movieData = [[NSData alloc]initWithContentsOfURL:urlvideo];AVURLAsset *asset=[[AVURLAsset alloc] initWithURL:urlvideo options:nil];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generator.appliesPreferredTrackTransform=TRUE;
CMTime thumbTime = CMTimeMakeWithSeconds(0,30);
AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error){
if (result != AVAssetImageGeneratorSucceeded) {
NSLog(@"couldn't generate thumbnail, error:%@", error);
}
UIImage *img = [UIImage imageWithCGImage:im];
};
}