目前,我正在提取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
中提取任何内容,结果为空。我需要的是视频帧率 / 编解码器 / 音频(立体声或单声道)/ 色彩空间。这就是全部。我已经通过以下方式得到了一些进展:
if let videoTrack = asset.tracks(withMediaType: .video).first {
let videoFormatDescription = videoTrack.formatDescriptions.first as! CMVideoFormatDescription
print (videoFormatDescription)
}
在 CMVideoFormatDescription
中,大多数所需的属性似乎都已经存在,但是目前我无法提取它们。