【发布时间】:2021-02-23 00:09:30
【问题描述】:
目前,我正在为 PHAsset 的图像提取 EXIF 元数据,但对视频没有运气。
对于图像,这对我有用:
let imageOptions = PHImageRequestOptions()
imageOptions.isNetworkAccessAllowed = true
imageOptions.isSynchronous = true
imageOptions.version = .current
PHImageManager.default().requestImageDataAndOrientation(for: self.asset!, options: imageOptions) { (data, responseString, orientation, info) in
if let imageData: Data = data {
if let imageSource = CGImageSourceCreateWithData(imageData as CFData, nil) {
let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil)! as NSDictionary
}
}
})
我需要进行哪些更改才能检索视频资产的元数据?
self.asset!.mediaType == .video
更新
在第一个答案之后,我尝试学习: https://developer.apple.com/documentation/avfoundation/media_assets_and_metadata/retrieving_media_metadata
到目前为止,我仍然无法理解这个概念。我试过了:
let formatsKey = "availableMetadataFormats"
asset.loadValuesAsynchronously(forKeys: [formatsKey]) {
var error: NSError? = nil
let status = asset.statusOfValue(forKey: formatsKey, error: &error)
if status == .loaded {
for format in asset.availableMetadataFormats {
let metadata = asset.metadata(forFormat: format)
print (metadata)
}
}
}
我无法提取 PHImageManager.default().requestAVAsset 中的任何内容,结果为空。
我需要的是视频 fps/编解码器/声音(立体声或单声道)/色彩空间。这就对了。我能够到达某个地方:
if let videoTrack = asset.tracks(withMediaType: .video).first {
let videoFormatDescription = videoTrack.formatDescriptions.first as! CMVideoFormatDescription
print (videoFormatDescription)
}
在CMVideoFormatDescription 中,似乎大多数必需的属性都存在,但目前我无法提取它们。
【问题讨论】:
-
“目前,我正在为 PHAsset 提取图像的 EXIF 元数据,但对图像不满意”不清楚。其中一个词应该是“视频”吗?
-
确实如此。已更正。
标签: ios swift video phasset phimagemanager