AVAsset
似乎唯一有效的方法是从请求PHImageManager
,并检查返回的资产是否为AVURLAsset
. 在这种情况下,URL 可用于直接访问文件并获取所需的字节块:
[[PHImageManager defaultManager] requestAVAssetForVideo:videoAsset options:nil resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
if ([asset isKindOfClass:[AVURLAsset class]]) {
NSURL *URL = [(AVURLAsset *)asset URL];
// use URL to get file content
}
}];
这不适用于慢动作视频,因为AVComposition
而不是AVURLAsset
返回。可能的解决方案是使用PHVideoRequestOptionsVersionOriginal
视频文件版本:
PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
options.version = PHVideoRequestOptionsVersionOriginal;
[[PHImageManager defaultManager] requestAVAssetForVideo:videoAsset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
if ([asset isKindOfClass:[AVURLAsset class]]) {
NSURL *URL = [(AVURLAsset *)asset URL];
// use URL to get file content
}
}];
并获得全尺寸图片网址:
PHContentEditingInputRequestOptions *options = [[PHContentEditingInputRequestOptions alloc] init];
options.canHandleAdjustmentData = ^BOOL(PHAdjustmentData *adjustmentData) {
return YES;
};
[imageAsset requestContentEditingInputWithOptions:options completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
// use contentEditingInput.fullSizeImageURL
}];