I am creating an application in which I need to record a video and upload it to a server. Now my project also has an Android version. To support the Android version, I have to record videos in mp4 format. I followed this tutorial to set the UIImagePicker media type to the movie format imagePicker.mediaTypes = [kUTTypeMovie as String]
UIImagePickerController perfect for my requirement, and the only thing I need to change is its save format in mp4. I tried kUTTypeMPEG4 in mediaTypes , but it throws an error at runtime without describing the error.
This is my video capture feature.
func startCameraFromViewController() { if UIImagePickerController.isSourceTypeAvailable(.Camera) == false { return } viewBlack.hidden = false presentViewController(cameraController, animated: false, completion: nil) cameraController.sourceType = .Camera cameraController.mediaTypes = [kUTTypeMovie as String] //cameraController.mediaTypes = [kUTTypeMPEG4 as String] cameraController.cameraCaptureMode = .Video cameraController.videoQuality = .TypeMedium if(getPurchaseId() as! Int == 0) { if(txtBenchMark.text?.isEmpty == false) { cameraController.videoMaximumDuration = NSTimeInterval(300.0) }else{ cameraController.videoMaximumDuration = NSTimeInterval(60.0) } }else{ cameraController.videoMaximumDuration = NSTimeInterval(600.0) } cameraController.allowsEditing = false }
I am using Swift 2.2 and Xcode 8 with Use Legacy swift Language version = Yes
Any alternative solutions are also welcome. Thanks in advance.
EDIT: I found out that there is no way to directly record mp4 video in swift. only can be converted to the required format from quicktime mov format in Apple.
ios swift video-capture uiimagepickercontroller
Kautham krishna
source share