Skip to main content
Version: 3.x.x

Optimize Video Track - iOS

While optimizing for the best viewing experience, it is necessary to fine-tune the video tracks that are being used during the calls.

For the best fine-tuning experience, we have introduced the ability to pass a custom video track for the participant's media before and during the meeting.

Custom Video Track​

This feature gives you powerful tools to deliver the best possible video stream for varying network conditions. You can specify a modern video quality profile (bitrateMode) and control simulcast behavior (maxLayer).

From version 3.1.0 onward, once you set a custom video track created using createCameraVideoTrack(), VideoSDK remembers its settings and automatically reuses them whenever the webcam is turned back on. To change the track configuration, call disableWebcam(), then pass a new track created using createCameraVideoTrack() to enableWebcam(customVideoStream:). VideoSDK preserves only tracks created using createCameraVideoTrack(). Filters applied through external SDKs or packages for virtual background are not preserved and must be re-applied each time the webcam is re-enabled.

How to Create a Custom Video Track ?​

  • You can create a Video Track using createCameraVideoTrack() method of VideoSDK class.

  • This method can be used to create video track by specifying parameters like video resolution, camera facing mode, and the quality controls (bitrateMode and maxLayer).

  • You can choose video resolution from the below mentioned list of values for the encoder config:

ConfigResolutionFrame RateOptimized (kbps)Balanced (kbps)High Quality (kbps)
h90p_w160p160x9030 fps4090120
h180p_w320p320x18030 fps60120180
h360p_w640p640x36030 fps300450600
h540p_w960p960x54030 fps6009001200
h720p_w1280p1280x72030 fps100015002000
h1080p_w1920p1920x108030 fps150022002700
h120p_w160p160x12030 fps4090120
h180p_w240p240x18030 fps90120180
h240p_w320p320x24030 fps100150200
h360p_w480p480x36030 fps270360540
h480p_w640p640x48030 fps350600900
h720p_w960p960x72030 fps90012001600
h1080p_w1440p1440x108030 fps150020002700
note

Above mentioned encoder configurations are valid for both, landscape as well as portrait mode.

Example​

import WebRTC
guard let videoMediaTrack = try? VideoSDK.createCameraVideoTrack(
// This will accept the enum value of CustomVideoTrackConfig which contains resolution (height x width) of video you want to capture.
encoderConfig: .h720p_w960p, // .h360p_w640p | .h480p_w640p ... // Default : .h720p_w1280p

// It will specify whether to use front or back camera for the video track.
facingMode: .front, // .back, Default : .front

// We will discuss this parameter in next step.
multiStream: true, // false, Default : true

// Optional: This specifies the video codec used to encode this track.
codec: .VP8, // .H264 | .VP9 | .AV1 , Default : .VP8

// Optional: This controls the video quality and bandwidth usage.
bitrateMode: BitrateMode.HIGH_QUALITY, // .BANDWIDTH_OPTIMIZED | .BALANCED Default: .BALANCED

// Optional: This specifies the maximum number of simulcast layers (maxLayer) to publish.
maxLayer: EncodingLayer.MAX_LAYER_2 // 2 | Default: .MAX_LAYER_3

) else { return}
caution

The capabilities of the device have a significant impact on how custom track configurations behave. Assuming a case where you set encoder configuration to 1080p but the webcam only supports 720p, then encoder configuration will automatically switch to the highest resolution that the device can handle, which is 720p.

What is multiStream?​
  • This parameter specifies whether the stream should send multiple resolution layers or a single resolution layer. It is true by default.

Refer to the Simulcast (Adaptive Bitrate) guide for the layers a track publishes and for how participants select the layer they receive.

What is BitrateMode?​

BitrateMode is the key setting for video quality. It lets you decide whether to prioritize sharp details, save internet data, or find a good balance between the two.

