视频推流质量配置
功能介绍
本节介绍如何配置视频编码相关参数(分辨率、帧率、码率、QP 等)以及如何按“全局/单设备”两种粒度进行配置。
注意:
成功进入房间后,才可以进行视频推流质量配置;
1. 本地视频全局配置(setVideoCfg)
本地视频全局配置作用于本端视频的默认编码参数;当某个视频设备未设置“私有配置”时,会使用本地视频全局配置。
- 获取本地视频全局配置:调用 getVideoCfg,返回 JSON 字符串,格式参见 VideoCfg。
- 设置本地视频全局配置:调用 setVideoCfg,传入 JSON 字符串。
VideoCfg 字段说明(节选):
| 参数 | 类型 | 说明 |
|---|---|---|
| size | string | 分辨率:"wh",如 "1280720" |
| fps | int | 帧率(见 VideoCfg 约束) |
| maxbps | int | 最大码率(bit/秒),如 100000 表示 100kbps |
示例:将全局分辨率设为 1280×720、帧率 15,其它参数保持不变:
RTCMeeting *meeting = [RTCMeeting shareInstance];
// 获取当前视频配置
VideoCfg *currentCfg = [meeting getVideoCfg];
currentCfg.size = CGSizeMake(1280, 720);
currentCfg.fps = 15;
BOOL success = [meeting setVideoCfg:currentCfg];
if (success) {
// 配置成功
} else {
// 配置失败
}
相关 API 请参考:
2. 单个视频设备私有配置(setLocVideoAttributes)
若希望对某一路视频设备(某个 videoID)单独设置编码参数,可使用私有配置:
- 设置私有配置:调用 setLocVideoAttributes(videoID, jsonAttributes),json 格式参见 CamAttribute。
- 获取私有配置:调用 getLocVideoAttributes(videoID)。
私有配置未设置时,将自动使用全局配置(见上一节)。
示例:配置该视频设备为 720p,帧率 15,码率为 1mbps:
RTCMeeting *meeting = [RTCMeeting shareInstance];
int videoID = videoDeviceID;
VideoCfg *quality1Cfg = [[VideoCfg alloc] init];
quality1Cfg.size = CGSizeMake(1280, 720); // 1280*720
quality1Cfg.fps = 15; // 15 fps
quality1Cfg.maxbps = 1000000; // 1000000 bps(即 1000 kbps)
CamAttribute *currentAttrs = [meeting getLocVideoAttributes:videoID];
currentAttrs.disabled = NO; // 是否禁用(false 表示启用)
currentAttrs.quality1_cfg = quality1Cfg;
[meeting setLocVideoAttributes:videoID attributes:currentAttrs];
相关 API 与结构请参考:
3. 限制与注意
- 分辨率、码率等限制与所有帐号授权有关。
- 开启更大分辨率、码率时将增加更大cpu、带宽开销,建议按需设置。