我试图从iphone 3GS相机拍摄的视频中获取(第一帧的)缩略图,以便我可以显示它.这该怎么做?
我正在尝试从视频中获取缩略图并在我的tableview中显示它.这是我的代码:
- (UIImage *)imageFromVideoURL:(NSURL *)contentURL {
AVAsset *asset = [AVAsset assetWithURL:contentURL];
// Get thumbnail at the very start of the video
CMTime thumbnailTime = [asset duration];
thumbnailTime.value = 25;
// Get image from the video at the given time
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
CGImageRef imageRef = [imageGenerator copyCGImageAtTime:thumbnailTime actualTime:NULL error:NULL];
UIImage *thumbnail = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return thumbnail;
}
Run Code Online (Sandbox Code Playgroud)
但是图像总是回归黑色.怎么了?