Stream square video with Video Core - Swift

274 views Asked by At

I have the following code which sets up a VCSession with the dimensions needed. 'camview' is a square UIView with the correct dimensions.

self.previewView = camview
let screenSize: CGSize = UIScreen.mainScreen().bounds.size
self.session = VCSimpleSession(videoSize: screenSize, frameRate: 30, bitrate: 1000000, useInterfaceOrientation: false)
session!.orientationLocked = false
session!.previewView.frame = camview.bounds
camview.addSubview(session!.previewView)

No matter how I try to set up the frames/bounds, either a) the output retains the screen aspect ratio but is reduced to fit into the square frame (if i set videoSize to camview) or b) as the code above implies, the video records full screen but only the square bit is visible.

I'm going round in circles - can anyone let me know how I can actually get the VCSimpleSession videoSize to correctly output only the square aspect ratio (i.e., only that part of the camera frame that is within the square)?

1

There are 1 answers

0
RobertyBob On

Seems that it needed the parameter for Aspect set. This seemed unlikely since the only options were Fit and Fill, neither of which seemed right. However it seems to have done the trick.

So set videoSize to camview, previewView.frame to same then add the following.

session!.aspectMode = VCAspectMode.AscpectModeFill

(The typo is videoCore not me)