PHAsset 视频 EXIF 元数据检索

问题描述

目前,我正在为 PHAsset 提取 EXIF 元数据,这些元数据是图像,但在视频方面没有运气。

对于图像,这对我有用:

for(i in 1:n)
   fun(input1[i],input2[i],...,inputk[i])

为检索视频资产的元数据需要进行哪些更改?

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,nil)! as NSDictionary

   }
 }

})

更新

一个回答后,我尝试学习: https://developer.apple.com/documentation/avfoundation/media_assets_and_metadata/retrieving_media_metadata

到目前为止,我仍然无法理解这个概念。我试过了:

self.asset!.mediaType == .video

我无法从 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) } } } 提取任何内容,结果为空。

我需要的是视频 fps/编解码器/声音(立体声或单声道)/色彩空间。这就对了。我可以通过以下方式到达某个地方:

PHImageManager.default().requestAVAsset

if let videoTrack = asset.tracks(withMediaType: .video).first { let videoFormatDescription = videoTrack.formatDescriptions.first as! CMVideoFormatDescription print (videoFormatDescription) } 中,大多数必需的属性似乎都存在,但到目前为止我无法提取它们。

解决方法

调用 requestAVAsset(forVideo:options:resultHandler:)。现在你有一个 AVAsset。它具有 metadatacommonMetadata 属性,您可以参加比赛了。