设置编码配置文件
本教程主要介绍如何。
1. 设置视频编码配置。
2. 设置音频编码配置。
3. 设置屏幕共享编码配置。
设置视频编码配置
指定预定义的配置文件,每个配置文件对应一组推荐的分辨率、帧率和比特率。
// Specify video profile when startingawait trtc.startLocalVideo({option: { profile: '480p' }});// Dynamically adjust video profile during the callawait trtc.updateLocalVideo({option: { profile: '360p' }});
视频 Profile | 分辨率(宽x高) | 帧率 (fps) | 比特率(kbps) |
120p | 160 x 120 | 15 | 200 |
180p | 320 x 180 | 15 | 350 |
240p | 320 x 240 | 15 | 400 |
360p | 640 x 360 | 15 | 800 |
480p | 640 x 480 | 15 | 900 |
720p | 1280 x 720 | 15 | 1500 |
1080p | 1920 x 1080 | 15 | 2000 |
1440p | 2560 x 1440 | 30 | 4860 |
4K | 3840 x 2160 | 30 | 9000 |
指定自定义分辨率、帧率和比特率:
// Specify video profile when startingawait trtc.startLocalVideo({option: { profile: { width: 640, height: 480, frameRate: 15, bitrate: 900 /* kpbs */} }});// Dynamically adjust video profile during the callawait trtc.updateLocalVideo({option: { profile: { width: 640, height: 360, frameRate: 15, bitrate: 800 /* kpbs */} }});
说明:
1. 由于设备和浏览器的限制,视频分辨率可能不完全匹配。在这种情况下,浏览器会自动调整分辨率,使其更接近 profile 指定的分辨率。
2. 由于网络和CPU性能的原因,视频编码的分辨率和帧率可能会低于预期。
2.1 对于摄像头来说,默认是帧率优先,性能不足时适当降低分辨率,优先保障帧率编码。
2.2 对于屏幕共享,默认是分辨率优先,性能不足时适当降低帧率,优先保障分辨率编码。
您可以通过 trtc.startLocalVideo() 和 trtc.updateLocalVideo()中的 qosPreference 参数更改此优先级。请参阅 QOS_PREFERENCE_SMOOTH 和 QOS_PREFERENCE_CLEAR.
设置音频编码配置
// Default profileawait trtc.startLocalAudio({ option: { profile: TRTC.TYPE.AUDIO_PROFILE_STANDARD }});// Note: SDK does not support dynamic adjustment of audio profile during the call.// You have to set audio profile in trtc.startLocalAudioawait trtc.updateLocalAudio({ option: { profile: TRTC.TYPE.AUDIO_PROFILE_HIGH }}); // Does not works.
Audio Profile | 采样率 | 声道数 | 比特率 (kbps) |
TRTC.TYPE.AUDIO_PROFILE_STANDARD(Default) | 48000 | 单声道 | 40 |
TRTC.TYPE.AUDIO_PROFILE_HIGH | 48000 | 单声道 | 128 |
TRTC.TYPE.AUDIO_PROFILE_STANDARD_STEREO | 48000 | 双声道 | 64 |
TRTC.TYPE.AUDIO_PROFILE_HIGH_STEREO | 48000 | 双声道 | 192 |
设置屏幕共享编码配置
// The default profile is '1080p'await trtc.startScreenShare({ option: { profile: '1080p_2' }});// Note: SDK does not support dynamic adjustment of screen sharing profile during the call.// Specify custom profile when startingawait trtc.startLocalVideo({option: { profile: { width: 1280, height: 720, frameRate: 15, bitrate: 1500 /* kpbs */} }});
屏幕 Profile | 分辨率(宽x高) | 帧率 (fps) | 比特率(kbps) |
480p | 640 x 480 | 5 | 900 |
480p_2 | 640 x 480 | 30 | 1000 |
720p | 1280 x 720 | 5 | 1200 |
720p_2 | 1280 x 720 | 30 | 3000 |
1080p | 1920 x 1080 | 5 | 1600 |
1080p_2 | 1920 x 1080 | 30 | 4000 |