ios音频格式转换 swift版

// 仅仅转换格式

func convertVideoQuailtyWithInputURL(inputUrl:NSURL,outputUrl:NSURL,completeHandler:(handler:AVAssetExportSession)->Void)->Void{

let avAsset = AVURLAsset.init(URL: inputUrl, options: nil)

let exportSession = AVAssetExportSession.init(asset: avAsset, presetName: AVAssetExportPresetHighestQuality  //输出质量)

exportSession?.outputFileType = AVFileTypeMPEG4  //类型

exportSession?.outputURL = outputUrl

exportSession?.shouldOptimizeForNetworkUse = true

exportSession?.exportAsynchronouslyWithCompletionHandler({ () -> Void in

switch exportSession!.status {

case AVAssetExportSessionStatus.Cancelled:

print("AVAssetExportSessionStatusCancelled")

case AVAssetExportSessionStatus.Unknown:

print("AVAssetExportSessionStatusUnknown")

case AVAssetExportSessionStatus.Waiting:

print("AVAssetExportSessionStatus.Waiting")

case AVAssetExportSessionStatus.Exporting:

print("AVAssetExportSessionStatus.Exporting")

case AVAssetExportSessionStatus.Completed:  //转码完成后在这里操作后续

print("AVAssetExportSessionStatusCompleted")

print("=====\(self.getVideoLength(outputUrl))")

print("=====\(self.getFileSize(outputUrl.path!))")

completeHandler(handler: exportSession!)

default:

break

}

})

}

你可能感兴趣的:(ios音频格式转换 swift版)