视频推流质量配置
功能介绍
本节介绍如何配置视频编码相关参数(分辨率、帧率、码率、QP 等)以及如何按“全局/单设备”两种粒度进行配置。
注意:
成功进入房间后,才可以进行视频推流质量配置;
1. 本地视频全局配置(setVideoCfg)
本地视频全局配置作用于本端视频的默认编码参数;当某个视频设备未设置“私有配置”时,会使用本地视频全局配置。
- 获取本地视频全局配置:调用 getVideoCfg,返回 JSON 字符串,格式参见 VideoCfg。
- 设置本地视频全局配置:调用 setVideoCfg,传入 JSON 字符串。
VideoCfg 字段说明(节选):
| 参数 | 类型 | 说明 |
|---|---|---|
| size | VSize | 分辨率:"wh",如 "1280720" |
| fps | int | 帧率(见 VideoCfg 约束) |
| maxbps | int | 最大码率(bit/秒),如 100000 表示 100kbps |
示例:将全局分辨率设为 1280×720、帧率 15,其它参数保持不变:
VideoCfg cfg = await RtcSDK.videoManager.getVideoCfg();
cfg.size = VSize(width: 1280, height: 720);
cfg.fps = 15;
RtcSDK.videoManager.setVideoCfg(cfg);
相关 API 请参考:
2. 单个视频设备私有配置(setLocVideoAttributes)
若希望对某一路视频设备(某个 videoID)单独设置编码参数,可使用私有配置:
- 设置私有配置:调用 setLocVideoAttributes(videoID, jsonAttributes),json 格式参见 VideoAttributes。
- 获取私有配置:调用 getLocVideoAttributes(videoID)。
私有配置未设置时,将自动使用全局配置(见上一节)。
示例:配置该视频设备为 720p,帧率 15,码率为 1mbps:
int videoID = /* 从 getAllVideoInfo 获取到的视频设备ID */;
VideoAttributes videoAttributes = await RtcSDK.videoManager.getLocVideoAttributes(videoID);
videoAttributes.quality2Cfg = VideoCfg cfg = (size: VSize(width: 576, height: 320), fps: 15);
// 第二档视频配置
RtcSDK.videoManager.setLocVideoAttributes(videoID, atvideoAttributestrs);
相关 API 与结构请参考:
3. 限制与注意
- 分辨率、码率等限制与所有帐号授权有关。
- 开启更大分辨率、码率时将增加更大cpu、带宽开销,建议按需设置。