Skip to main content
Version: 5.x.x

Custom Video Track - Flutter​

  • You can create a Video Track using createCameraVideoTrack() method of VideoSDK class.
  • 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 example 3017 without camera permission, 3021 when there is no camera, 3023 when the camera is in use, 3026 when the camera fails to open, or 3071 for an unknown cameraId.
  • 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 deviceId of a camera from VideoSDK.getCameras().
  • 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.
Encoder ConfigResolutionOptimized (kbps)Balanced (kbps)High Quality (kbps)
h90p_w160p160x904090120
h180p_w320p320x18060120180
h360p_w640p640x360300450600
h540p_w960p960x5406009001200
h720p_w1280p1280x720100015002000
h1080p_w1920p1920x1080150022002700
h120p_w160p160x1204090120
h180p_w240p240x18090120180
h240p_w320p320x240100150200
h360p_w480p480x360270360540
h480p_w640p640x480350600900
h720p_w960p960x72090012001600
h1080p_w1440p1440x1080150020002700

Use only the values in this table. Other CustomCameraTrackConfig values, such as h1440p_w2560p and h2160p_w3840p, are not supported.

important

The actual video resolution may differ from the requested value due to device and hardware limitations.

note

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.
  • multiStream

    • type: bool
    • required: false
    • default: true
    • It will specify if the stream should send multiple resolution layers or single resolution layer.
info
  • 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 encoderConfig table lists the bitrate for each mode.
  • 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 multiStream is true. Smaller resolutions send fewer layers.
    • To send a single layer, set multiStream to false.
  • 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.

Returns​

  • Future<CustomStreamTrack>
  • If the track cannot be created, the method throws a VideoSDKError. It never returns null.

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 of VideoSDK class.
  • 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 example 3018 without microphone permission, 3022 when there is no microphone, 3024 when the microphone is in use, or 3071 for an unknown microphoneId.
  • 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 deviceId of a microphone from VideoSDK.getMics().
  • encoderConfig:

    • type: CustomMicrophoneTrackConfig
    • required: false
    • default: SPEECH_STANDARD
    • You can choose from the below mentioned list of values for the encoder config.
Encoder ConfigBitrateAuto GainEcho CancellationNoise Suppression
SPEECH_LOW_QUALITY24 kbpsTRUETRUETRUE
SPEECH_STANDARD24 kbpsTRUETRUETRUE
MUSIC_STANDARD40 kbpsFALSEFALSEFALSE
STANDARD_STEREO64 kbpsFALSEFALSEFALSE
HIGH_QUALITY128 kbpsFALSEFALSEFALSE
HIGH_QUALITY_STEREO192 kbpsFALSEFALSEFALSE
  • noiseConfig

    • type: NoiseConfig

    • required: false

    • If you pass a NoiseConfig, every flag you leave out is turned on, except highPassFilter, which stays off. Pass no noiseConfig to use the values of the encoderConfig profile.

    • NoiseConfig takes these optional flags:

    • echoCancellation

      • type: bool
      • required: false
      • If true echo cancellation will be turned on else it would be turned off.
    • autoGainControl

      • type: bool
      • required: false
      • If true auto gain will be turned on else it would be turned off.
    • noiseSuppression

      • type: bool
      • required: false
      • If true noise suppression will be turned on else it would be turned off.
    • highPassFilter

      • type: bool
      • required: false
      • If true the high-pass filter, which cuts low-frequency noise, will be turned on else it would be turned off.

Returns​

  • Future<CustomStreamTrack>
  • If the track cannot be created, the method throws a VideoSDKError. It never returns null.

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 of VideoSDK class, and pass it to room.enableScreenShare(customTrack:).
  • Without a track, room.enableScreenShare() shares at CustomScreenShareTrackConfig.h720p_15fps. To use any other profile, create a track.
  • On Android, this method asks the user for screen-capture consent, and returns null if the user declines. On iOS, the system broadcast picker opens when you call room.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.
Encoder ConfigResolutionFrame RateBitrate (kbps)
h360p_30fps640x36030 fps400
h480p_15fps854x48015 fps300
h480p_30fps854x48030 fps500
h720p_5fps1280x7205 fps400
h720p_15fps1280x72015 fps1000
h720p_30fps1280x72030 fps1500
h1080p_15fps1920x108015 fps1500
h1080p_30fps1920x108030 fps2000
note

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.
  • 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.

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. error is a VideoSDKError when the device was lost, another app took it or the system revoked access, and null when the track ended without an error, such as after stop().
  • Set after the track has ended, it is called at once.

isEnded​

  • type: bool (read-only)
  • true once stop() 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 has shareEncoderConfig.

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