createCameraVideoTrack

fun createCameraVideoTrack(encoderConfig: String, facingMode: String, optimizationMode: CustomStreamTrack.VideoMode, multiStream: Boolean, context: Context, videoDeviceInfo: VideoDeviceInfo, maxLayer: Integer, bitrateMode: BitrateMode, videoCodec: VideoCodec): CustomStreamTrack

Creates a custom camera video track with full control over simulcast layers, bitrate mode, and the preferred video codec.

Use this to create a video track before joining a meeting or to replace the active video track during a meeting using enableWebcam. This is the most configurable overload, allowing you to specify the maximum number of simulcast layers, the bitrate mode, and a preferred VideoCodec for the producer.

If the requested codec cannot be produced (not supported by the device, the hardware encoder fails at runtime, or the server rejects it), the SDK falls back to VP8 and emits onError(3008) (ERROR_VIDEO_PRODUCE_CODEC_NOT_SUPPORTED). If a remote participant cannot decode the codec, the SDK also falls back to VP8 and instead fires onCodecChanged.

Note: Multistream (simulcast) is only supported on VP8. If you request AV1, VP9, or H264 with multiStream=true, the SDK silently downgrades to single-layer encoding and emits onError(3009) (ERROR_MULTISTREAM_NOT_SUPPORTED).

For more details, see Custom Video Track - Android.

Return

A CustomStreamTrack for the camera, or null if creation fails (e.g., camera permission denied).

Code Example:


val videoTrack = VideoSDK.createCameraVideoTrack(
    "h720p_w1280p",                         // 720p resolution
    "front",                                 // front camera
    CustomStreamTrack.VideoMode.MOTION,      // optimize for motion
    false,                                   // simulcast off (required for non-VP8 codecs)
    context,
    null,                                    // use default camera
    1,                                       // single layer
    BitrateMode.BALANCED,
    VideoCodec.H264                          // request H264
)

// Use the track when enabling webcam
meeting.enableWebcam(videoTrack)

Parameters

encoderConfig

Video resolution preset (e.g., "h480p_w720p", "h720p_w1280p"). If null or empty, defaults to "h480p_w720p". Available presets: "h144p_w176p", "h240p_w320p", "h360p_w640p", "h480p_w640p", "h480p_w720p", "h720p_w960p", "h720p_w1280p", "h1080p_w1440p".

facingMode

Camera facing mode: "front" or "back".

optimizationMode

Video optimization mode. MOTION prioritizes frame rate (ideal for video calls), while TEXT prioritizes resolution (ideal for screen content). See CustomStreamTrack.VideoMode.

multiStream

If true, enables simulcast encoding (VP8 only — see Note above). Required for adaptive subscription and per-participant quality control via setViewPort or setQuality.

context

Application context.

videoDeviceInfo

(Optional) Specific camera device. Use getVideoDevices to enumerate available cameras. If null, the default camera for the specified facingMode is used.

maxLayer

(Optional) Maximum number of simulcast layers (e.g., 2, or 3). More layers provide finer quality adaptation at the cost of higher encoding overhead. Only effective when multiStream is true. If null, the SDK default is used.

bitrateMode

(Optional) The bitrate mode for encoding. HIGH_QUALITY provides better quality at the expense of higher bandwidth, BALANCED is suitable for most conditions, and BANDWIDTH_OPTIMIZED conserves bandwidth. If null, the SDK default is used. See BitrateMode.

videoCodec

(Optional) Preferred video codec. If null, the SDK defaults to VP8. If the requested codec is unavailable on the device, the SDK falls back to VP8. See VideoCodec.

See also