Custom Video Track - Flutter
- You can create a Video Track using
createCameraVideoTrack()method ofVideoSDKclass. - This method can be used to create video track using different encoding parameters, camera facing mode, bitrate mode and codec.
- This method does not ask for camera permission. Call
VideoSDK.requestPermissions()before you create the track. - If the track cannot be created, the method throws a
VideoSDKError, for example3017without camera permission,3021when there is no camera,3023when the camera is in use,3026when the camera fails to open, or3071for an unknowncameraId. - The camera opens when the track is created. If you do not use the track, call
stop()on it to close the camera.
Parameters
-
cameraId:
- type:
String - required:
false - It will be the id of the camera from which the video should be captured. Use the
deviceIdof a camera fromVideoSDK.getCameras().
- type:
-
encoderConfig:
- type:
CustomCameraTrackConfig - required:
false - default:
h720p_w1280p - You can choose from the below mentioned list of values for the encoder config. The bitrate columns show the maximum bitrate of the full-resolution video for each
bitrateMode.
- type:
| Encoder Config | Resolution | Optimized (kbps) | Balanced (kbps) | High Quality (kbps) |
|---|---|---|---|---|
| h90p_w160p | 160x90 | 40 | 90 | 120 |
| h180p_w320p | 320x180 | 60 | 120 | 180 |
| h360p_w640p | 640x360 | 300 | 450 | 600 |
| h540p_w960p | 960x540 | 600 | 900 | 1200 |
| h720p_w1280p | 1280x720 | 1000 | 1500 | 2000 |
| h1080p_w1920p | 1920x1080 | 1500 | 2200 | 2700 |
| h120p_w160p | 160x120 | 40 | 90 | 120 |
| h180p_w240p | 240x180 | 90 | 120 | 180 |
| h240p_w320p | 320x240 | 100 | 150 | 200 |
| h360p_w480p | 480x360 | 270 | 360 | 540 |
| h480p_w640p | 640x480 | 350 | 600 | 900 |
| h720p_w960p | 960x720 | 900 | 1200 | 1600 |
| h1080p_w1440p | 1440x1080 | 1500 | 2000 | 2700 |
Use only the values in this table. Other CustomCameraTrackConfig values, such as h1440p_w2560p and h2160p_w3840p, are not supported.
The actual video resolution may differ from the requested value due to device and hardware limitations.
Above mentioned encoder configurations are valid for both, landscape as well as portrait mode.
-
facingMode:
- type:
FacingMode - required:
false - default:
FacingMode.FRONT - Allowed values :
FacingMode.FRONT|FacingMode.BACK - It will specify whether to use front or back camera for the video track.
- type:
-
multiStream
- type:
bool - required:
false - default:
true - It will specify if the stream should send multiple resolution layers or single resolution layer.
- type:
- To learn more about optimizations and best practices for using custom video tracks, follow this guide.
- This parameter is only available from
v1.0.9.
-
bitrateMode
- type:
BitrateMode - required:
false - default:
BitrateMode.BALANCED - Allowed values :
BitrateMode.BANDWIDTH_OPTIMIZED|BitrateMode.BALANCED|BitrateMode.HIGH_QUALITY - It will specify how the encoder trades video quality against bandwidth. The
encoderConfigtable lists the bitrate for each mode.
- type:
-
maxLayer
- type:
EncodingLayer - required:
false - default:
EncodingLayer.MAX_LAYER_3 - Allowed values :
EncodingLayer.MAX_LAYER_2|EncodingLayer.MAX_LAYER_3 - It will specify the highest number of resolution layers the stream sends when
multiStreamistrue. Smaller resolutions send fewer layers. - To send a single layer, set
multiStreamtofalse.
- type:
-
codec
- type:
VideoCodec - required:
false - default:
VideoCodec.VP8 - Allowed values :
VideoCodec.VP8|VideoCodec.H264|VideoCodec.VP9|VideoCodec.AV1 - It will specify the codec used to encode the video. To pick one, refer to the Video Codecs guide.
- type:
Returns
Future<CustomStreamTrack>- If the track cannot be created, the method throws a
VideoSDKError. It never returnsnull.
Example
final permissions = await VideoSDK.requestPermissions(Permissions.VIDEO);
if (permissions['video'] != true) return;
try {
CustomStreamTrack videoTrack = await VideoSDK.createCameraVideoTrack(
encoderConfig: CustomCameraTrackConfig.h720p_w960p,
multiStream: true,
facingMode: FacingMode.FRONT,
bitrateMode: BitrateMode.HIGH_QUALITY,
maxLayer: EncodingLayer.MAX_LAYER_2,
);
} on VideoSDKError catch (error) {
log("Could not create the track: ${error.code} ${error.name}");
}
Custom Audio Track - Flutter
- You can create a Audio Track using
createMicrophoneAudioTrack()method ofVideoSDKclass. - This method can be used to create audio track using different encoding parameters and noise cancellation configuration.
- This method does not ask for microphone permission. Call
VideoSDK.requestPermissions()before you create the track. - If the track cannot be created, the method throws a
VideoSDKError, for example3018without microphone permission,3022when there is no microphone,3024when the microphone is in use, or3071for an unknownmicrophoneId. - The microphone opens when the track is created. If you do not use the track, call
stop()on it to close the microphone.
Parameters
-
microphoneId:
- type:
String - required:
false - It will be the id of the mic from which the audio should be captured. Use the
deviceIdof a microphone fromVideoSDK.getMics().
- type:
-
encoderConfig:
- type:
CustomMicrophoneTrackConfig - required:
false - default:
SPEECH_STANDARD - You can choose from the below mentioned list of values for the encoder config.
- type:
| Encoder Config | Bitrate | Auto Gain | Echo Cancellation | Noise Suppression |
|---|---|---|---|---|
| SPEECH_LOW_QUALITY | 24 kbps | TRUE | TRUE | TRUE |
| SPEECH_STANDARD | 24 kbps | TRUE | TRUE | TRUE |
| MUSIC_STANDARD | 40 kbps | FALSE | FALSE | FALSE |
| STANDARD_STEREO | 64 kbps | FALSE | FALSE | FALSE |
| HIGH_QUALITY | 128 kbps | FALSE | FALSE | FALSE |
| HIGH_QUALITY_STEREO | 192 kbps | FALSE | FALSE | FALSE |
-
noiseConfig
-
type:
NoiseConfig -
required:
false -
If you pass a
NoiseConfig, every flag you leave out is turned on, excepthighPassFilter, which stays off. Pass nonoiseConfigto use the values of theencoderConfigprofile. -
NoiseConfigtakes these optional flags: -
echoCancellation
- type:
bool - required:
false - If
trueecho cancellation will be turned on else it would be turned off.
- type:
-
autoGainControl
- type:
bool - required:
false - If
trueauto gain will be turned on else it would be turned off.
- type:
-
noiseSuppression
- type:
bool - required:
false - If
truenoise suppression will be turned on else it would be turned off.
- type:
-
highPassFilter
- type:
bool - required:
false - If
truethe high-pass filter, which cuts low-frequency noise, will be turned on else it would be turned off.
- type:
-
Returns
Future<CustomStreamTrack>- If the track cannot be created, the method throws a
VideoSDKError. It never returnsnull.
Example
final permissions = await VideoSDK.requestPermissions(Permissions.AUDIO);
if (permissions['audio'] != true) return;
try {
CustomStreamTrack audioTrack = await VideoSDK.createMicrophoneAudioTrack(
encoderConfig: CustomMicrophoneTrackConfig.SPEECH_STANDARD,
noiseConfig: const NoiseConfig(noiseSuppression: true, echoCancellation: true),
);
} on VideoSDKError catch (error) {
log("Could not create the track: ${error.code} ${error.name}");
}
Custom Screen Share Track - Flutter
- You can create a Screen Share Track using
createScreenShareVideoTrack()method ofVideoSDKclass, and pass it toroom.enableScreenShare(customTrack:). - Without a track,
room.enableScreenShare()shares atCustomScreenShareTrackConfig.h720p_15fps. To use any other profile, create a track. - On Android, this method asks the user for screen-capture consent, and returns
nullif the user declines. On iOS, the system broadcast picker opens when you callroom.enableScreenShare(). - On iOS, screen share also needs a Broadcast Upload Extension. Refer to Flutter iOS Screen Share for the setup.
Parameters
-
encoderConfig:
- type:
CustomScreenShareTrackConfig - required:
false - default:
h720p_15fps - You can choose from the below mentioned list of values for the encoder config.
- type:
| Encoder Config | Resolution | Frame Rate | Bitrate (kbps) |
|---|---|---|---|
| h360p_30fps | 640x360 | 30 fps | 400 |
| h480p_15fps | 854x480 | 15 fps | 300 |
| h480p_30fps | 854x480 | 30 fps | 500 |
| h720p_5fps | 1280x720 | 5 fps | 400 |
| h720p_15fps | 1280x720 | 15 fps | 1000 |
| h720p_30fps | 1280x720 | 30 fps | 1500 |
| h1080p_15fps | 1920x1080 | 15 fps | 1500 |
| h1080p_30fps | 1920x1080 | 30 fps | 2000 |
On iOS, the system chooses the capture resolution.
-
multiStream
- type:
bool - required:
false - default:
false - It will specify if the screen share should send multiple resolution layers or single resolution layer.
- type:
-
withAudio
- type:
bool - required:
false - default:
false - If
true, the audio playing on the device is captured too and mixed into your microphone track, so muting the microphone mutes both. This works on Android 10 (API level 29) and later only. iOS does not support it.
- type:
Returns
Future<CustomStreamTrack?>
Example
final CustomStreamTrack? shareTrack = await VideoSDK.createScreenShareVideoTrack(
encoderConfig: CustomScreenShareTrackConfig.h720p_15fps,
withAudio: true, // Android only
);
// On Android, null means the user declined the capture prompt.
if (shareTrack != null) {
await room.enableScreenShare(customTrack: shareTrack);
}
CustomStreamTrack - Flutter
The camera and microphone methods above return a CustomStreamTrack. The screen share method returns a CustomStreamTrack, or null if the user declines.
stop()
- It releases the track and the camera, microphone or screen capture behind it.
- Call it on a track that no room has taken, for example when the user leaves the pre-call screen without joining.
Returns
Future<void>
onEnded
- type:
void Function(VideoSDKError? error)? - It is called once when the track ends.
erroris aVideoSDKErrorwhen the device was lost, another app took it or the system revoked access, andnullwhen the track ended without an error, such as afterstop(). - Set after the track has ended, it is called at once.
isEnded
- type:
bool(read-only) trueoncestop()has run or the track has ended. You cannot join with an ended track.
encoderConfig
- type:
CustomCameraTrackConfig - The profile a camera track was created with. A microphone track has
audioEncoderConfig, and a screen-share track hasshareEncoderConfig.
Example
final CustomStreamTrack track = await VideoSDK.createCameraVideoTrack();
track.onEnded = (VideoSDKError? error) {
log("Camera track ended: ${error?.code}");
};
// Later, if the user does not join:
await track.stop();
Got a Question? Ask us on discord

