我的测量时间从几十秒到几分钟,具体取决于视频的大小。这个更改请求是否应该快速(本地闪存盘复制/元数据/校验和),因为它将本地视频添加到photolibrary /相机胶卷? 当打开iCloud备份时,似乎会出现此问题。我无法通过网络搜索或apple dev文档找到更多有用的信息。
示例代码:
func exportAssetToPhotoLibrary(videoURL: NSURL, _ exportedAsset: (localIdentifier: String) -> Void) {
var localIdentifier = ""
var startTime = NSDate.timeIntervalSinceReferenceDate()
PHPhotoLibrary.sharedPhotoLibrary().performChanges({
let assetRequest = PHAssetChangeRequest.creationRequestForAssetFromVideoAtFileURL(videoURL)
let assetPlaceholder = assetRequest.placeholderForCreatedAsset
localIdentifier = assetPlaceholder.localIdentifier
},
completionHandler: { success, error in
var elapsedTime: NSTimeInterval = NSDate.timeIntervalSinceReferenceDate() - startTime
NSLog("exported cameo video to photo library \(elapsedTime)")
exportedAsset(localIdentifier: localIdentifier)
})
}