Skip to contentSkip to navigationSkip to topbar

Specify Video Constraints for iOS v2.x


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
name: "Screen")
17
18
// If the constraints are not satisfied, a nil track will be returned.
19
if (localVideoTrack == nil) {
20
print ("Error: Failed to create a video track using the local camera.")
21
}

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
name:@"Camera"];
18
19
// If the constraints are not satisfied, a nil track will be returned.
20
if (localVideoTrack == nil) {
21
NSLog(@"Error: Failed to create a video track using the local camera.");
22
}

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.