mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-09-12 18:44:25 +08:00
perf(video): 使用有界 VBR 优化 H264 码率
H264 编码器探测与初始化使用 VBR,将峰值码率和缓冲区限制为目标码率的两倍。动态调整码率时同步更新限制,并保留 QSV 的专用处理。
This commit is contained in:
@@ -397,6 +397,14 @@ struct CodecOptions {
|
|||||||
|
|
||||||
bool set_rate_control(AVCodecContext *c, const std::string &name, int rc,
|
bool set_rate_control(AVCodecContext *c, const std::string &name, int rc,
|
||||||
int q) {
|
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) {
|
if (name.find("vaapi") != std::string::npos && rc == RC_CQ) {
|
||||||
// Used only after the normal bitrate-based VAAPI initialization fails.
|
// Used only after the normal bitrate-based VAAPI initialization fails.
|
||||||
// Some drivers, including Intel iHD on Jasper Lake, expose CQP as their
|
// 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) {
|
bool change_bit_rate(AVCodecContext *c, const std::string &name, int kbs) {
|
||||||
if (kbs > 0) {
|
if (kbs > 0) {
|
||||||
c->bit_rate = kbs * 1000;
|
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) {
|
if (name.find("qsv") != std::string::npos) {
|
||||||
c->rc_max_rate = c->bit_rate;
|
c->rc_max_rate = c->bit_rate;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ pub fn get_available_encoders(width: u32, height: u32) -> Vec<CodecInfo> {
|
|||||||
align: 1,
|
align: 1,
|
||||||
fps: 30,
|
fps: 30,
|
||||||
gop: 30,
|
gop: 30,
|
||||||
rc: RateControl::RC_CBR,
|
rc: RateControl::RC_VBR,
|
||||||
quality: Quality::Quality_Low, // Use low quality preset for fastest encoding (ultrafast)
|
quality: Quality::Quality_Low, // Use low quality preset for fastest encoding (ultrafast)
|
||||||
kbs: 2000,
|
kbs: 2000,
|
||||||
q: 23,
|
q: 23,
|
||||||
@@ -297,7 +297,7 @@ impl H264Encoder {
|
|||||||
align: 1,
|
align: 1,
|
||||||
fps: config.fps as i32,
|
fps: config.fps as i32,
|
||||||
gop: config.gop_size as i32,
|
gop: config.gop_size as i32,
|
||||||
rc: RateControl::RC_CBR,
|
rc: RateControl::RC_VBR,
|
||||||
quality: Quality::Quality_Low, // Use low quality preset for fastest encoding (lowest latency)
|
quality: Quality::Quality_Low, // Use low quality preset for fastest encoding (lowest latency)
|
||||||
kbs: config.bitrate_kbps as i32,
|
kbs: config.bitrate_kbps as i32,
|
||||||
q: 23,
|
q: 23,
|
||||||
|
|||||||
Reference in New Issue
Block a user