VideoEncoderConfiguration

Video encoder configurations.

public class VideoEncoderConfiguration {
  static public class VideoDimensions {
    public int width;
    public int height;
    public VideoDimensions(int width, int height) {
      this.width = width;
      this.height = height;
    }
    public VideoDimensions() {
      this.width = 0;
      this.height = 0;
    }
  }
  public final static VideoDimensions VD_120x120 = new VideoDimensions(120, 120);
  public final static VideoDimensions VD_160x120 = new VideoDimensions(160, 120);
  public final static VideoDimensions VD_180x180 = new VideoDimensions(180, 180);
  public final static VideoDimensions VD_240x180 = new VideoDimensions(240, 180);
  public final static VideoDimensions VD_320x180 = new VideoDimensions(320, 180);
  public final static VideoDimensions VD_240x240 = new VideoDimensions(240, 240);
  public final static VideoDimensions VD_320x240 = new VideoDimensions(320, 240);
  public final static VideoDimensions VD_424x240 = new VideoDimensions(424, 240);
  public final static VideoDimensions VD_360x360 = new VideoDimensions(360, 360);
  public final static VideoDimensions VD_480x360 = new VideoDimensions(480, 360);
  public final static VideoDimensions VD_640x360 = new VideoDimensions(640, 360);
  public final static VideoDimensions VD_480x480 = new VideoDimensions(480, 480);
  public final static VideoDimensions VD_640x480 = new VideoDimensions(640, 480);
  public final static VideoDimensions VD_840x480 = new VideoDimensions(840, 480);
  public final static VideoDimensions VD_960x540 = new VideoDimensions(960, 540);
  public final static VideoDimensions VD_960x720 = new VideoDimensions(960, 720);
  public final static VideoDimensions VD_1280x720 = new VideoDimensions(1280, 720);
  public final static VideoDimensions VD_1920x1080 = new VideoDimensions(1920, 1080);
  public final static VideoDimensions VD_2540x1440 = new VideoDimensions(2540, 1440);
  public final static VideoDimensions VD_3840x2160 = new VideoDimensions(3840, 2160);
  public enum FRAME_RATE {
    FRAME_RATE_FPS_1(1),
    FRAME_RATE_FPS_7(7),
    FRAME_RATE_FPS_10(10),
    FRAME_RATE_FPS_15(15),
    FRAME_RATE_FPS_24(24),
    FRAME_RATE_FPS_30(30),
    FRAME_RATE_FPS_60(60);
    private int value;
    private FRAME_RATE(int v) {
      value = v;
    }
    public int getValue() {
      return this.value;
    }
  }
  public enum ORIENTATION_MODE {
    ORIENTATION_MODE_ADAPTIVE(0),
    ORIENTATION_MODE_FIXED_LANDSCAPE(1),
    ORIENTATION_MODE_FIXED_PORTRAIT(2);
    private int value;
    private ORIENTATION_MODE(int v) {
      value = v;
    }
    public int getValue() {
      return this.value;
    }
  }
  public enum ENCODING_PREFERENCE {
    PREFER_AUTO(-1),
    PREFER_SOFTWARE(0),
    PREFER_HARDWARE(1);
    private int value;
    private ENCODING_PREFERENCE(int v) {
      value = v;
    }
    public int getValue() {
      return this.value;
    }
  }
  public enum COMPRESSION_PREFERENCE {
    PREFER_LOW_LATENCY(0),
    PREFER_QUALITY(1);
    private int value;
    private COMPRESSION_PREFERENCE(int v) {
      value = v;
    }
    public int getValue() {
      return this.value;
    }
  }
  static public class AdvanceOptions {
    public ENCODING_PREFERENCE encodingPreference;
    public COMPRESSION_PREFERENCE compressionPreference;
    public AdvanceOptions(
        ENCODING_PREFERENCE encodingPreference, COMPRESSION_PREFERENCE compressionPreference) {
      this.encodingPreference = encodingPreference;
      this.compressionPreference = compressionPreference;
    }
    public AdvanceOptions() {
      this.encodingPreference = ENCODING_PREFERENCE.PREFER_AUTO;
      this.compressionPreference = COMPRESSION_PREFERENCE.PREFER_LOW_LATENCY;
    }
  }
  public enum DEGRADATION_PREFERENCE {
    MAINTAIN_QUALITY(0),
    MAINTAIN_FRAMERATE(1),
    MAINTAIN_BALANCED(2),
    MAINTAIN_RESOLUTION(3),
    DISABLED(100);
    private int value;
    private DEGRADATION_PREFERENCE(int v) {
      value = v;
    }
    public int getValue() {
      return this.value;
    }
  }
  public enum CODEC_CAP_MASK {
    CODEC_CAP_MASK_NONE(0),
    CODEC_CAP_MASK_HW_DEC(1),
    CODEC_CAP_MASK_HW_ENC(2),
    CODEC_CAP_MASK_SW_DEC(4),
    CODEC_CAP_MASK_SW_ENC(8);
    private int value;
    private CODEC_CAP_MASK(int v) {
      value = v;
    }
    public int getValue() {
      return this.value;
    }
  }
  ;
  public enum MIRROR_MODE_TYPE {
    MIRROR_MODE_AUTO(0),
    MIRROR_MODE_ENABLED(1),
    MIRROR_MODE_DISABLED(2);
    private int value;
    private MIRROR_MODE_TYPE(int v) {
      value = v;
    }
    public int getValue() {
      return this.value;
    }
  }
  public enum VIDEO_CODEC_TYPE {
    VIDEO_CODEC_NONE(0),
    VIDEO_CODEC_VP8(1),
    VIDEO_CODEC_H264(2),
    VIDEO_CODEC_H265(3),
    VIDEO_CODEC_GENERIC(6),
    VIDEO_CODEC_GENERIC_H264(7),
    VIDEO_CODEC_AV1(12),
    VIDEO_CODEC_VP9(13),
    VIDEO_CODEC_GENERIC_JPEG(20);
    private int value;
    private VIDEO_CODEC_TYPE(int v) {
      value = v;
    }
    public int getValue() {
      return this.value;
    }
  }
  public static final int STANDARD_BITRATE = 0;
  public static final int COMPATIBLE_BITRATE = -1;
  public static final int DEFAULT_MIN_BITRATE = -1;
  public static final int DEFAULT_MIN_FRAMERATE = -1;
  public static final int DEFAULT_MIN_BITRATE_EQUAL_TO_TARGET_BITRATE = -2;
  public VideoDimensions dimensions;
  public int frameRate;
  public int minFrameRate;
  public int bitrate;
  public int minBitrate;
  public ORIENTATION_MODE orientationMode;
  public DEGRADATION_PREFERENCE degradationPrefer;
  public MIRROR_MODE_TYPE mirrorMode;
  public AdvanceOptions advanceOptions;
  public VIDEO_CODEC_TYPE codecType;
  public VideoEncoderConfiguration() {
    this.dimensions = new VideoDimensions(960, 540);
    this.frameRate = FRAME_RATE.FRAME_RATE_FPS_15.getValue();
    this.minFrameRate = DEFAULT_MIN_FRAMERATE;
    this.bitrate = STANDARD_BITRATE;
    this.minBitrate = DEFAULT_MIN_BITRATE;
    this.orientationMode = ORIENTATION_MODE.ORIENTATION_MODE_ADAPTIVE;
    this.degradationPrefer = DEGRADATION_PREFERENCE.MAINTAIN_QUALITY;
    this.mirrorMode = MIRROR_MODE_TYPE.MIRROR_MODE_DISABLED;
    this.advanceOptions = new AdvanceOptions(
        ENCODING_PREFERENCE.PREFER_AUTO, COMPRESSION_PREFERENCE.PREFER_LOW_LATENCY);
    this.codecType = VIDEO_CODEC_TYPE.VIDEO_CODEC_H265;
  }
  public VideoEncoderConfiguration(VideoDimensions dimensions, FRAME_RATE frameRate, int bitrate,
      ORIENTATION_MODE orientationMode) {
    this.dimensions = dimensions;
    this.frameRate = frameRate.getValue();
    this.minFrameRate = DEFAULT_MIN_FRAMERATE;
    this.bitrate = bitrate;
    this.minBitrate = DEFAULT_MIN_BITRATE;
    this.orientationMode = orientationMode;
    this.degradationPrefer = DEGRADATION_PREFERENCE.MAINTAIN_QUALITY;
    this.mirrorMode = MIRROR_MODE_TYPE.MIRROR_MODE_DISABLED;
    this.advanceOptions = new AdvanceOptions(
        ENCODING_PREFERENCE.PREFER_AUTO, COMPRESSION_PREFERENCE.PREFER_LOW_LATENCY);
    this.codecType = VIDEO_CODEC_TYPE.VIDEO_CODEC_H265;
  }
  public VideoEncoderConfiguration(VideoDimensions dimensions, FRAME_RATE frameRate, int bitrate,
      ORIENTATION_MODE orientationMode, MIRROR_MODE_TYPE mirrorMode) {
    this.dimensions = dimensions;
    this.frameRate = frameRate.getValue();
    this.minFrameRate = DEFAULT_MIN_FRAMERATE;
    this.bitrate = bitrate;
    this.minBitrate = DEFAULT_MIN_BITRATE;
    this.orientationMode = orientationMode;
    this.degradationPrefer = DEGRADATION_PREFERENCE.MAINTAIN_QUALITY;
    this.mirrorMode = mirrorMode;
    this.advanceOptions = new AdvanceOptions(
        ENCODING_PREFERENCE.PREFER_AUTO, COMPRESSION_PREFERENCE.PREFER_LOW_LATENCY);
    this.codecType = VIDEO_CODEC_TYPE.VIDEO_CODEC_H265;
  }
  public VideoEncoderConfiguration(
      int width, int height, FRAME_RATE frameRate, int bitrate, ORIENTATION_MODE orientationMode) {
    this.dimensions = new VideoDimensions(width, height);
    this.frameRate = frameRate.getValue();
    this.minFrameRate = DEFAULT_MIN_FRAMERATE;
    this.bitrate = bitrate;
    this.minBitrate = DEFAULT_MIN_BITRATE;
    this.orientationMode = orientationMode;
    this.degradationPrefer = DEGRADATION_PREFERENCE.MAINTAIN_QUALITY;
    this.mirrorMode = MIRROR_MODE_TYPE.MIRROR_MODE_DISABLED;
    this.advanceOptions = new AdvanceOptions(
        ENCODING_PREFERENCE.PREFER_AUTO, COMPRESSION_PREFERENCE.PREFER_LOW_LATENCY);
    this.codecType = VIDEO_CODEC_TYPE.VIDEO_CODEC_H265;
  }
  public VideoEncoderConfiguration(int width, int height, FRAME_RATE frameRate, int bitrate,
      ORIENTATION_MODE orientationMode, MIRROR_MODE_TYPE mirrorMode) {
    this.dimensions = new VideoDimensions(width, height);
    this.frameRate = frameRate.getValue();
    this.minFrameRate = DEFAULT_MIN_FRAMERATE;
    this.bitrate = bitrate;
    this.minBitrate = DEFAULT_MIN_BITRATE;
    this.orientationMode = orientationMode;
    this.degradationPrefer = DEGRADATION_PREFERENCE.MAINTAIN_QUALITY;
    this.mirrorMode = mirrorMode;
    this.advanceOptions = new AdvanceOptions(
        ENCODING_PREFERENCE.PREFER_AUTO, COMPRESSION_PREFERENCE.PREFER_LOW_LATENCY);
    this.codecType = VIDEO_CODEC_TYPE.VIDEO_CODEC_H265;
  }
}

