Menu

Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

Specifying Video Constraints

You can customize the video capture by setting video constraints on a local video track. Setting constraints, lets you optimize the video track to network and device conditions. You can set size constraints, frame rate constraints or the aspect ratio constraints of your choice. Note that video constraints are used to resolve the capture format, but the actual video sent to Participant may be downscaled temporally or spatially in response to network and device conditions.

// Create camera capturer
CameraCapturer cameraCapturer = new CameraCapturer(context, 
    CameraCapturer.CameraSource.FRONT_CAMERA);

// Setup video constraints
VideoConstraints videoConstraints = new VideoConstraints.Builder()
    .aspectRatio(VideoConstraints.ASPECT_RATIO_16_9)
    .minVideoDimensions(VideoDimensions.CIF_VIDEO_DIMENSIONS)
    .maxVideoDimensions(VideoDimensions.HD_720P_VIDEO_DIMENSIONS)
    .minFps(5)
    .maxFps(24)
    .build();

// Add a video track with constraints
LocalVideoTrack localVideoTrack = LocalVideoTrack.create(context, true, cameraCapturer, videoConstraints);

// If the constraints are not satisfied a null track will be returned
if (localVideoTrack == null) {
    Log.e(TAG, "Unable to satisfy constraints);
}

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 browsing the Twilio tag on Stack Overflow.

Loading Code Sample...