feat: audio audio channel count

This commit is contained in:
2025-06-09 11:23:38 +01:00
parent 29ab054747
commit 7a7d116ce0
3 changed files with 24 additions and 19 deletions

View File

@ -78,16 +78,16 @@ mod tests {
#[test] #[test]
fn test_buffer() -> Result<()> { fn test_buffer() -> Result<()> {
unsafe { unsafe {
let mut buf = AudioFifo::new(AVSampleFormat::AV_SAMPLE_FMT_S16, 2)?; let mut buf = AudioFifo::new(AVSampleFormat::AV_SAMPLE_FMT_FLTP, 2)?;
let mut enc = Encoder::new_with_name("libfdk_aac")? let mut enc = Encoder::new_with_name("aac")?
.with_sample_format(AVSampleFormat::AV_SAMPLE_FMT_S16) .with_sample_format(AVSampleFormat::AV_SAMPLE_FMT_FLTP)
.with_sample_rate(48_000)? .with_sample_rate(48_000)?
.with_default_channel_layout(2) .with_default_channel_layout(2)
.open(None)?; .open(None)?;
let mut demo_frame = av_frame_alloc(); let mut demo_frame = av_frame_alloc();
(*demo_frame).format = AVSampleFormat::AV_SAMPLE_FMT_S16 as _; (*demo_frame).format = AVSampleFormat::AV_SAMPLE_FMT_FLTP as _;
(*demo_frame).ch_layout = AVChannelLayout::empty(); (*demo_frame).ch_layout = AVChannelLayout::empty();
av_channel_layout_default(&mut (*demo_frame).ch_layout, 2); av_channel_layout_default(&mut (*demo_frame).ch_layout, 2);
(*demo_frame).nb_samples = 2048; (*demo_frame).nb_samples = 2048;

View File

@ -107,7 +107,7 @@ impl Demuxer {
let ret = avformat_open_input( let ret = avformat_open_input(
&mut self.ctx, &mut self.ctx,
if let Some(url) = url { if let Some(url) = url {
cstr!(url.as_str()) cstr!(url.as_str()) as _
} else { } else {
ptr::null_mut() ptr::null_mut()
}, },
@ -173,42 +173,45 @@ impl Demuxer {
AVMediaType::AVMEDIA_TYPE_VIDEO => { AVMediaType::AVMEDIA_TYPE_VIDEO => {
streams.push(StreamInfo { streams.push(StreamInfo {
stream, stream,
index: (*stream).index as usize, index: (*stream).index as _,
codec: (*(*stream).codecpar).codec_id as isize, codec: (*(*stream).codecpar).codec_id as _,
stream_type: StreamType::Video, stream_type: StreamType::Video,
width: (*(*stream).codecpar).width as usize, width: (*(*stream).codecpar).width as _,
height: (*(*stream).codecpar).height as usize, height: (*(*stream).codecpar).height as _,
fps: av_q2d((*stream).avg_frame_rate) as f32, fps: av_q2d((*stream).avg_frame_rate) as _,
format: (*(*stream).codecpar).format as isize, format: (*(*stream).codecpar).format as _,
sample_rate: 0, sample_rate: 0,
channels: 0,
language, language,
}); });
} }
AVMediaType::AVMEDIA_TYPE_AUDIO => { AVMediaType::AVMEDIA_TYPE_AUDIO => {
streams.push(StreamInfo { streams.push(StreamInfo {
stream, stream,
index: (*stream).index as usize, index: (*stream).index as _,
codec: (*(*stream).codecpar).codec_id as isize, codec: (*(*stream).codecpar).codec_id as _,
stream_type: StreamType::Audio, stream_type: StreamType::Audio,
width: (*(*stream).codecpar).width as usize, width: (*(*stream).codecpar).width as _,
height: (*(*stream).codecpar).height as usize, height: (*(*stream).codecpar).height as _,
fps: 0.0, fps: 0.0,
format: (*(*stream).codecpar).format as isize, format: (*(*stream).codecpar).format as _,
sample_rate: (*(*stream).codecpar).sample_rate as usize, sample_rate: (*(*stream).codecpar).sample_rate as _,
channels: (*(*stream).codecpar).ch_layout.nb_channels as _,
language, language,
}); });
} }
AVMediaType::AVMEDIA_TYPE_SUBTITLE => { AVMediaType::AVMEDIA_TYPE_SUBTITLE => {
streams.push(StreamInfo { streams.push(StreamInfo {
stream, stream,
index: (*stream).index as usize, index: (*stream).index as _,
codec: (*(*stream).codecpar).codec_id as isize, codec: (*(*stream).codecpar).codec_id as _,
stream_type: StreamType::Subtitle, stream_type: StreamType::Subtitle,
width: 0, width: 0,
height: 0, height: 0,
fps: 0.0, fps: 0.0,
format: 0, format: 0,
sample_rate: 0, sample_rate: 0,
channels: 0,
language, language,
}); });
} }

View File

@ -133,6 +133,8 @@ pub struct StreamInfo {
pub sample_rate: usize, pub sample_rate: usize,
/// Subtitle / Audio language /// Subtitle / Audio language
pub language: String, pub language: String,
/// Number of audio channels
pub channels: u8,
// private stream pointer // private stream pointer
pub(crate) stream: *mut AVStream, pub(crate) stream: *mut AVStream,