This is the function I use to compress video files in Swift:
private func compressVideo(inputURL: URL, outputURL: URL, handler:@escaping (_ exportSession: AVAssetExportSession?)-> Void) {
let urlAsset = AVURLAsset(url: inputURL, options: nil)
guard let exportSession = AVAssetExportSession(asset: urlAsset, presetName: AVAssetExportPresetLowQuality) else {
handler(nil)
return
}
exportSession.outputURL = outputURL
exportSession.outputFileType = AVFileType.mp4
exportSession.shouldOptimizeForNetworkUse = true
exportSession.exportAsynchronously { () -> Void in
handler(exportSession)
}
}
But the result is not as I expect;) For example, when I have 17MB size before compression, then as output I get 0.6MB. Is it possible to set somewhere type of compression or something like this to get a result with better quality? I will have satisfied when I get ~2MB file size in output.