let exportSession = AVAssetExportSession.init(asset: asset, presetName: AVAssetExportPresetHighestQuality)
// remove file if already exits
let fileManager = FileManager.default
do{
try? fileManager.removeItem(at: outputUrl)
}catch{
print("can't")
}
exportSession?.outputFileType = AVFileTypeMPEG4
exportSession?.outputURL = outputUrl
exportSession?.metadata = asset.metadata
exportSession?.exportAsynchronously(completionHandler: {
if (exportSession?.status == .completed)
{
print("AV export succeeded.")
// outputUrl to post Audio on server
}
else if (exportSession?.status == .cancelled)
{
print("AV export cancelled.")
}
else
{
print ("Error is \(String(describing: exportSession?.error))")
}
})
对,我就是这么折腾
参考:
https://stackoverflow.com/questions/45974974/how-to-convert-caf-audio-file-into-mp4-file-in-swift