1

I am using a UIImagePickerController to record a video and I need a video with max duration of 30 sec or max size of 40 MB. By default i have set it videoMaximumDuration, but I don't know how to restrict the maximum size of a video and is there any idea to limit a video size?

  • I think You cannot limit video size because user can select any size of video. You can compress it before sending to server. – Kishan Bhatiya Jan 03 '20 at 06:10

1 Answers1

0

Please refer this library https://github.com/zhangao0086/DKImagePickerController

let maxDuration:Float64 = 60
let videoDuration = asset!.duration
let videoDurationSeconds = CMTimeGetSeconds(videoDuration)

   if videoDurationSeconds > maxDuration {
       if UIVideoEditorController.canEditVideoAtPath(asset!.URL.path!) {
              let videoEditor = UIVideoEditorController()
              self.videoEditor.videoPath = asset!.URL.path!
              self.videoEditor.videoMaximumDuration = 60.0
              self.presentViewController(self.videoEditor, animated: true, completion: nil)

             }

         }


// MARK: - UIVideoEditorControllerDelegate

func videoEditorController(editor: UIVideoEditorController, didSaveEditedVideoToPath editedVideoPath: String) { 

                 self.videoEditor.dismissViewControllerAnimated(true, completion: nil)
                            //Do whatever you wish with the trimmed video here
                        }
Jawad Ali
  • 13,556
  • 3
  • 32
  • 49
Himanshu Patel
  • 1,015
  • 8
  • 26