fix: assign encoder timebase from sample rate
This commit is contained in:
parent
497234f4b2
commit
b226e011db
@ -81,7 +81,7 @@ mod tests {
|
|||||||
|
|
||||||
let mut enc = Encoder::new_with_name("libfdk_aac")?
|
let mut enc = Encoder::new_with_name("libfdk_aac")?
|
||||||
.with_sample_format(AVSampleFormat::AV_SAMPLE_FMT_S16)
|
.with_sample_format(AVSampleFormat::AV_SAMPLE_FMT_S16)
|
||||||
.with_sample_rate(48_000)
|
.with_sample_rate(48_000)?
|
||||||
.with_default_channel_layout(2)
|
.with_default_channel_layout(2)
|
||||||
.open(None)?;
|
.open(None)?;
|
||||||
|
|
||||||
|
@ -108,9 +108,13 @@ impl Encoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set the encoder sample rate (audio)
|
/// Set the encoder sample rate (audio)
|
||||||
pub unsafe fn with_sample_rate(self, fmt: i32) -> Self {
|
pub unsafe fn with_sample_rate(self, rate: i32) -> Result<Self> {
|
||||||
(*self.ctx).sample_rate = fmt;
|
if (*self.ctx).time_base.num != 1 || (*self.ctx).time_base.den != 1 {
|
||||||
self
|
bail!("Cannot assign sample_rate for a video encoder")
|
||||||
|
}
|
||||||
|
(*self.ctx).sample_rate = rate;
|
||||||
|
(*self.ctx).time_base = AVRational { num: 1, den: rate };
|
||||||
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the encoder width in pixels
|
/// Set the encoder width in pixels
|
||||||
@ -138,11 +142,14 @@ impl Encoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set the encoder framerate
|
/// Set the encoder framerate
|
||||||
pub unsafe fn with_framerate(self, fps: f32) -> Self {
|
pub unsafe fn with_framerate(self, fps: f32) -> Result<Self> {
|
||||||
|
if (*self.ctx).time_base.num != 1 || (*self.ctx).time_base.den != 1 {
|
||||||
|
bail!("Cannot assign framerate for an audio encoder")
|
||||||
|
}
|
||||||
let q = av_d2q(fps as f64, 90_000);
|
let q = av_d2q(fps as f64, 90_000);
|
||||||
(*self.ctx).framerate = q;
|
(*self.ctx).framerate = q;
|
||||||
(*self.ctx).time_base = av_inv_q(q);
|
(*self.ctx).time_base = av_inv_q(q);
|
||||||
self
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the encoder pixel format
|
/// Set the encoder pixel format
|
||||||
|
@ -400,7 +400,7 @@ mod tests {
|
|||||||
.with_height((*frame).height)
|
.with_height((*frame).height)
|
||||||
.with_pix_fmt(AV_PIX_FMT_YUV420P)
|
.with_pix_fmt(AV_PIX_FMT_YUV420P)
|
||||||
.with_bitrate(1_000_000)
|
.with_bitrate(1_000_000)
|
||||||
.with_framerate(30.0)
|
.with_framerate(30.0)?
|
||||||
.with_profile(AV_PROFILE_H264_MAIN)
|
.with_profile(AV_PROFILE_H264_MAIN)
|
||||||
.with_level(50)
|
.with_level(50)
|
||||||
.open(None)?;
|
.open(None)?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user