Attributes

dimensions
Users can set the resolution by themselves, or directly select the desired resolution from the following list:
  • VD_120x120: The video resolution is 120 × 120.
  • VD_160x120: The video resolution is 160 × 120.
  • VD_180x180: The video resolution is 180 × 180.
  • VD_240x180: The video resolution is 240 × 180.
  • VD_320x180: The video resolution is 320 × 180.
  • VD_240x240: The video resolution is 240 × 240.
  • VD_320x240: The video resolution is 320 × 240.
  • VD_424x240: The video resolution is 424 × 240.
  • VD_360x360: The video resolution is 360 × 360.
  • VD_480x360: The video resolution is 480 × 360.
  • VD_640x360: The video resolution is 640 × 360.
  • VD_480x480: The video resolution is 480 × 480.
  • VD_640x480: The video resolution is 640 × 480.
  • VD_840x480: The video resolution is 840 × 480.
  • VD_960x540: The video resolution is 960 × 540.
  • VD_960x720: The video resolution is 960 × 720.
  • VD_1280x720: The video resolution is 1280 × 720.
  • VD_1920x1080: The video resolution is 1920 × 1080.
  • VD_2540x1440: The video resolution is 2540 × 1440.
  • VD_3840x2160: The video resolution is 3840 × 2160.
