获取相册视频数据的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 {
//--
}
}
}
// 创建文件夹
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
}
}
}
}
}
参考链接:
https://www.jianshu.com/p/486de4f331db 本文章的swift版本
https://www.jianshu.com/p/f0b299a2f2d5 此文章兼容方式不可用