Menu

Expand
Rate this page:

Specifying Video Constraints

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

// Create camera object
let camera = TVICameraCapturer(source: .frontCamera)

// Setup the video constraints
let videoConstraints = TVIVideoConstraints { (constraints) in
    constraints.maxSize = TVIVideoConstraintsSize960x540
    constraints.minSize = TVIVideoConstraintsSize960x540
    constraints.maxFrameRate = TVIVideoConstraintsFrameRateNone
    constraints.minFrameRate = TVIVideoConstraintsFrameRateNone
}

// Add local video track with camera and video constraints
localVideoTrack = TVILocalVideoTrack(capturer: capturer,
                                     enabled: true,
                                     constraints: videoConstraints)

// If the constraints are not satisfied, a nil track will be returned.
if (localVideoTrack == nil) {
    print ("Error: Failed to create a video track using the local camera.")
}

In Objective-C

// Create camera object
TVICameraCapturer *camera = = [[TVICameraCapturer alloc] init];

// Setup the video constraints
TVIVideoConstraints *videoConstraints = [TVIVideoConstraints constraintsWithBlock:
                              ^(TVIVideoConstraintsBuilder * _Nonnull builder) {
    builder.maxSize = TVIVideoConstraintsSize960x540;
    builder.minSize = TVIVideoConstraintsSize960x540;
    builder.maxFrameRate = TVIVideoConstraintsFrameRateNone;
    builder.minFrameRate = TVIVideoConstraintsFrameRateNone;
}];

// Add local video track with camera and video constraints
TVIVideoTrack *localVideoTrack = [TVILocalVideoTrack trackWithCapturer:camera
                                                               enabled:YES
                                                           constraints:videoConstraints];

// If the constraints are not satisfied, a nil track will be returned.
if (localVideoTrack == nil) {
    NSLog(@"Error: Failed to create a video track using the local camera.");
}
Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.

        
        
        

        Thank you for your feedback!

        Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

        Sending your feedback...
        🎉 Thank you for your feedback!
        Something went wrong. Please try again.

        Thanks for your feedback!

        Refer us and get $10 in 3 simple steps!

        Step 1

        Get link

        Get a free personal referral link here

        Step 2

        Give $10

        Your user signs up and upgrade using link

        Step 3

        Get $10

        1,250 free SMSes
        OR 1,000 free voice mins
        OR 12,000 chats
        OR more