perf(video): 使用有界 VBR 优化 H264 码率

H264 编码器探测与初始化使用 VBR,将峰值码率和缓冲区限制为目标码率的两倍。动态调整码率时同步更新限制,并保留 QSV 的专用处理。
This commit is contained in:
mofeng-git
2026-09-05 14:10:53 +08:00
parent 3749bafae0
commit a8ee9552a0
2 changed files with 14 additions and 2 deletions

View File

@@ -397,6 +397,14 @@ struct CodecOptions {
bool set_rate_control(AVCodecContext *c, const std::string &name, int rc,
int q) {
// Remote-desktop content is usually sparse. VBR avoids padding static
// frames up to the target bitrate while allowing short bursts for screen
// changes. Keep those bursts bounded at twice the target bitrate.
if (rc == RC_VBR && c->bit_rate > 0) {
c->rc_max_rate = c->bit_rate * 2;
c->rc_buffer_size = c->rc_max_rate;
}
if (name.find("vaapi") != std::string::npos && rc == RC_CQ) {
// Used only after the normal bitrate-based VAAPI initialization fails.
// Some drivers, including Intel iHD on Jasper Lake, expose CQP as their
@@ -495,6 +503,10 @@ bool set_others(void *priv_data, const std::string &name) {
bool change_bit_rate(AVCodecContext *c, const std::string &name, int kbs) {
if (kbs > 0) {
c->bit_rate = kbs * 1000;
if (c->rc_max_rate > 0 && name.find("qsv") == std::string::npos) {
c->rc_max_rate = c->bit_rate * 2;
c->rc_buffer_size = c->rc_max_rate;
}
if (name.find("qsv") != std::string::npos) {
c->rc_max_rate = c->bit_rate;
}