如何使用PhotoKit访问慢动作视频的NSData / NSURL [英] How to access NSData/NSURL of slow motion videos using PhotoKit
问题描述
使用新的Photo框架,我可以使用 requestImageDataForAsset
访问PHAssets的 NSData
。我还可以使用返回的 info NSDictionary
的 PHImageFileURLKey
来访问文件URL。
Working with new Photo framework, I can access the NSData
of PHAssets using requestImageDataForAsset
. I can also access the file URL using the PHImageFileURLKey
of the returned info NSDictionary
.
[[PHImageManager defaultManager] requestImageDataForAsset:asset options:nil resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
//imageData contains the correct data for images and videos
NSLog(@"info - %@", info);
NSURL* fileURL = [info objectForKey:@"PHImageFileURLKey"];
}];
这适用于图片和普通视频。
This works fine for images and normal videos.
但是,当资产是PHAssetMediaSubtypeVideoHighFrameRate(慢动作视频)时,返回的数据对应于包含视频第一帧的JPG文件(NSData,dataUTI和信息字典都指向同一个jpg文件) 。例如,这是为慢动作视频返回的URL和dataUTI:
However, when the asset is a PHAssetMediaSubtypeVideoHighFrameRate (slow motion video), the returned data corresponds to a JPG file containing the first frame of the video (both the NSData, the dataUTI and the info dictionary point to the same jpg file). As example, this is the URL and the dataUTI returned for a slow motion video:
PHImageFileURLKey =
file:// /var/mobile/Media/PhotoData/Metadata/DCIM/100APPLE/IMG_0642.JPG;
PHImageFileUTIKey =public.jpeg;
PHImageFileURLKey = "file:///var/mobile/Media/PhotoData/Metadata/DCIM/100APPLE/IMG_0642.JPG"; PHImageFileUTIKey = "public.jpeg";
为什么会这样?
如何访问慢动作视频的NSData / NSURL而不是JPG预览?
Why is this happening? How can i access the NSData/NSURL of the slow motion video instead of this JPG preview?
推荐答案
坚果和测试每一个选项我发现了问题。
After going nuts and testing every single option I found the problem.
为慢动作视频返回JPG图像的责任是的默认
property。 PHImageRequestOptionsVersionCurrent
值> PHImageRequestOptions.version
The responsable of returning JPG images for slow motion videos is the default PHImageRequestOptionsVersionCurrent
value for the PHImageRequestOptions.version
property.
只需将版本分配给PHImageRequestOptionsVersionUnadjusted或PHImageRequestOptionsVersionOriginal将返回原始慢动作视频。
Simply assign the version to PHImageRequestOptionsVersionUnadjusted or PHImageRequestOptionsVersionOriginal will return the original slow motion video.
PHImageRequestOptions * imageRequestOptions = [[PHImageRequestOptions alloc] init];
imageRequestOptions.version = PHImageRequestOptionsVersionUnadjusted;
// or
imageRequestOptions.version = PHImageRequestOptionsVersionOriginal;
我认为这是一种意想不到的行为,因为我不期待当前版本的慢动作视频是静止图像(可能是应用了慢动作效果的视频,但不是照片)。
I consider this as an unexpected behaviour, since i am not expecting that the "current" version of a slow motion video is a still image (maybe a video with the slow motion effect applied, but not a photo).
希望这对某人有用。
这篇关于如何使用PhotoKit访问慢动作视频的NSData / NSURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!