Swift: video records at one size but renders at wrong size

Solution 1:

If I get you right, it seems that you have misunderstood the fact that device screen width is'n equal to camera preview (and capture) size.

The videoGravity property of your previewLayer indicates how to stretch/fit your preview inside your layer. It doesn't affect capture output.

Actual frame size of output depends on sessionPreset property of your current AVCaptureSession. And as I can understand by reading GitHub repository of PBJVision lib, its singleton has setter for this (called captureSessionPreset). You can change it inside your initPBJVision method.

There you can find possible values of session presets.

Solution 2:

Try SDAVAssetExportSession

You can specify the AVVideoWidthKey and AVVideoHeightKey You can also specify the profile, AVVideoProfileLevelKey ie AVVideoProfileLevelH264HighAutoLevel for supporting something 4k, a friend (Michael Lowin) tracked that property down to help us improve some export qualities.