I'm currently exporting a video in the following way:
let exporter = AVAssetExportSession.init(asset: mixComposition, presetName: AVAssetExportPreset1280x720)
exporter?.outputURL = outputPath
exporter?.outputFileType = AVFileType.mp4
exporter?.shouldOptimizeForNetworkUse = true
exporter?.videoComposition = mainCompositionInst
A 15s video consumes about 20MB in data. Comparing this to Snapchat's 2MB videos, this number seems totally unacceptable.
I already reduced the quality of the export- and capture session (1280x720).
The video is filmed on a custom camera. UIImagePickerController
is not used.
AVAssetExportSession is used with default settings.
Is there any way I can reduce the size of my videos? Thanks a lot!
EDIT 1: I tried to use this library: https://cocoapods.org/pods/NextLevelSessionExporter
Unfortunately, this creates sizing problems and removes my audio:
// Creating exporter
let exporter = NextLevelSessionExporter(withAsset: mixComposition)
exporter.outputURL = outputPath
exporter.outputFileType = AVFileType.mp4
exporter.videoComposition = mainCompositionInst
let compressionDict: [String: Any] = [
AVVideoAverageBitRateKey: NSNumber(integerLiteral: 2500000),
AVVideoProfileLevelKey: AVVideoProfileLevelH264BaselineAutoLevel as String,
]
exporter.videoOutputConfiguration = [
AVVideoCodecKey: AVVideoCodecType.h264,
AVVideoWidthKey: NSNumber(integerLiteral: 1280),
AVVideoHeightKey: NSNumber(integerLiteral: 720),
AVVideoScalingModeKey: AVVideoScalingModeResizeAspectFill,
AVVideoCompressionPropertiesKey: compressionDict
]
exporter.audioOutputConfiguration = [
AVFormatIDKey: kAudioFormatMPEG4AAC,
AVEncoderBitRateKey: NSNumber(integerLiteral: 128000),
AVNumberOfChannelsKey: NSNumber(integerLiteral: 2),
AVSampleRateKey: NSNumber(value: Float(44100))
]