-1
我試圖實例化PHLivePhoto
,但每當我嘗試保存構成實況照片的視頻時,我都無法使其正常工作。如何將視頻保存到Swift Playgrounds中的URL
這裏有一個小的代碼片段,我寫的是處理出口視頻:
public func exportFilteredVideo(to outputURL: URL, completion: @escaping (Void) -> Void) {
if FileManager.default.fileExists(atPath: outputURL.path) {
try? FileManager.default.removeItem(at: outputURL)
}
let export = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetMediumQuality)!
export.outputFileType = AVFileTypeQuickTimeMovie
export.outputURL = outputURL
export.videoComposition = generateComposition()
export.exportAsynchronously(completionHandler: completion)
}
這是當我嘗試檢索視頻:
let destURL = url.deletingLastPathComponent().appendingPathComponent("Test.mov")
pixellationFilter.exportFilteredVideo(to: destURL) {
print(try! destURL.checkResourceIsReachable()) //An error is thrown! Why though, isn't the export completed?
}
目前,我懷疑是您可能無法寫入指定的URL
。但是,我的理解是,無論何時我想創建PHLivePhoto
對象,我都需要將資源指定爲URL
而不是Data
。如果這是可能的,我可以改爲使用數據,而不是將其導出到URL
。我可能是錯的,但我並沒有真的找到一種方法來創建與Data
PHLivePhoto
。有一個PHAssetResource
類,但只有幫助獲取PHLivePhoto
的數據文件不創建PHLivePhoto
。
所以我可能的解決方案,我相信在這一刻是:
- 圖出來我如何可以將視頻保存爲
URL
。 - 嘗試通過
Data
而不是URL
創建實時照片。
fileURL它就是數據所在的位置 –
@LeoDabus同意,但創建PHLivePhoto時,我需要使用此方法:request(使用資源文件URL:佔位符Image:target尺寸:內容模式:結果處理:)'。正如你所看到的,它將'[URL]'作爲參數而不是'Data'。 – Harish
@LeoDabus以下是相關文檔:https://developer.apple.com/reference/photos/phlivephoto/1616434-request – Harish