1

I am attempting to compress a video for use in Parse in swift however I am running into the issue of the video either being 9 MB if I set the quality to AVAssetExportPresetHighQuality or too low quality with AVAssetExportPresetMediumQuality (the video is very grainy and not suitable for any consumer to actually use). Are there any other methods to control the file size such as setting the bitrate while recording? My compression code is below and is very basic however it creates terrible quality videos. I would prefer to have the size of the file be around 1-3 MB and have alright quality however I cannot find any inbetween.

func compressVideo(inputURL: NSURL, outputURL: NSURL, handler:(session: AVAssetExportSession)-> Void)
{
    /*var settings: [NSObject : AnyObject] = [AVVideoCodecKey: AVVideoCodecH264, AVVideoWidthKey: 1080, AVVideoHeightKey: 1920, AVVideoCompressionPropertiesKey: [AVVideoAverageBitRateKey: 100, AVVideoProfileLevelKey: .Main31, AVVideoMaxKeyFrameIntervalKey: 30]]
    var writer_input: AVAssetWriterInput = AVAssetWriterInput.assetWriterInputWithMediaType(AVMediaTypeVideo, outputSettings: )*/

    let urlAsset = AVURLAsset(URL: inputURL, options: nil)

    let exportSession = AVAssetExportSession(asset: urlAsset, presetName: AVAssetExportPresetMediumQuality)

    exportSession!.outputURL = outputURL

    exportSession!.outputFileType = AVFileTypeQuickTimeMovie

    exportSession!.shouldOptimizeForNetworkUse = true

    exportSession!.exportAsynchronouslyWithCompletionHandler { () -> Void in

        handler(session: exportSession!)
    }

}
maz
  • 349
  • 2
  • 3
  • 15
  • This got me learning more about bit rate and quality of videos: http://stackoverflow.com/questions/11751883/how-can-i-reduce-the-file-size-of-a-video-created-with-uiimagepickercontroller/11819382#11819382 – Taku Jul 22 '16 at 16:48

0 Answers0