Skip to contentSkip to navigationSkip to topbar
Rate this page:

Specify Video Constraints for iOS v2.x


(warning)

Warning

This page is for reference only. We are no longer onboarding new customers to Programmable Video. Existing customers can continue to use the product until December 5, 2024(link takes you to an external page).
We recommend migrating your application to the API provided by our preferred video partner, Zoom. We've prepared this migration guide(link takes you to an external page) to assist you in minimizing any service disruption.

You can customize the properties of the video produced by a TVIVideoCapturer using TVIVideoConstraints. Constraints allow you to choose at runtime between one of the many TVIVideoFormats that are supported by the capturer. The included TVICameraCapturer class exposes formats based upon what your device's cameras are capable of.

Constraints allow you to filter by several criteria including size, frame rate, and aspect ratio. While constraints are used to resolve the actual capture format, the video sent to other Participants may be downscaled (temporally or spatially) in response to network and device conditions.

In Swift


_21
// Create camera object
_21
let camera = TVICameraCapturer(source: .frontCamera)
_21
_21
// Setup the video constraints
_21
let videoConstraints = TVIVideoConstraints { (constraints) in
_21
constraints.maxSize = TVIVideoConstraintsSize960x540
_21
constraints.minSize = TVIVideoConstraintsSize960x540
_21
constraints.maxFrameRate = TVIVideoConstraintsFrameRateNone
_21
constraints.minFrameRate = TVIVideoConstraintsFrameRateNone
_21
}
_21
_21
// Add local video track with camera and video constraints
_21
localVideoTrack = TVILocalVideoTrack(capturer: capturer,
_21
enabled: true,
_21
constraints: videoConstraints,
_21
name: "Screen")
_21
_21
// If the constraints are not satisfied, a nil track will be returned.
_21
if (localVideoTrack == nil) {
_21
print ("Error: Failed to create a video track using the local camera.")
_21
}

In Objective-C


_22
// Create camera object
_22
TVICameraCapturer *camera = = [[TVICameraCapturer alloc] init];
_22
_22
// Setup the video constraints
_22
TVIVideoConstraints *videoConstraints = [TVIVideoConstraints constraintsWithBlock:
_22
^(TVIVideoConstraintsBuilder * _Nonnull builder) {
_22
builder.maxSize = TVIVideoConstraintsSize960x540;
_22
builder.minSize = TVIVideoConstraintsSize960x540;
_22
builder.maxFrameRate = TVIVideoConstraintsFrameRateNone;
_22
builder.minFrameRate = TVIVideoConstraintsFrameRateNone;
_22
}];
_22
_22
// Add local video track with camera and video constraints
_22
TVIVideoTrack *localVideoTrack = [TVILocalVideoTrack trackWithCapturer:camera
_22
enabled:YES
_22
constraints:videoConstraints
_22
name:@"Camera"];
_22
_22
// If the constraints are not satisfied, a nil track will be returned.
_22
if (localVideoTrack == nil) {
_22
NSLog(@"Error: Failed to create a video track using the local camera.");
_22
}


Rate this page: