feat: parse language to streaminfo
This commit is contained in:
parent
ad0919b2a4
commit
07a2c72888
12
src/demux.rs
12
src/demux.rs
@ -150,6 +150,12 @@ impl Demuxer {
|
|||||||
while n_stream < (*self.ctx).nb_streams as usize {
|
while n_stream < (*self.ctx).nb_streams as usize {
|
||||||
let stream = *(*self.ctx).streams.add(n_stream);
|
let stream = *(*self.ctx).streams.add(n_stream);
|
||||||
n_stream += 1;
|
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 {
|
match (*(*stream).codecpar).codec_type {
|
||||||
AVMediaType::AVMEDIA_TYPE_VIDEO => {
|
AVMediaType::AVMEDIA_TYPE_VIDEO => {
|
||||||
streams.push(StreamInfo {
|
streams.push(StreamInfo {
|
||||||
@ -162,6 +168,7 @@ impl Demuxer {
|
|||||||
fps: av_q2d((*stream).avg_frame_rate) as f32,
|
fps: av_q2d((*stream).avg_frame_rate) as f32,
|
||||||
format: (*(*stream).codecpar).format as isize,
|
format: (*(*stream).codecpar).format as isize,
|
||||||
sample_rate: 0,
|
sample_rate: 0,
|
||||||
|
language,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
AVMediaType::AVMEDIA_TYPE_AUDIO => {
|
AVMediaType::AVMEDIA_TYPE_AUDIO => {
|
||||||
@ -175,6 +182,7 @@ impl Demuxer {
|
|||||||
fps: 0.0,
|
fps: 0.0,
|
||||||
format: (*(*stream).codecpar).format as isize,
|
format: (*(*stream).codecpar).format as isize,
|
||||||
sample_rate: (*(*stream).codecpar).sample_rate as usize,
|
sample_rate: (*(*stream).codecpar).sample_rate as usize,
|
||||||
|
language,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
AVMediaType::AVMEDIA_TYPE_SUBTITLE => {
|
AVMediaType::AVMEDIA_TYPE_SUBTITLE => {
|
||||||
@ -188,6 +196,7 @@ impl Demuxer {
|
|||||||
fps: 0.0,
|
fps: 0.0,
|
||||||
format: 0,
|
format: 0,
|
||||||
sample_rate: 0,
|
sample_rate: 0,
|
||||||
|
language,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
AVMediaType::AVMEDIA_TYPE_ATTACHMENT => {}
|
AVMediaType::AVMEDIA_TYPE_ATTACHMENT => {}
|
||||||
@ -239,10 +248,11 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[ignore]
|
||||||
fn test_stream_groups() -> Result<()> {
|
fn test_stream_groups() -> Result<()> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut demux =
|
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()?;
|
let probe = demux.probe_input()?;
|
||||||
assert_eq!(1, probe.streams.len());
|
assert_eq!(1, probe.streams.len());
|
||||||
assert_eq!(1, probe.groups.len());
|
assert_eq!(1, probe.groups.len());
|
||||||
|
@ -103,16 +103,26 @@ impl Display for StreamType {
|
|||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct StreamInfo {
|
pub struct StreamInfo {
|
||||||
|
/// Stream index
|
||||||
pub index: usize,
|
pub index: usize,
|
||||||
|
/// Stream type video/audio/subtitle
|
||||||
pub stream_type: StreamType,
|
pub stream_type: StreamType,
|
||||||
|
/// Stream codec
|
||||||
pub codec: isize,
|
pub codec: isize,
|
||||||
|
/// Pixel format / Sample format
|
||||||
pub format: isize,
|
pub format: isize,
|
||||||
|
|
||||||
|
/// Video width
|
||||||
pub width: usize,
|
pub width: usize,
|
||||||
|
/// Video height
|
||||||
pub height: usize,
|
pub height: usize,
|
||||||
|
/// Video FPS
|
||||||
pub fps: f32,
|
pub fps: f32,
|
||||||
|
|
||||||
|
/// Audio sample rate
|
||||||
pub sample_rate: usize,
|
pub sample_rate: usize,
|
||||||
|
/// Subtitle / Audio language
|
||||||
|
pub language: String,
|
||||||
|
|
||||||
// private stream pointer
|
// private stream pointer
|
||||||
pub(crate) stream: *mut AVStream,
|
pub(crate) stream: *mut AVStream,
|
||||||
@ -147,7 +157,7 @@ impl Display for StreamInfo {
|
|||||||
),
|
),
|
||||||
StreamType::Audio => write!(
|
StreamType::Audio => write!(
|
||||||
f,
|
f,
|
||||||
"{} #{}: codec={},format={},sample_rate={}",
|
"{} #{}: codec={},format={},sample_rate={},lang={}",
|
||||||
self.stream_type,
|
self.stream_type,
|
||||||
self.index,
|
self.index,
|
||||||
codec_name,
|
codec_name,
|
||||||
@ -157,11 +167,12 @@ impl Display for StreamInfo {
|
|||||||
)))
|
)))
|
||||||
},
|
},
|
||||||
self.sample_rate,
|
self.sample_rate,
|
||||||
|
self.language,
|
||||||
),
|
),
|
||||||
StreamType::Subtitle => write!(
|
StreamType::Subtitle => write!(
|
||||||
f,
|
f,
|
||||||
"{} #{}: codec={}",
|
"{} #{}: codec={},lang={}",
|
||||||
self.stream_type, self.index, codec_name
|
self.stream_type, self.index, codec_name, self.language
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ impl Transcoder {
|
|||||||
if let Some(enc) = self.encoders.get_mut(&src_index) {
|
if let Some(enc) = self.encoders.get_mut(&src_index) {
|
||||||
for mut frame in self.decoder.decode_pkt(pkt)? {
|
for mut frame in self.decoder.decode_pkt(pkt)? {
|
||||||
// scale video frame before sending to encoder
|
// 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 enc_ctx = enc.codec_context();
|
||||||
let new_frame = sws.process_frame(
|
let new_frame = sws.process_frame(
|
||||||
frame,
|
frame,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user