update hwcodec, use ms as pts like vpx (#8422)

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages 2024-06-20 13:57:56 +08:00 committed by GitHub
parent 7956953669
commit 30bd4e1cef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 24 additions and 17 deletions

4
Cargo.lock generated
View File

@ -3037,8 +3037,8 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "hwcodec"
version = "0.4.17"
source = "git+https://github.com/21pages/hwcodec#38eb9bfc4730986ebeb519ab39027d654356ce1a"
version = "0.4.18"
source = "git+https://github.com/21pages/hwcodec#b84d5bbefa949194d1fc51a5c7e9d7988e315ce6"
dependencies = [
"bindgen 0.59.2",
"cc",

View File

@ -287,13 +287,17 @@ mod hw {
let mut mid_data = Vec::new();
let mut counter = 0;
let mut time_sum = Duration::ZERO;
let start = std::time::Instant::now();
loop {
match c.frame(std::time::Duration::from_millis(30)) {
Ok(frame) => {
let tmp_timer = Instant::now();
let frame = frame.to(encoder.yuvfmt(), &mut yuv, &mut mid_data).unwrap();
let yuv = frame.yuv().unwrap();
for ref frame in encoder.encode(&yuv).unwrap() {
for ref frame in encoder
.encode(&yuv, start.elapsed().as_millis() as _)
.unwrap()
{
size += frame.data.len();
h26xs.push(frame.data.to_vec());

View File

@ -28,7 +28,7 @@ use hwcodec::{
};
const DEFAULT_PIXFMT: AVPixelFormat = AVPixelFormat::AV_PIX_FMT_NV12;
pub const DEFAULT_TIME_BASE: [i32; 2] = [1, 30];
pub const DEFAULT_FPS: i32 = 30;
const DEFAULT_GOP: i32 = i32::MAX;
const DEFAULT_HW_QUALITY: Quality = Quality_Default;
@ -82,7 +82,7 @@ impl EncoderApi for HwRamEncoder {
pixfmt: DEFAULT_PIXFMT,
align: HW_STRIDE_ALIGN as _,
kbs: bitrate as i32,
timebase: DEFAULT_TIME_BASE,
fps: DEFAULT_FPS,
gop,
quality: DEFAULT_HW_QUALITY,
rc,
@ -113,16 +113,16 @@ impl EncoderApi for HwRamEncoder {
}
}
fn encode_to_message(&mut self, input: EncodeInput, _ms: i64) -> ResultType<VideoFrame> {
fn encode_to_message(&mut self, input: EncodeInput, ms: i64) -> ResultType<VideoFrame> {
let mut vf = VideoFrame::new();
let mut frames = Vec::new();
for frame in self
.encode(input.yuv()?)
.encode(input.yuv()?, ms)
.with_context(|| "Failed to encode")?
{
frames.push(EncodedVideoFrame {
data: Bytes::from(frame.data),
pts: frame.pts as _,
pts: frame.pts,
key: frame.key == 1,
..Default::default()
});
@ -236,8 +236,8 @@ impl HwRamEncoder {
info
}
pub fn encode(&mut self, yuv: &[u8]) -> ResultType<Vec<EncodeFrame>> {
match self.encoder.encode(yuv) {
pub fn encode(&mut self, yuv: &[u8], ms: i64) -> ResultType<Vec<EncodeFrame>> {
match self.encoder.encode(yuv, ms) {
Ok(v) => {
let mut data = Vec::<EncodeFrame>::new();
data.append(v);
@ -664,7 +664,7 @@ pub fn check_available_hwcodec() -> String {
pixfmt: DEFAULT_PIXFMT,
align: HW_STRIDE_ALIGN as _,
kbs: 0,
timebase: DEFAULT_TIME_BASE,
fps: DEFAULT_FPS,
gop: DEFAULT_GOP,
quality: DEFAULT_HW_QUALITY,
rc: RC_CBR,

View File

@ -331,7 +331,7 @@ impl RecorderApi for HwRecorder {
width: ctx.width,
height: ctx.height,
is265: ctx.format == CodecFormat::H265,
framerate: crate::hwcodec::DEFAULT_TIME_BASE[1] as _,
framerate: crate::hwcodec::DEFAULT_FPS as _,
})
.map_err(|_| anyhow!("Failed to create hardware muxer"))?;
Ok(HwRecorder {

View File

@ -99,15 +99,18 @@ impl EncoderApi for VRamEncoder {
fn encode_to_message(
&mut self,
frame: EncodeInput,
_ms: i64,
ms: i64,
) -> ResultType<hbb_common::message_proto::VideoFrame> {
let texture = frame.texture()?;
let mut vf = VideoFrame::new();
let mut frames = Vec::new();
for frame in self.encode(texture).with_context(|| "Failed to encode")? {
for frame in self
.encode(texture, ms)
.with_context(|| "Failed to encode")?
{
frames.push(EncodedVideoFrame {
data: Bytes::from(frame.data),
pts: frame.pts as _,
pts: frame.pts,
key: frame.key == 1,
..Default::default()
});
@ -266,8 +269,8 @@ impl VRamEncoder {
}
}
pub fn encode(&mut self, texture: *mut c_void) -> ResultType<Vec<EncodeFrame>> {
match self.encoder.encode(texture) {
pub fn encode(&mut self, texture: *mut c_void, ms: i64) -> ResultType<Vec<EncodeFrame>> {
match self.encoder.encode(texture, ms) {
Ok(v) => {
let mut data = Vec::<EncodeFrame>::new();
data.append(v);