0

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358

1 Answers1

0

You can use AVAssetExportPresetMediumQuality for better quality than AVAssetExportPresetLowQuality.

Or you can use AVAssetWriter for more cutomization

Aznix
  • 337
  • 3
  • 8