LiveTranscoding
旁路推流的转码属性。
public class LiveTranscoding {
public enum AudioSampleRateType {
TYPE_32000(32000),
TYPE_44100(44100),
TYPE_48000(48000);
private int value;
private AudioSampleRateType(int v) {
value = v;
}
public static int getValue(AudioSampleRateType type) {
return type.value;
}
}
public enum VideoCodecProfileType {
BASELINE(66),
MAIN(77),
HIGH(100);
private int value;
private VideoCodecProfileType(int v) {
value = v;
}
public static int getValue(VideoCodecProfileType type) {
return type.value;
}
}
public enum AudioCodecProfileType {
LC_AAC(0),
HE_AAC(1),
HE_AAC(1);
HE_AAC_V2(2);
private int value;
private AudioCodecProfileType(int v) {
value = v;
}
public static int getValue(AudioCodecProfileType type) {
return type.value;
}
}
public enum VideoCodecType {
H264(1),
H265(2);
private int value;
private VideoCodecType(int v) {
value = v;
}
public static int getValue(VideoCodecType type) {
return type.value;
}
}
public int width;
public int height;
public int videoBitrate;
public int videoFramerate;
public boolean lowLatency;
@Deprecated public boolean lowLatency;
public int videoGop;
private ArrayList<AgoraImage> watermarkList;
public void addWatermark(AgoraImage watermark) {
if (watermarkList == null) {
watermarkList = new ArrayList<AgoraImage>();
}
watermarkList.add(watermark);
}
public boolean removeWatermark(AgoraImage watermark) {
if (watermarkList == null) {
return false;
}
return watermarkList.remove(watermark);
}
public ArrayList<AgoraImage> getWatermarkList() {
return watermarkList;
}
private ArrayList<AgoraImage> backgroundImageList;
public void addBackgroundImage(AgoraImage backgroundImage) {
if (backgroundImageList == null) {
backgroundImageList = new ArrayList<AgoraImage>();
}
backgroundImageList.add(backgroundImage);
}
public boolean removeBackgroundImage(AgoraImage backgroundImage) {
if (backgroundImageList == null) {
return false;
}
return backgroundImageList.remove(backgroundImage);
}
public ArrayList<AgoraImage> getBackgroundImageList() {
return backgroundImageList;
}
public AudioSampleRateType audioSampleRate;
public int audioBitrate;
public int audioChannels;
public AudioCodecProfileType audioCodecProfile;
public VideoCodecProfileType videoCodecProfile;
public VideoCodecType videoCodecType;
@Deprecated public int userCount;
@Deprecated public int backgroundColor;
public String userConfigExtraInfo;
public String metadata;
@Deprecated public String metadata;
private Map<Integer, TranscodingUser> transcodingUsers;
private Map<String, Boolean> advancedFeatures;
public void setAdvancedFeatures(String featureName, Boolean opened) {
advancedFeatures.put(featureName, opened);
}
public Map<String, Boolean> getAdvancedFeatures() {
return advancedFeatures;
}
public static class TranscodingUser {
public int uid;
public String userId;
public String userId;
public int x;
public int y;
public int width;
public int height;
public int zOrder;
public float alpha;
public int audioChannel;
public TranscodingUser() {
alpha = 1;
}
}
public LiveTranscoding() {
width = 360;
height = 640;
videoBitrate = 400;
videoCodecProfile = VideoCodecProfileType.HIGH;
videoCodecType = VideoCodecType.H264;
videoGop = 30;
videoFramerate = 15;
lowLatency = false;
audioSampleRate = AudioSampleRateType.TYPE_44100;
audioBitrate = 48;
audioChannels = 1;
audioCodecProfile = AudioCodecProfileType.LC_AAC;
transcodingUsers = new HashMap<>();
advancedFeatures = new HashMap<>();
backgroundColor = 0xFF000000;
userConfigExtraInfo = null;
metadata = null;
}
public int addUser(TranscodingUser user) {
if (user == null || user.uid == 0) {
return -Constants.ERR_INVALID_ARGUMENT;
}
transcodingUsers.put(user.uid, user);
userCount = transcodingUsers.size();
return Constants.ERR_OK;
}
public final ArrayList<TranscodingUser> getUsers() {
Collection<TranscodingUser> values = transcodingUsers.values();
return new ArrayList<>(values);
}
public void setUsers(ArrayList<TranscodingUser> users) {
transcodingUsers.clear();
if (users != null) {
for (TranscodingUser user : users) {
transcodingUsers.put(user.uid, user);
}
}
userCount = transcodingUsers.size();
}
public void setUsers(Map<Integer, TranscodingUser> users) {
transcodingUsers.clear();
if (users != null) {
transcodingUsers.putAll(users);
}
userCount = transcodingUsers.size();
}
public int removeUser(int uid) {
if (!transcodingUsers.containsKey(uid))
return -Constants.ERR_INVALID_ARGUMENT;
transcodingUsers.remove(uid);
userCount = transcodingUsers.size();
return Constants.ERR_OK;
}
public int getUserCount() {
return transcodingUsers.size();
}
public int getBackgroundColor() {
return this.backgroundColor;
}
public void setBackgroundColor(int color) {
this.backgroundColor = color;
}
public void setBackgroundColor(int red, int green, int blue) {
this.backgroundColor = (red << 16) | (green << 8) | (blue << 0);
}
@Deprecated
public int getRed() {
return (backgroundColor >> 16) & 0x0ff;
}
@Deprecated
public int getGreen() {
return (backgroundColor >> 8) & 0x0ff;
}
@Deprecated
public int getBlue() {
return backgroundColor & 0x0ff;
}
@Deprecated
public void setRed(int red) {
int green = getGreen();
int blue = getBlue();
this.backgroundColor = (red << 16) | (green << 8) | (blue << 0);
}
@Deprecated
public void setGreen(int green) {
int red = getRed();
int blue = getBlue();
this.backgroundColor = (red << 16) | (green << 8) | (blue << 0);
}
@Deprecated
public void setBlue(int blue) {
int red = getRed();
int green = getGreen();
this.backgroundColor = (red << 16) | (green << 8) | (blue << 0);
}
}
width
推流视频的总宽度,默认值 360,单位为像素。
- 如果推视频流,
width
取值范围为 [64,1920]。如果取值低于 64,声网服务器会自动调整为 64; 如果取值高于 1920,声网服务器会自动调整为 1920。 - 如果推音频流,请将
width
和height
设为 0。
height
推流视频的总高度,默认值 640,单位为像素。
- 如果推视频流,
height
取值范围为 [64,1080]。如果取值低于 64,声网服务器会自动调整为 64; 如果取值高于 1080,声网服务器会自动调整为 1080。 - 如果推音频流,请将
width
和height
设为 0。
videoBitrate
用于旁路直播的输出视频的码率。单位为 Kbps。400 Kbps 为默认值。
你可以根据视频属性参考表中的码率值进行设置;如果设置的码率超出合理范围,声网服务器会在合理区间内自动调整码率值。
videoFrameRate
用于旁路直播的输出视频的帧率。取值范围是 (0,30],单位为 fps。15 fps 为默认值。
注意: 声网服务器会将高于 30 fps 的帧率统一调整为 30 fps。
lowLatency
低延时模式
true
: 低延时,不保证画质。false
:(默认值)高延时,保证画质。
弃用
不建议使用。
videoGop
用于旁路直播的输出视频的 GOP(Group of Pictures)。单位为帧。默认值为 30。
videoCodecProfile
用于旁路直播的输出视频的编码规格。可以设置为 66、77 或 100,详见 VideoCodecProfileType
。
注意: 如果你把这个参数设为其他值,声网服务器会将其调整为默认值。
videoCodecType
用于旁路直播的输出视频的编解码类型。详见 VideoCodecType
。
transcodingUsers
用于管理参与旁路直播的视频转码合图的用户。最多支持 17 人同时参与转码合图。详见 TranscodingUser
。
userConfigExtraInfo
预留参数:用户自定义的发送到旁路推流客户端的信息,用于填充 H264/H265 视频中 SEI 帧内容。长度限制:4096 字节。关于 SEI 的详细信息,详见 SEI 帧相关问题。
backgroundColor
弃用
已废弃,不建议使用。请改用 setBackgroundColor [1/2]
方法。
userCount
弃用
已废弃,不建议使用。请改用 getUserCount
方法。
metadata
发送给 CDN 客户端的 metadata。
弃用
已废弃,不建议使用。
audioSampleRate
用于旁路推流的输出媒体流的音频采样率 (Hz),详见 AudioSampleRateType
。
audioBitrate
用于旁路直播的输出音频的码率。单位为 Kbps,默认值为 48,最大值为 128。
audioChannels
用于旁路直播的输出音频的声道数,默认值为 1。取值范围为 [1,5] 中的整型,建议取 1 或 2。3、4、5 需要特殊播放器支持:
- 1: (默认)单声道
- 2: 双声道
- 3: 三声道
- 4: 四声道
- 5: 五声道
audioCodecProfile
用于旁路直播输出音频的编码规格。详见 AudioCodecProfileType
。