You can choose from three distinct modes:

  • .BANDWIDTH_OPTIMIZED: Prioritizes lower bandwidth usage over video quality. Ideal for users with poor or unstable network conditions.
  • .BALANCED: The default setting. It provides a smart compromise between clear video and efficient bandwidth consumption, suitable for most use cases.
  • .HIGH_QUALITY: Prioritizes video quality over bandwidth usage. Use this when high-fidelity video is essential and viewers are expected to have strong network connections.
What is MaxLayer?​
  • This parameter caps how many layers a track publishes, and accepts EncodingLayer.MAX_LAYER_2 or EncodingLayer.MAX_LAYER_3. It applies only when multiStream is true, and defaults to .MAX_LAYER_3.

Refer to the Simulcast (Adaptive Bitrate) guide for what each value publishes.

What is codec?​
  • This parameter specifies the video codec used to encode your stream. VideoSDK supports VP8 (default), H264, VP9, and AV1, set through VideoCodec.
  • Currently, VideoSDK doesn't support multiStream for H264, VP9, and AV1. multiStream defaults to true, so set multiStream: false when you create an H264, VP9, or AV1 track. Otherwise VideoSDK sets it to false for you and emits the ERROR_MULTISTREAM_NOT_SUPPORTED error.

Refer to the Video Codecs guide to compare the four codecs, to check which codec a meeting is actually using, and to handle the cases where a codec is not supported.

How to Setup a Custom Video Track ?​

The custom track can be set up both before and after the initialization of the meeting.

  1. Setting up a Custom Track during the initialization of a meeting
  2. Setting up a Custom Track with methods
1. Setting up a Custom Track during the initialization of a meeting​

If you are passing webcamEnabled: true in the createRoom and want to use custom tracks from start of the meeting, you can pass custom track in the customCameraVideoTrack as shown below.

caution
  • Custom Track will not apply on webcamEnabled: false configuration.

  • Custom video track's facingMode takes precedence over the cameraPosition specified during the join method. Ensure you set facingMode appropriately to achieve the desired camera orientation.

Example​
import VideoSDKRTC

guard let videoMediaTrack = try? VideoSDK.createCameraVideoTrack(
encoderConfig: .h720p_w960p,
facingMode: .front,
multiStream: true,
codec: .VP8, // .H264 | .VP9 | .AV1 , Default : .VP8
bitrateMode: .HIGH_QUALITY, // Default: .BALANCED
maxLayer: .MAX_LAYER_2 // Default: .MAX_LAYER_3
) else {
return
}

let meeting = VideoSDK.initMeeting(
meetingId: meetingId,
participantName: name,
micEnabled: micEnabled, // optional, default: true
webcamEnabled: cameraEnabled, // optional, default: true
// Pass the custom track here which will be used to when webcam is auto started
customCameraVideoStream: videoMediaTrack
)

2. Setting up a Custom Track with methods​

In order to switch tracks during the meeting, you have to pass the CustomTrack in the enableWebCam() method of Room.

tip

Make sure to call disableWebcam() before you create a new track as it may lead to unexpected behavior.

Example​
import VideoSDKRTC

@IBAction func videoButtonTapped(_ sender: Any) {
if !on {
guard let videoMediaTrack = try? VideoSDK.createCameraVideoTrack(
encoderConfig: .h720p_w960p,
facingMode: .front,
multiStream: true,
codec: .VP8, // .H264 | .VP9 | .AV1 , Default : .VP8
bitrateMode: .HIGH_QUALITY, // Default: .BALANCED
maxLayer: .MAX_LAYER_2 // Default: .MAX_LAYER_3
) else {
return
}
self.meeting?.enableWebcam(customVideoStream: videoMediaTrack)
} else {
self.meeting?.disableWebcam()
}
}

Which Configuration is suitable for Device ?​

In this section, we will understand participant size wise encoder(Resolution) and multiStream configuration.

API Reference​

The API references for all the methods and events utilised in this guide are provided below.

Got a Question? Ask us on discord