Should selected videos be compressed in iOS (Swift)?
Hey there,
my app allows users to pick media from their library. With videos, as they can be quite heavy in size, compression seems to become interesting.
However, while picking, it is shown that the video is already being compressed:
At the bottom of the image you're able to see the blue progress bar saying "Compressing Video"
I'm making use of Apple's default UIImagePicker and therefore get a URL once the user has finished picking.
This is the code I'm using to handle picks:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
guard info[UIImagePickerController.InfoKey.mediaType] != nil else { return }
let mediaType = info[UIImagePickerController.InfoKey.mediaType] as! CFString
switch mediaType {
case kUTTypeImage:
// code removed for brevity
case kUTTypeMovie:
print("Movie!") // it's a movie!
if let mediaUrl = info[UIImagePickerController.InfoKey.mediaURL] as? NSURL{
print("Picked video with ending:", mediaUrl.path?.suffix(4)) // print out the video suffix
}
break
default:
print("Unknown media!")
}
viewController.dismiss(animated: true, completion: nil) // dismiss the picker
}
Until now, I've always compressed the file further, but I'm not sure if this makes any sense at all as iOS seems to already compress the file.
Any thoughts on this topic? Any help would be greatly appreciated!