make hwcodec's bitrate the same as vpx

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2022-06-29 09:46:42 +08:00
parent b45dc606f1
commit 75fc49b301
4 changed files with 10 additions and 33 deletions

2
Cargo.lock generated
View File

@ -2234,7 +2234,7 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]] [[package]]
name = "hwcodec" name = "hwcodec"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/21pages/hwcodec#0b5dbdbf3ef5cd41d27b691ebd00bf7646ad6d78" source = "git+https://github.com/21pages/hwcodec#bfc558d2375928b0a59336cfc72336415db27066"
dependencies = [ dependencies = [
"bindgen", "bindgen",
"cc", "cc",

View File

@ -33,7 +33,7 @@ pub struct HwEncoderConfig {
pub codec_name: String, pub codec_name: String,
pub width: usize, pub width: usize,
pub height: usize, pub height: usize,
pub bitrate_ratio: i32, pub bitrate: i32,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View File

@ -49,19 +49,17 @@ impl EncoderApi for HwEncoder {
{ {
match cfg { match cfg {
EncoderCfg::HW(config) => { EncoderCfg::HW(config) => {
let (bitrate, timebase, gop, quality, rc) =
HwEncoder::convert_quality(&config.codec_name, config.bitrate_ratio);
let ctx = EncodeContext { let ctx = EncodeContext {
name: config.codec_name.clone(), name: config.codec_name.clone(),
width: config.width as _, width: config.width as _,
height: config.height as _, height: config.height as _,
pixfmt: DEFAULT_PIXFMT, pixfmt: DEFAULT_PIXFMT,
align: HW_STRIDE_ALIGN as _, align: HW_STRIDE_ALIGN as _,
bitrate, bitrate: config.bitrate * 1000,
timebase, timebase: DEFAULT_TIME_BASE,
gop, gop: DEFAULT_GOP,
quality, quality: DEFAULT_HW_QUALITY,
rc, rc: DEFAULT_RC,
}; };
let format = match Encoder::format_from_name(config.codec_name.clone()) { let format = match Encoder::format_from_name(config.codec_name.clone()) {
Ok(format) => format, Ok(format) => format,
@ -142,7 +140,8 @@ impl EncoderApi for HwEncoder {
} }
fn set_bitrate(&mut self, bitrate: u32) -> ResultType<()> { fn set_bitrate(&mut self, bitrate: u32) -> ResultType<()> {
todo!() self.encoder.set_bitrate((bitrate * 1000) as _).ok();
Ok(())
} }
} }
@ -218,28 +217,6 @@ impl HwEncoder {
Err(_) => Ok(Vec::<EncodeFrame>::new()), Err(_) => Ok(Vec::<EncodeFrame>::new()),
} }
} }
fn convert_quality(
name: &str,
bitrate_ratio: i32,
) -> (i32, [i32; 2], i32, Quality, RateContorl) {
// TODO
let mut bitrate = if name.contains("qsv") {
1_000_000
} else {
2_000_000
};
if bitrate_ratio > 0 && bitrate_ratio <= 200 {
bitrate = bitrate * bitrate_ratio / 100;
};
(
bitrate,
DEFAULT_TIME_BASE,
DEFAULT_GOP,
DEFAULT_HW_QUALITY,
DEFAULT_RC,
)
}
} }
pub struct HwDecoder { pub struct HwDecoder {

View File

@ -553,7 +553,7 @@ fn run(sp: GenericService) -> ResultType<()> {
codec_name, codec_name,
width, width,
height, height,
bitrate_ratio: bitrate as _, bitrate: bitrate as _,
}), }),
None => EncoderCfg::VPX(VpxEncoderConfig { None => EncoderCfg::VPX(VpxEncoderConfig {
width: width as _, width: width as _,