make hwcodec's bitrate the same as vpx
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
parent
b45dc606f1
commit
75fc49b301
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -2234,7 +2234,7 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||
[[package]]
|
||||
name = "hwcodec"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/21pages/hwcodec#0b5dbdbf3ef5cd41d27b691ebd00bf7646ad6d78"
|
||||
source = "git+https://github.com/21pages/hwcodec#bfc558d2375928b0a59336cfc72336415db27066"
|
||||
dependencies = [
|
||||
"bindgen",
|
||||
"cc",
|
||||
|
@ -33,7 +33,7 @@ pub struct HwEncoderConfig {
|
||||
pub codec_name: String,
|
||||
pub width: usize,
|
||||
pub height: usize,
|
||||
pub bitrate_ratio: i32,
|
||||
pub bitrate: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -49,19 +49,17 @@ impl EncoderApi for HwEncoder {
|
||||
{
|
||||
match cfg {
|
||||
EncoderCfg::HW(config) => {
|
||||
let (bitrate, timebase, gop, quality, rc) =
|
||||
HwEncoder::convert_quality(&config.codec_name, config.bitrate_ratio);
|
||||
let ctx = EncodeContext {
|
||||
name: config.codec_name.clone(),
|
||||
width: config.width as _,
|
||||
height: config.height as _,
|
||||
pixfmt: DEFAULT_PIXFMT,
|
||||
align: HW_STRIDE_ALIGN as _,
|
||||
bitrate,
|
||||
timebase,
|
||||
gop,
|
||||
quality,
|
||||
rc,
|
||||
bitrate: config.bitrate * 1000,
|
||||
timebase: DEFAULT_TIME_BASE,
|
||||
gop: DEFAULT_GOP,
|
||||
quality: DEFAULT_HW_QUALITY,
|
||||
rc: DEFAULT_RC,
|
||||
};
|
||||
let format = match Encoder::format_from_name(config.codec_name.clone()) {
|
||||
Ok(format) => format,
|
||||
@ -142,7 +140,8 @@ impl EncoderApi for HwEncoder {
|
||||
}
|
||||
|
||||
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()),
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -553,7 +553,7 @@ fn run(sp: GenericService) -> ResultType<()> {
|
||||
codec_name,
|
||||
width,
|
||||
height,
|
||||
bitrate_ratio: bitrate as _,
|
||||
bitrate: bitrate as _,
|
||||
}),
|
||||
None => EncoderCfg::VPX(VpxEncoderConfig {
|
||||
width: width as _,
|
||||
|
Loading…
x
Reference in New Issue
Block a user