Attention:
  • Whether the 720p resolution or above can be supported depends on the device. If the device cannot support 720p, the frame rate will be lower than the set value.
  • The default value is 960 × 540.
codecType
The codec type of the local video stream. See VIDEO_CODEC_TYPE.
frameRate
The frame rate (fps) of the encoding video frame. The default value is 15. See FRAME_RATE.
bitrate

The encoding bitrate (Kbps) of the video. This parameter does not need to be set; keeping the default value STANDARD_BITRATE is sufficient. The SDK automatically matches the most suitable bitrate based on the video resolution and frame rate you have set. For the correspondence between video resolution, frame rate, and bitrate, please refer to Video profile.

  • STANDARD_BITRATE(0): (Recommended) Standard bitrate mode.
  • COMPATIBLE_BITRATE(-1): Adaptive bitrate mode. In general, Agora suggests that you do not use this value.
minBitrate

The minimum encoding bitrate (Kbps) of the video.

The SDK automatically adjusts the encoding bitrate to adapt to the network conditions. Using a value greater than the default value forces the video encoder to output high-quality images but may cause more packet loss and sacrifice the smoothness of the video transmission. Unless you have special requirements for image quality, Agora does not recommend changing this value.

Attention: This parameter only applies to the interactive streaming profile.
orientationMode
The orientation mode of the encoded video. See ORIENTATION_MODE.
degradationPreference
Video degradation preference under limited bandwidth. See DEGRADATION_PREFERENCE.
mirrorMode
The mirror mode specified in video encoder configurations only affect the view of remote users.
  • VIDEO_MIRROR_MODE_AUTO(0): The SDK determines whether to enable the mirror mode. The SDK disables mirror mode by default.
  • VIDEO_MIRROR_MODE_ENABLED(1): Enables the mirror mode for remote users.
  • VIDEO_MIRROR_MODE_DISABLED(2): Disables the mirror mode for remote users.
Attention: By default, the video is not mirrored.
advanceOptions
Advanced options for video encoding. See AdvanceOptions.