Skip to contentSkip to navigationSkip to topbar

Specify Video Constraints for iOS v1.x


Deprecation Notice - all 1.x Versions
Please note that all Programmable Video iOS SDK 1.x versions are deprecated. Version 3.x is the latest version of the Programmable Video iOS SDK. Please see the Getting Started Guide for more information.

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

1
// Create camera object
2
let camera = TVICameraCapturer(source: .frontCamera)
3
4
// Setup the video constraints
5
let videoConstraints = TVIVideoConstraints { (constraints) in
6
constraints.maxSize = TVIVideoConstraintsSize960x540
7
constraints.minSize = TVIVideoConstraintsSize960x540
8
constraints.maxFrameRate = TVIVideoConstraintsFrameRateNone
9
constraints.minFrameRate = TVIVideoConstraintsFrameRateNone
10
}
11
12
// Add local video track with camera and video constraints
13
localVideoTrack = TVILocalVideoTrack(capturer: capturer,
14
enabled: true,
15
constraints: videoConstraints)
16
17
// If the constraints are not satisfied, a nil track will be returned.
18
if (localVideoTrack == nil) {
19
print ("Error: Failed to create a video track using the local camera.")
20
}

In Objective-C

1
// Create camera object
2
TVICameraCapturer *camera = = [[TVICameraCapturer alloc] init];
3
4
// Setup the video constraints
5
TVIVideoConstraints *videoConstraints = [TVIVideoConstraints constraintsWithBlock:
6
^(TVIVideoConstraintsBuilder * _Nonnull builder) {
7
builder.maxSize = TVIVideoConstraintsSize960x540;
8
builder.minSize = TVIVideoConstraintsSize960x540;
9
builder.maxFrameRate = TVIVideoConstraintsFrameRateNone;
10
builder.minFrameRate = TVIVideoConstraintsFrameRateNone;
11
}];
12
13
// Add local video track with camera and video constraints
14
TVIVideoTrack *localVideoTrack = [TVILocalVideoTrack trackWithCapturer:camera
15
enabled:YES
16
constraints:videoConstraints];
17
18
// If the constraints are not satisfied, a nil track will be returned.
19
if (localVideoTrack == nil) {
20
NSLog(@"Error: Failed to create a video track using the local camera.");
21
}

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.