VideoEncoderConfiguration
视频编码器的配置。
Java
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 boolean encodeAlpha;
public AdvanceOptions(ENCODING_PREFERENCE encodingPreference,
COMPRESSION_PREFERENCE compressionPreference, boolean encodeAlpha) {
this.encodingPreference = encodingPreference;
this.compressionPreference = compressionPreference;
this.encodeAlpha = encodeAlpha;
}
public AdvanceOptions() {
this.encodingPreference = ENCODING_PREFERENCE.PREFER_AUTO;
this.compressionPreference = COMPRESSION_PREFERENCE.PREFER_LOW_LATENCY;
this.encodeAlpha = false;
}
}
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, false);
this.codecType = VIDEO_CODEC_TYPE.VIDEO_CODEC_NONE;
}
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, false);
this.codecType = VIDEO_CODEC_TYPE.VIDEO_CODEC_NONE;
}
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, false);
this.codecType = VIDEO_CODEC_TYPE.VIDEO_CODEC_NONE;
}
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, false);
this.codecType = VIDEO_CODEC_TYPE.VIDEO_CODEC_NONE;
}
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, false);
this.codecType = VIDEO_CODEC_TYPE.VIDEO_CODEC_NONE;
}
}
dimensions
用户可以自行设置分辨率,也可以在如下列表中直接选择想要的分辨率:
- VD_120x120:视频分辨率为 120 × 120。
- VD_160x120:视频分辨率为 160 × 120。
- VD_180x180:视频分辨率为 180 × 180。
- VD_240x180:视频分辨率为 240 × 180。
- VD_320x180:视频分辨率为 320 × 180。
- VD_240x240:视频分辨率为 240 × 240。
- VD_320x240:视频分辨率为 320 × 240。
- VD_424x240:视频分辨率为 424 × 240。
- VD_360x360:视频分辨率为 360 × 360。
- VD_480x360:视频分辨率为 480 × 360。
- VD_640x360:视频分辨率为 640 × 360。
- VD_480x480:视频分辨率为 480 × 480。
- VD_640x480:视频分辨率为 640 × 480。
- VD_840x480:视频分辨率为 840 × 480。
- VD_960x540:视频分辨率为 960 × 540。
- VD_960x720:视频分辨率为 960 × 720。
- VD_1280x720:视频分辨率为 1280 × 720。
- VD_1920x1080:视频分辨率为 1920 × 1080。
- VD_2540x1440:视频分辨率为 2540 × 1440。
- VD_3840x2160:视频分辨率为 3840 × 2160。
注意
- 视频能否达到 720P 及以上分辨率取决于设备的性能,在性能配备较低的设备上有可能无法实现。如果采用 720P 分辨率而设备性能跟不上,则有可能出现帧率过低的情况。
- 默认值为 960 × 540。
codecType
视频编码类型,详见 VIDEO_CODEC_TYPE。
frameRate
视频编码的帧率(fps),默认值为 15。详见 FRAME_RATE。
bitrate
视频编码码率,单位为 Kbps。该参数无需设置,保留默认值 STANDARD_BITRATE 即可,SDK 会根据你设定的视频分辨率和帧率自动匹配最合适的码率。有关视频分辨率和帧率的对应关系,详见视频属性。
- STANDARD_BITRATE (0): (默认) 标准码率模式。
- COMPATIBLE_BITRATE (-1): 适配码率模式。一般情况下,声网建议你不要使用该值。
minBitrate
最低编码码率,单位为 Kbps。
SDK 会根据网络状况自动调整视频编码码率。将参数设为高于默认值可强制视频编码器输出高质量图片,但在网络状况不佳情况下可能导致网络丢包并影响视频播放的流畅度造成卡顿。因此如非对画质有特殊需求,声网建议不要修改该参数的值。
注意
该参数仅适用于直播场景。
orientationMode
视频编码的方向模式,详见 ORIENTATION_MODE。
degradationPreference
带宽受限时,视频编码降级偏好。详见 DEGRADATION_PREFERENCE。
注意
当该参数设置为 MAINTAIN_FRAMERATE (1) 或者 MAINTAIN_BALANCED (2) 时,需要同时将 orientationMode 设置为 ORIENTATION_MODE_ADAPTIVE (0),否则设置不生效。
mirrorMode
发送编码视频时是否开启镜像模式,只影响远端用户看到的视频画面。
- VIDEO_MIRROR_MODE_AUTO (0):SDK 决定镜像模式。默认关闭远端用户的镜像模式。
- VIDEO_MIRROR_MODE_ENABLED (1):开启远端用户的镜像模式。
- VIDEO_MIRROR_MODE_DISABLED (2):关闭远端用户的镜像模式。
注意
默认关闭镜像模式。
advanceOptions
视频编码的高级选项。详见 AdvanceOptions。