獲取相冊視頻數據的URL時会前,因為獲取到的對象不是AVURLAsset僻爽,而是AVComposition導致的,因為AVComposition沒有URL屬性
func aaa() {
if let asset = avAsset as? AVComposition,
asset.tracks.count == 2 {// 慢動作視頻
self?.dealSVideo(asset, currentAsset)
}
}
func dealSVideo(_ asset: AVComposition) {
let creater: (URL) -> Void = { dir in
if !FileManager.default.fileExists(atPath: dir.path) {
do {
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
} catch {
//--
}
}
}
// 創(chuàng)建文件夾
creater(videoDirectory)
let path = videoDirectory.appendingPathComponent("\(fileName).mp4").path
if FileManager.default.fileExists(atPath: path) {
已導出過-直接使用path
} else {
*******HUD show(因為比較耗時)***
let exporter = AVAssetExportSession(asset: asset,
presetName: AVAssetExportPresetMediumQuality)
exporter?.outputURL = URL(fileURLWithPath: path)
exporter?.outputFileType = .mov
exporter?.shouldOptimizeForNetworkUse = true
exporter?.exportAsynchronously {
DispatchQueue.main.async {
*******HUD dissmiss***
if exporter?.status == .completed {
已導出成功-直接使用path
}
}
}
}
}
參考鏈接:
http://www.reibang.com/p/486de4f331db 本文章的swift版本
http://www.reibang.com/p/f0b299a2f2d5 此文章兼容方式不可用