skip to Main Content

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:

enter image description here
Console output

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


  1. 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.

    Login or Signup to reply.
  2. I just did the following for testing and got all available video dimensions printed:

    let descriptions = device.formats.map(.formatDescription)
    let sizes = descriptions.map(.dimensions)
    print(sizes)
    

    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?

    Login or Signup to reply.
  3. You just need below line.That’s it.

       let dimensions = CMVideoFormatDescriptionGetDimensions(format.formatDescription)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search