I’m trying to display the dimensions in which photos/video recordings can be taken to the user.
While photo dimensions are easily accessible through AVCaptureDevice.Format.highResolutionStillImageDimensions
, I have no idea how I can achieve the same for videos.
I’ve tried the AVCaptureDevice.Format.formatDescription.dimensions
property (or the .presentationDimensions(..)
func), but those just gave me the following compile errors:
Since those are available since iOS 13.0 (I believe that was Swift 5.1?), I should definitely have the API for those (especially since I can CMD + Click on them in my code), and my project should compile. Am I missing something here? Is there a better solution to get the resolution a capture device can record videos in?
3
Answers
There is no direct API to get the video resolution.
You can set the AVCaptureSession.sessionPreset to one of the AVCaptureSession.Preset, then use canSetSessionPreset(_:) to check if the preset is supported by the current device.
I just did the following for testing and got all available video dimensions printed:
I also checked if it compiled for iOS, Simulator, and macOS, and it does.
Are you still supporting iOS 12? Did you check your SDK setting?
You just need below line.That’s it.