如何删除AVExportSession的AVMetadata

How to delete AVMetadata of AVExportSession

我正在 swift 4 中进行一些简单的视频编辑,使用 AVAsset() 读取视频,然后使用 AVExportSession 导出结果。一切正常,除了一件事:resulted 视频保留了 original 视频的元数据。 此元数据包括(例如)拍摄视频的时间和地点。 我看到AVExportSession有一个metadata:[AVMetadataItem]属性,但是不知道怎么用。我将它设置为 nil 但它不起作用,它仍然保留旧的元数据。 我阅读了 apple's documentation 的内容,它说您不能创建实例,也不能修改元数据项,那么我该怎么做?如何删除该元数据或将新生成的元数据写入其中? 有很多关于读取元数据的信息,但关于写入元数据的信息不多。

提前致谢。

附加链接 https://developer.apple.com/documentation/avfoundation/avassetexportsession

您可以使用 AVMetadataItemFilter.forSharing() 过滤元数据。 来自规范:Removes user-identifying metadata items, such as location information and leaves only metadata releated to commerce or playback itself.(参见 https://developer.apple.com/documentation/avfoundation/avmetadataitemfilter/1387905-forsharing

只需将其添加到您的导出会话:

let exportSession = AVExportSession() // choose your appropriate init
exportSession.metadataItemFilter = AVMetadataItemFilter.forSharing()