feat: parse language to streaminfo

This commit is contained in:
kieran 2024-11-12 10:58:14 +00:00
parent ad0919b2a4
commit 07a2c72888
No known key found for this signature in database
GPG Key ID: DE71CEB3925BE941
3 changed files with 27 additions and 6 deletions

View File

@ -150,6 +150,12 @@ impl Demuxer {
while n_stream < (*self.ctx).nb_streams as usize {
let stream = *(*self.ctx).streams.add(n_stream);
n_stream += 1;
let lang = av_dict_get((*stream).metadata, cstr!("language"), ptr::null_mut(), 0);
let language = if lang.is_null() {
"".to_string()
} else {
rstr!((*lang).value).to_string()
};
match (*(*stream).codecpar).codec_type {
AVMediaType::AVMEDIA_TYPE_VIDEO => {
streams.push(StreamInfo {
@ -162,6 +168,7 @@ impl Demuxer {
fps: av_q2d((*stream).avg_frame_rate) as f32,
format: (*(*stream).codecpar).format as isize,
sample_rate: 0,
language,
});
}
AVMediaType::AVMEDIA_TYPE_AUDIO => {
@ -175,6 +182,7 @@ impl Demuxer {
fps: 0.0,
format: (*(*stream).codecpar).format as isize,
sample_rate: (*(*stream).codecpar).sample_rate as usize,
language,
});
}
AVMediaType::AVMEDIA_TYPE_SUBTITLE => {
@ -188,6 +196,7 @@ impl Demuxer {
fps: 0.0,
format: 0,
sample_rate: 0,
language,
});
}
AVMediaType::AVMEDIA_TYPE_ATTACHMENT => {}
@ -239,10 +248,11 @@ mod tests {
use super::*;
#[test]
#[ignore]
fn test_stream_groups() -> Result<()> {
unsafe {
let mut demux =
Demuxer::new("/core/Camera/Syncthing/Camera S22/Camera/20241104_121607.heic")?;
Demuxer::new("/core/[SubsPlease] Kinoko Inu - 06 (1080p) [FECF68AF].mkv")?;
let probe = demux.probe_input()?;
assert_eq!(1, probe.streams.len());
assert_eq!(1, probe.groups.len());

View File

@ -103,16 +103,26 @@ impl Display for StreamType {
#[derive(Clone, Debug, PartialEq)]
pub struct StreamInfo {
/// Stream index
pub index: usize,
/// Stream type video/audio/subtitle
pub stream_type: StreamType,
/// Stream codec
pub codec: isize,
/// Pixel format / Sample format
pub format: isize,
/// Video width
pub width: usize,
/// Video height
pub height: usize,
/// Video FPS
pub fps: f32,
/// Audio sample rate
pub sample_rate: usize,
/// Subtitle / Audio language
pub language: String,
// private stream pointer
pub(crate) stream: *mut AVStream,
@ -147,7 +157,7 @@ impl Display for StreamInfo {
),
StreamType::Audio => write!(
f,
"{} #{}: codec={},format={},sample_rate={}",
"{} #{}: codec={},format={},sample_rate={},lang={}",
self.stream_type,
self.index,
codec_name,
@ -157,11 +167,12 @@ impl Display for StreamInfo {
)))
},
self.sample_rate,
self.language,
),
StreamType::Subtitle => write!(
f,
"{} #{}: codec={}",
self.stream_type, self.index, codec_name
"{} #{}: codec={},lang={}",
self.stream_type, self.index, codec_name, self.language
),
}
}

View File

@ -111,7 +111,7 @@ impl Transcoder {
if let Some(enc) = self.encoders.get_mut(&src_index) {
for mut frame in self.decoder.decode_pkt(pkt)? {
// scale video frame before sending to encoder
let mut frame = if let Some(sws) = self.scalers.get_mut(&src_index) {
let frame = if let Some(sws) = self.scalers.get_mut(&src_index) {
let enc_ctx = enc.codec_context();
let new_frame = sws.process_frame(
frame,