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 TVIVideoFormat
s 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 object2let camera = TVICameraCapturer(source: .frontCamera)34// Setup the video constraints5let videoConstraints = TVIVideoConstraints { (constraints) in6constraints.maxSize = TVIVideoConstraintsSize960x5407constraints.minSize = TVIVideoConstraintsSize960x5408constraints.maxFrameRate = TVIVideoConstraintsFrameRateNone9constraints.minFrameRate = TVIVideoConstraintsFrameRateNone10}1112// Add local video track with camera and video constraints13localVideoTrack = TVILocalVideoTrack(capturer: capturer,14enabled: true,15constraints: videoConstraints,16name: "Screen")1718// If the constraints are not satisfied, a nil track will be returned.19if (localVideoTrack == nil) {20print ("Error: Failed to create a video track using the local camera.")21}
In Objective-C
1// Create camera object2TVICameraCapturer *camera = = [[TVICameraCapturer alloc] init];34// Setup the video constraints5TVIVideoConstraints *videoConstraints = [TVIVideoConstraints constraintsWithBlock:6^(TVIVideoConstraintsBuilder * _Nonnull builder) {7builder.maxSize = TVIVideoConstraintsSize960x540;8builder.minSize = TVIVideoConstraintsSize960x540;9builder.maxFrameRate = TVIVideoConstraintsFrameRateNone;10builder.minFrameRate = TVIVideoConstraintsFrameRateNone;11}];1213// Add local video track with camera and video constraints14TVIVideoTrack *localVideoTrack = [TVILocalVideoTrack trackWithCapturer:camera15enabled:YES16constraints:videoConstraints17name:@"Camera"];1819// If the constraints are not satisfied, a nil track will be returned.20if (localVideoTrack == nil) {21NSLog(@"Error: Failed to create a video track using the local camera.");22}