ビデオの制限を指定する

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 objectletcamera=TVICameraCapturer(source:.frontCamera)// Setup the video constraintsletvideoConstraints=TVIVideoConstraints{(constraints)inconstraints.maxSize=TVIVideoConstraintsSize960x540constraints.minSize=TVIVideoConstraintsSize960x540constraints.maxFrameRate=TVIVideoConstraintsFrameRateNoneconstraints.minFrameRate=TVIVideoConstraintsFrameRateNone}// Add local video track with camera and video constraintslocalVideoTrack=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 objectTVICameraCapturer*camera==[[TVICameraCaptureralloc]init];// Setup the video constraintsTVIVideoConstraints*videoConstraints=[TVIVideoConstraintsconstraintsWithBlock:^(TVIVideoConstraintsBuilder*_Nonnullbuilder){builder.maxSize=TVIVideoConstraintsSize960x540;builder.minSize=TVIVideoConstraintsSize960x540;builder.maxFrameRate=TVIVideoConstraintsFrameRateNone;builder.minFrameRate=TVIVideoConstraintsFrameRateNone;}];// Add local video track with camera and video constraintsTVIVideoTrack*localVideoTrack=[TVILocalVideoTracktrackWithCapturer:cameraenabled:YESconstraints: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:

ヘルプが必要ですか？

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.