1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
extern crate ffmpeg_next as ffmpeg;
use ffmpeg::{
codec::Parameters as AvCodecParameters,
Error as AvError,
Rational as AvRational,
};
use super::{
io::Reader,
Error,
};
type Result<T> = std::result::Result<T, Error>;
/// Holds transferable stream information. This can be used to duplicate
/// stream settings for the purpose of transmuxing or transcoding.
#[derive(Clone)]
pub struct StreamInfo {
pub index: usize,
codec_parameters: AvCodecParameters,
time_base: AvRational,
}
impl StreamInfo {
/// Fetch stream information from a reader by stream index.
///
/// # Arguments
///
/// * `reader` - Reader to find stream information from.
/// * `stream_index` - Index of stream in reader.
pub(crate) fn from_reader(
reader: &Reader,
stream_index: usize,
) -> Result<Self> {
let stream = reader
.input
.stream(stream_index)
.ok_or(AvError::StreamNotFound)?;
Ok(Self {
index: stream_index,
codec_parameters: stream.parameters().clone(),
time_base: stream.time_base(),
})
}
/// Turn information back into parts for usage.
///
/// Note: Consumes stream information object.
///
/// # Returns
///
/// A tuple consisting of:
/// * The stream index.
/// * Codec parameters.
/// * Original stream time base.
pub(crate) fn into_parts(self) -> (
usize,
AvCodecParameters,
AvRational
) {
(
self.index,
self.codec_parameters,
self.time_base
)
}
}