-2

I am recording video with a camera that returns .mov format then I export that video in .mp4 format and change the Quality to reduce the size of the video with the following code...

   func convertMOVtoMP4(inputURL: URL, outputURL: URL, completion: @escaping (Bool) -> Void) {
        let asset = AVURLAsset(url: inputURL)
        
        DispatchQueue.main.async {
            guard let exportSession = AVAssetExportSession(asset: asset,
                                                           presetName: AVAssetExportPreset960x540) else {
                completion(false)
                return
            }
            
            exportSession.outputURL = outputURL
            exportSession.outputFileType = .mp4
            exportSession.shouldOptimizeForNetworkUse = true
            
            exportSession.exportAsynchronously {
                switch exportSession.status {
                case .completed:
                    completion(true)
                default:
                    completion(false)
                }
            }
        }
    }

How can I modify the frame rate and bit rate when exporting video in mp4 ...

Wahab Khan Jadon
  • 875
  • 13
  • 21
  • What matters more for file size than container format (.mov , .mp4) is the codec type , e.g. mpeg2, h264, .. – soundflix Aug 03 '23 at 06:58

1 Answers1

0
let videoSettings:[String:Any] = [
        AVVideoCompressionPropertiesKey: [AVVideoAverageBitRateKey: self.bitrate],
        AVVideoCodecKey: AVVideoCodecType.h264,
        AVVideoHeightKey: videoTrack.naturalSize.height,
        AVVideoWidthKey: videoTrack.naturalSize.width,
        AVVideoScalingModeKey: AVVideoScalingModeResizeAspectFill
    ]

let bitrate: NSNumber = NSNumber(value: 1250000) // *** you can change this number to increase/decrease the quality. The more you increase, the better the video quality but the the compressed file size will also increase

I have update my answer

Chandaboy
  • 1,302
  • 5
  • 10
  • I am already exporting the video in `.mp4` and it's working fine... I want to modify the frame rate and bit rate of the video during export... – Wahab Khan Jadon Aug 02 '23 at 11:35
  • 2
    hmm then please check this link https://stackoverflow.com/questions/11751883/how-can-i-reduce-the-file-size-of-a-video-created-with-uiimagepickercontroller – Chandaboy Aug 02 '23 at 11:46