Skip to main content
Version: 0.x.x

Custom Video Sources - Android

To deliver high-quality livestreams, it's essential to fine-tune the video tracks being broadcasted. Whether youโ€™re hosting a webinar, or streaming an event, using custom video tracks gives you better control over stream quality and performance.

Custom Video Trackโ€‹

This feature can be used to add custom video encoder configurations, optimization mode (whether you want to focus on motion, text or detail of the video) and background removal & video filter from external SDK(e.g., Banuba)and send it to other participants.

How to Create a Custom Video Track ?โ€‹

  • You can create a Video Track using createCameraVideoTrack() method of VideoSDK.
  • This method can be used to create video track using different encoding parameters, camera facing mode, and optimization mode and return CustomStreamTrack.

Exampleโ€‹

val videoCustomTrack: CustomStreamTrack = VideoSDK.createCameraVideoTrack(

// This will accept the resolution (height x width) of video you want to capture.
"h720p_w960p", // "h720p_w960p" | "h720p_w1280p" ... // Default : "h480p_w720p"

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

// We will discuss this parameter in next step.
CustomStreamTrack.VideoMode.MOTION, // CustomStreamTrack.VideoMode.TEXT, CustomStreamTrack.VideoMode.DETAIL , Default : CustomStreamTrack.VideoMode.MOTION

// multiStream - we will discuss this parameter in next step.
false, // true

// Pass Context
this,

// This is Optional parameter. We will discuss this parameter in next step.
observer)
caution

The behavior of custom track configurations is influenced by the capabilities of the device. For example, if you set the encoder configuration to 1080p but the webcam only supports 720p, the encoder configuration will automatically adjust to the highest resolution that the device can handle, which in this case is 720p.

What is optimizationMode?โ€‹
  • This parameter specifies the optimization mode for the video track being generated.
  • motion : This type of track focuses more on motion video such as webcam video, movies or video games.
    • It will degrade resolution in order to maintain frame rate.
  • text : This type of track focuses on significant sharp edges and areas of consistent color that can change frequently such as presentations or web pages with text content.
    • It will degrade frame rate in order to maintain resolution.
  • detail : This type of track focuses more on the details of the video such as, presentations, painting or line art.
    • It will degrade frame rate in order to maintain resolution.
What is multiStream?โ€‹
  • By enabling multiStream, your livestream will broadcast multiple resolutions (e.g., 720p, 480p, 360p), allowing viewers to receive the best stream quality based on their network. The multiStream : true configuration indicates that VideoSDK, by default, sends multiple resolution video streams to the server. For example, if a user's device capability is 720p, VideoSDK sends streams in 720p, 640p, and 480p resolution. This enables VideoSDK to deliver the appropriate stream to each participant based on their network bandwidth.

Multi Stream False

Setting multiStream : false restricts VideoSDK to send only one stream, helping to maintain quality by focusing on a single resolution.

Multi Stream False

danger

The setQuality parameter will not have any effect if multiStream is set to false.

How to Setup a Custom Video Track ?โ€‹

You can plug in your custom video track either before going live or dynamically while the session is ongoing.

  1. Setup during live stream initialization
  2. Setup dynamically using methods
1. Setting up a Custom Track during the initialization of a liveStreamโ€‹

If you're starting the stream with the webcam enabled (webcamEnabled: true) and wish to use a custom track from the beginning, pass it through the config of initMeeting as shown below.

caution

Custom Track will not apply on the webcamEnabled: false configuration.

Exampleโ€‹
override fun onCreate(savedInstanceState: Bundle?) {
//..

val customTracks: MutableMap<String, CustomStreamTrack> = HashMap()
val videoCustomTrack: CustomStreamTrack =
VideoSDK.createCameraVideoTrack("h720p_w960p", "front", CustomStreamTrack.VideoMode.MOTION, false, this)
customTracks["video"] = videoCustomTrack //Key must be "video"

// create a new meeting instance
val liveStream = VideoSDK.initMeeting(
this@MainActivity, meetingId, participantName,
//MicEnabled
true,
//WebcamEnabled , If true, it will use the passed custom track to turn webcam on
true,
// ParticipantId
null,
// Mode
null,
// MultiStream
false,
//Pass the custom tracks here
customTracks,
//MetaData
null
)
}

2. Setting up a Custom Track with methodsโ€‹

In order to switch tracks during the meeting, you have to pass the CustomStreamTrack in the enableWebcam() method of Meeting.

tip

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

Exampleโ€‹
val customStreamTrack: CustomStreamTrack = VideoSDK.createCameraVideoTrack("h720p_w960p", "back", CustomStreamTrack.VideoMode.MOTION, false, this)
liveStream!!.enableWebcam(customStreamTrack)

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