pub struct Stream<'a> { /* private fields */ }Implementations§
Source§impl<'a> Stream<'a>
impl<'a> Stream<'a>
pub fn id(&self) -> i32
Sourcepub fn codec(&self) -> Context
pub fn codec(&self) -> Context
Examples found in repository?
examples/transcode-audio.rs (line 73)
63fn transcoder<P: AsRef<Path>>(
64 ictx: &mut format::context::Input,
65 octx: &mut format::context::Output,
66 path: &P,
67 filter_spec: &str,
68) -> Result<Transcoder, ffmpeg::Error> {
69 let input = ictx
70 .streams()
71 .best(media::Type::Audio)
72 .expect("could not find best audio stream");
73 let mut decoder = input.codec().decoder().audio()?;
74 let codec = ffmpeg::encoder::find(octx.format().codec(path, media::Type::Audio))
75 .expect("failed to find encoder")
76 .audio()?;
77 let global = octx
78 .format()
79 .flags()
80 .contains(ffmpeg::format::flag::Flags::GLOBAL_HEADER);
81
82 decoder.set_parameters(input.parameters())?;
83
84 let mut output = octx.add_stream(codec)?;
85 let mut encoder = output.codec().encoder().audio()?;
86
87 let channel_layout = codec
88 .channel_layouts()
89 .map(|cls| cls.best(decoder.channel_layout().channels()))
90 .unwrap_or(ffmpeg::channel_layout::ChannelLayout::STEREO);
91
92 if global {
93 encoder.set_flags(ffmpeg::codec::flag::Flags::GLOBAL_HEADER);
94 }
95
96 encoder.set_rate(decoder.rate() as i32);
97 encoder.set_channel_layout(channel_layout);
98 encoder.set_channels(channel_layout.channels());
99 encoder.set_format(
100 codec
101 .formats()
102 .expect("unknown supported formats")
103 .next()
104 .unwrap(),
105 );
106 encoder.set_bit_rate(decoder.bit_rate());
107 encoder.set_max_bit_rate(decoder.max_bit_rate());
108
109 encoder.set_time_base((1, decoder.rate() as i32));
110 output.set_time_base((1, decoder.rate() as i32));
111
112 let encoder = encoder.open_as(codec)?;
113 output.set_parameters(&encoder);
114
115 let filter = filter(filter_spec, &decoder, &encoder)?;
116
117 Ok(Transcoder {
118 stream: input.index(),
119 filter: filter,
120 decoder: decoder,
121 encoder: encoder,
122 })
123}More examples
examples/metadata.rs (line 45)
5fn main() {
6 ffmpeg::init().unwrap();
7
8 match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9 Ok(context) => {
10 for (k, v) in context.metadata().iter() {
11 println!("{}: {}", k, v);
12 }
13
14 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15 println!("Best video stream index: {}", stream.index());
16 }
17
18 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19 println!("Best audio stream index: {}", stream.index());
20 }
21
22 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23 println!("Best subtitle stream index: {}", stream.index());
24 }
25
26 println!(
27 "duration (seconds): {:.2}",
28 context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29 );
30
31 for stream in context.streams() {
32 println!("stream index {}:", stream.index());
33 println!("\ttime_base: {}", stream.time_base());
34 println!("\tstart_time: {}", stream.start_time());
35 println!("\tduration (stream timebase): {}", stream.duration());
36 println!(
37 "\tduration (seconds): {:.2}",
38 stream.duration() as f64 * f64::from(stream.time_base())
39 );
40 println!("\tframes: {}", stream.frames());
41 println!("\tdisposition: {:?}", stream.disposition());
42 println!("\tdiscard: {:?}", stream.discard());
43 println!("\trate: {}", stream.rate());
44
45 let codec = stream.codec();
46 println!("\tmedium: {:?}", codec.medium());
47 println!("\tid: {:?}", codec.id());
48
49 if codec.medium() == ffmpeg::media::Type::Video {
50 if let Ok(video) = codec.decoder().video() {
51 println!("\tbit_rate: {}", video.bit_rate());
52 println!("\tmax_rate: {}", video.max_bit_rate());
53 println!("\tdelay: {}", video.delay());
54 println!("\tvideo.width: {}", video.width());
55 println!("\tvideo.height: {}", video.height());
56 println!("\tvideo.format: {:?}", video.format());
57 println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58 println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59 println!("\tvideo.color_space: {:?}", video.color_space());
60 println!("\tvideo.color_range: {:?}", video.color_range());
61 println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62 println!(
63 "\tvideo.color_transfer_characteristic: {:?}",
64 video.color_transfer_characteristic()
65 );
66 println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67 println!("\tvideo.references: {}", video.references());
68 println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69 }
70 } else if codec.medium() == ffmpeg::media::Type::Audio {
71 if let Ok(audio) = codec.decoder().audio() {
72 println!("\tbit_rate: {}", audio.bit_rate());
73 println!("\tmax_rate: {}", audio.max_bit_rate());
74 println!("\tdelay: {}", audio.delay());
75 println!("\taudio.rate: {}", audio.rate());
76 println!("\taudio.channels: {}", audio.channels());
77 println!("\taudio.format: {:?}", audio.format());
78 println!("\taudio.frames: {}", audio.frames());
79 println!("\taudio.align: {}", audio.align());
80 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81 println!("\taudio.frame_start: {:?}", audio.frame_start());
82 }
83 }
84 }
85 }
86
87 Err(error) => println!("error: {}", error),
88 }
89}Sourcepub fn parameters(&self) -> Parameters
pub fn parameters(&self) -> Parameters
Examples found in repository?
examples/transcode-audio.rs (line 82)
63fn transcoder<P: AsRef<Path>>(
64 ictx: &mut format::context::Input,
65 octx: &mut format::context::Output,
66 path: &P,
67 filter_spec: &str,
68) -> Result<Transcoder, ffmpeg::Error> {
69 let input = ictx
70 .streams()
71 .best(media::Type::Audio)
72 .expect("could not find best audio stream");
73 let mut decoder = input.codec().decoder().audio()?;
74 let codec = ffmpeg::encoder::find(octx.format().codec(path, media::Type::Audio))
75 .expect("failed to find encoder")
76 .audio()?;
77 let global = octx
78 .format()
79 .flags()
80 .contains(ffmpeg::format::flag::Flags::GLOBAL_HEADER);
81
82 decoder.set_parameters(input.parameters())?;
83
84 let mut output = octx.add_stream(codec)?;
85 let mut encoder = output.codec().encoder().audio()?;
86
87 let channel_layout = codec
88 .channel_layouts()
89 .map(|cls| cls.best(decoder.channel_layout().channels()))
90 .unwrap_or(ffmpeg::channel_layout::ChannelLayout::STEREO);
91
92 if global {
93 encoder.set_flags(ffmpeg::codec::flag::Flags::GLOBAL_HEADER);
94 }
95
96 encoder.set_rate(decoder.rate() as i32);
97 encoder.set_channel_layout(channel_layout);
98 encoder.set_channels(channel_layout.channels());
99 encoder.set_format(
100 codec
101 .formats()
102 .expect("unknown supported formats")
103 .next()
104 .unwrap(),
105 );
106 encoder.set_bit_rate(decoder.bit_rate());
107 encoder.set_max_bit_rate(decoder.max_bit_rate());
108
109 encoder.set_time_base((1, decoder.rate() as i32));
110 output.set_time_base((1, decoder.rate() as i32));
111
112 let encoder = encoder.open_as(codec)?;
113 output.set_parameters(&encoder);
114
115 let filter = filter(filter_spec, &decoder, &encoder)?;
116
117 Ok(Transcoder {
118 stream: input.index(),
119 filter: filter,
120 decoder: decoder,
121 encoder: encoder,
122 })
123}Sourcepub fn index(&self) -> usize
pub fn index(&self) -> usize
Examples found in repository?
examples/transcode-audio.rs (line 118)
63fn transcoder<P: AsRef<Path>>(
64 ictx: &mut format::context::Input,
65 octx: &mut format::context::Output,
66 path: &P,
67 filter_spec: &str,
68) -> Result<Transcoder, ffmpeg::Error> {
69 let input = ictx
70 .streams()
71 .best(media::Type::Audio)
72 .expect("could not find best audio stream");
73 let mut decoder = input.codec().decoder().audio()?;
74 let codec = ffmpeg::encoder::find(octx.format().codec(path, media::Type::Audio))
75 .expect("failed to find encoder")
76 .audio()?;
77 let global = octx
78 .format()
79 .flags()
80 .contains(ffmpeg::format::flag::Flags::GLOBAL_HEADER);
81
82 decoder.set_parameters(input.parameters())?;
83
84 let mut output = octx.add_stream(codec)?;
85 let mut encoder = output.codec().encoder().audio()?;
86
87 let channel_layout = codec
88 .channel_layouts()
89 .map(|cls| cls.best(decoder.channel_layout().channels()))
90 .unwrap_or(ffmpeg::channel_layout::ChannelLayout::STEREO);
91
92 if global {
93 encoder.set_flags(ffmpeg::codec::flag::Flags::GLOBAL_HEADER);
94 }
95
96 encoder.set_rate(decoder.rate() as i32);
97 encoder.set_channel_layout(channel_layout);
98 encoder.set_channels(channel_layout.channels());
99 encoder.set_format(
100 codec
101 .formats()
102 .expect("unknown supported formats")
103 .next()
104 .unwrap(),
105 );
106 encoder.set_bit_rate(decoder.bit_rate());
107 encoder.set_max_bit_rate(decoder.max_bit_rate());
108
109 encoder.set_time_base((1, decoder.rate() as i32));
110 output.set_time_base((1, decoder.rate() as i32));
111
112 let encoder = encoder.open_as(codec)?;
113 output.set_parameters(&encoder);
114
115 let filter = filter(filter_spec, &decoder, &encoder)?;
116
117 Ok(Transcoder {
118 stream: input.index(),
119 filter: filter,
120 decoder: decoder,
121 encoder: encoder,
122 })
123}
124
125// Transcode the `best` audio stream of the input file into a the output file while applying a
126// given filter. If no filter was specified the stream gets copied (`anull` filter).
127//
128// Example 1: Transcode *.mp3 file to *.wmv while speeding it up
129// transcode-audio in.mp3 out.wmv "atempo=1.2"
130//
131// Example 2: Overlay an audio file
132// transcode-audio in.mp3 out.mp3 "amovie=overlay.mp3 [ov]; [in][ov] amerge [out]"
133//
134// Example 3: Seek to a specified position (in seconds)
135// transcode-audio in.mp3 out.mp3 anull 30
136fn main() {
137 ffmpeg::init().unwrap();
138
139 let input = env::args().nth(1).expect("missing input");
140 let output = env::args().nth(2).expect("missing output");
141 let filter = env::args().nth(3).unwrap_or_else(|| "anull".to_owned());
142 let seek = env::args().nth(4).and_then(|s| s.parse::<i64>().ok());
143
144 let mut ictx = format::input(&input).unwrap();
145 let mut octx = format::output(&output).unwrap();
146 let mut transcoder = transcoder(&mut ictx, &mut octx, &output, &filter).unwrap();
147
148 if let Some(position) = seek {
149 // If the position was given in seconds, rescale it to ffmpegs base timebase.
150 let position = position.rescale((1, 1), rescale::TIME_BASE);
151 // If this seek was embedded in the transcoding loop, a call of `flush()`
152 // for every opened buffer after the successful seek would be advisable.
153 ictx.seek(position, ..position).unwrap();
154 }
155
156 octx.set_metadata(ictx.metadata().to_owned());
157 octx.write_header().unwrap();
158
159 let in_time_base = transcoder.decoder.time_base();
160 let out_time_base = octx.stream(0).unwrap().time_base();
161
162 let mut decoded = frame::Audio::empty();
163 let mut encoded = ffmpeg::Packet::empty();
164
165 for (stream, mut packet) in ictx.packets() {
166 if stream.index() == transcoder.stream {
167 packet.rescale_ts(stream.time_base(), in_time_base);
168
169 if let Ok(true) = transcoder.decoder.decode(&packet, &mut decoded) {
170 let timestamp = decoded.timestamp();
171 decoded.set_pts(timestamp);
172
173 transcoder
174 .filter
175 .get("in")
176 .unwrap()
177 .source()
178 .add(&decoded)
179 .unwrap();
180
181 while let Ok(..) = transcoder
182 .filter
183 .get("out")
184 .unwrap()
185 .sink()
186 .frame(&mut decoded)
187 {
188 if let Ok(true) = transcoder.encoder.encode(&decoded, &mut encoded) {
189 encoded.set_stream(0);
190 encoded.rescale_ts(in_time_base, out_time_base);
191 encoded.write_interleaved(&mut octx).unwrap();
192 }
193 }
194 }
195 }
196 }
197
198 transcoder
199 .filter
200 .get("in")
201 .unwrap()
202 .source()
203 .flush()
204 .unwrap();
205
206 while let Ok(..) = transcoder
207 .filter
208 .get("out")
209 .unwrap()
210 .sink()
211 .frame(&mut decoded)
212 {
213 if let Ok(true) = transcoder.encoder.encode(&decoded, &mut encoded) {
214 encoded.set_stream(0);
215 encoded.rescale_ts(in_time_base, out_time_base);
216 encoded.write_interleaved(&mut octx).unwrap();
217 }
218 }
219
220 if let Ok(true) = transcoder.encoder.flush(&mut encoded) {
221 encoded.set_stream(0);
222 encoded.rescale_ts(in_time_base, out_time_base);
223 encoded.write_interleaved(&mut octx).unwrap();
224 }
225
226 octx.write_trailer().unwrap();
227}More examples
examples/metadata.rs (line 15)
5fn main() {
6 ffmpeg::init().unwrap();
7
8 match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9 Ok(context) => {
10 for (k, v) in context.metadata().iter() {
11 println!("{}: {}", k, v);
12 }
13
14 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15 println!("Best video stream index: {}", stream.index());
16 }
17
18 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19 println!("Best audio stream index: {}", stream.index());
20 }
21
22 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23 println!("Best subtitle stream index: {}", stream.index());
24 }
25
26 println!(
27 "duration (seconds): {:.2}",
28 context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29 );
30
31 for stream in context.streams() {
32 println!("stream index {}:", stream.index());
33 println!("\ttime_base: {}", stream.time_base());
34 println!("\tstart_time: {}", stream.start_time());
35 println!("\tduration (stream timebase): {}", stream.duration());
36 println!(
37 "\tduration (seconds): {:.2}",
38 stream.duration() as f64 * f64::from(stream.time_base())
39 );
40 println!("\tframes: {}", stream.frames());
41 println!("\tdisposition: {:?}", stream.disposition());
42 println!("\tdiscard: {:?}", stream.discard());
43 println!("\trate: {}", stream.rate());
44
45 let codec = stream.codec();
46 println!("\tmedium: {:?}", codec.medium());
47 println!("\tid: {:?}", codec.id());
48
49 if codec.medium() == ffmpeg::media::Type::Video {
50 if let Ok(video) = codec.decoder().video() {
51 println!("\tbit_rate: {}", video.bit_rate());
52 println!("\tmax_rate: {}", video.max_bit_rate());
53 println!("\tdelay: {}", video.delay());
54 println!("\tvideo.width: {}", video.width());
55 println!("\tvideo.height: {}", video.height());
56 println!("\tvideo.format: {:?}", video.format());
57 println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58 println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59 println!("\tvideo.color_space: {:?}", video.color_space());
60 println!("\tvideo.color_range: {:?}", video.color_range());
61 println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62 println!(
63 "\tvideo.color_transfer_characteristic: {:?}",
64 video.color_transfer_characteristic()
65 );
66 println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67 println!("\tvideo.references: {}", video.references());
68 println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69 }
70 } else if codec.medium() == ffmpeg::media::Type::Audio {
71 if let Ok(audio) = codec.decoder().audio() {
72 println!("\tbit_rate: {}", audio.bit_rate());
73 println!("\tmax_rate: {}", audio.max_bit_rate());
74 println!("\tdelay: {}", audio.delay());
75 println!("\taudio.rate: {}", audio.rate());
76 println!("\taudio.channels: {}", audio.channels());
77 println!("\taudio.format: {:?}", audio.format());
78 println!("\taudio.frames: {}", audio.frames());
79 println!("\taudio.align: {}", audio.align());
80 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81 println!("\taudio.frame_start: {:?}", audio.frame_start());
82 }
83 }
84 }
85 }
86
87 Err(error) => println!("error: {}", error),
88 }
89}Sourcepub fn time_base(&self) -> Rational
pub fn time_base(&self) -> Rational
Examples found in repository?
examples/transcode-audio.rs (line 160)
136fn main() {
137 ffmpeg::init().unwrap();
138
139 let input = env::args().nth(1).expect("missing input");
140 let output = env::args().nth(2).expect("missing output");
141 let filter = env::args().nth(3).unwrap_or_else(|| "anull".to_owned());
142 let seek = env::args().nth(4).and_then(|s| s.parse::<i64>().ok());
143
144 let mut ictx = format::input(&input).unwrap();
145 let mut octx = format::output(&output).unwrap();
146 let mut transcoder = transcoder(&mut ictx, &mut octx, &output, &filter).unwrap();
147
148 if let Some(position) = seek {
149 // If the position was given in seconds, rescale it to ffmpegs base timebase.
150 let position = position.rescale((1, 1), rescale::TIME_BASE);
151 // If this seek was embedded in the transcoding loop, a call of `flush()`
152 // for every opened buffer after the successful seek would be advisable.
153 ictx.seek(position, ..position).unwrap();
154 }
155
156 octx.set_metadata(ictx.metadata().to_owned());
157 octx.write_header().unwrap();
158
159 let in_time_base = transcoder.decoder.time_base();
160 let out_time_base = octx.stream(0).unwrap().time_base();
161
162 let mut decoded = frame::Audio::empty();
163 let mut encoded = ffmpeg::Packet::empty();
164
165 for (stream, mut packet) in ictx.packets() {
166 if stream.index() == transcoder.stream {
167 packet.rescale_ts(stream.time_base(), in_time_base);
168
169 if let Ok(true) = transcoder.decoder.decode(&packet, &mut decoded) {
170 let timestamp = decoded.timestamp();
171 decoded.set_pts(timestamp);
172
173 transcoder
174 .filter
175 .get("in")
176 .unwrap()
177 .source()
178 .add(&decoded)
179 .unwrap();
180
181 while let Ok(..) = transcoder
182 .filter
183 .get("out")
184 .unwrap()
185 .sink()
186 .frame(&mut decoded)
187 {
188 if let Ok(true) = transcoder.encoder.encode(&decoded, &mut encoded) {
189 encoded.set_stream(0);
190 encoded.rescale_ts(in_time_base, out_time_base);
191 encoded.write_interleaved(&mut octx).unwrap();
192 }
193 }
194 }
195 }
196 }
197
198 transcoder
199 .filter
200 .get("in")
201 .unwrap()
202 .source()
203 .flush()
204 .unwrap();
205
206 while let Ok(..) = transcoder
207 .filter
208 .get("out")
209 .unwrap()
210 .sink()
211 .frame(&mut decoded)
212 {
213 if let Ok(true) = transcoder.encoder.encode(&decoded, &mut encoded) {
214 encoded.set_stream(0);
215 encoded.rescale_ts(in_time_base, out_time_base);
216 encoded.write_interleaved(&mut octx).unwrap();
217 }
218 }
219
220 if let Ok(true) = transcoder.encoder.flush(&mut encoded) {
221 encoded.set_stream(0);
222 encoded.rescale_ts(in_time_base, out_time_base);
223 encoded.write_interleaved(&mut octx).unwrap();
224 }
225
226 octx.write_trailer().unwrap();
227}More examples
examples/metadata.rs (line 33)
5fn main() {
6 ffmpeg::init().unwrap();
7
8 match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9 Ok(context) => {
10 for (k, v) in context.metadata().iter() {
11 println!("{}: {}", k, v);
12 }
13
14 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15 println!("Best video stream index: {}", stream.index());
16 }
17
18 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19 println!("Best audio stream index: {}", stream.index());
20 }
21
22 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23 println!("Best subtitle stream index: {}", stream.index());
24 }
25
26 println!(
27 "duration (seconds): {:.2}",
28 context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29 );
30
31 for stream in context.streams() {
32 println!("stream index {}:", stream.index());
33 println!("\ttime_base: {}", stream.time_base());
34 println!("\tstart_time: {}", stream.start_time());
35 println!("\tduration (stream timebase): {}", stream.duration());
36 println!(
37 "\tduration (seconds): {:.2}",
38 stream.duration() as f64 * f64::from(stream.time_base())
39 );
40 println!("\tframes: {}", stream.frames());
41 println!("\tdisposition: {:?}", stream.disposition());
42 println!("\tdiscard: {:?}", stream.discard());
43 println!("\trate: {}", stream.rate());
44
45 let codec = stream.codec();
46 println!("\tmedium: {:?}", codec.medium());
47 println!("\tid: {:?}", codec.id());
48
49 if codec.medium() == ffmpeg::media::Type::Video {
50 if let Ok(video) = codec.decoder().video() {
51 println!("\tbit_rate: {}", video.bit_rate());
52 println!("\tmax_rate: {}", video.max_bit_rate());
53 println!("\tdelay: {}", video.delay());
54 println!("\tvideo.width: {}", video.width());
55 println!("\tvideo.height: {}", video.height());
56 println!("\tvideo.format: {:?}", video.format());
57 println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58 println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59 println!("\tvideo.color_space: {:?}", video.color_space());
60 println!("\tvideo.color_range: {:?}", video.color_range());
61 println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62 println!(
63 "\tvideo.color_transfer_characteristic: {:?}",
64 video.color_transfer_characteristic()
65 );
66 println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67 println!("\tvideo.references: {}", video.references());
68 println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69 }
70 } else if codec.medium() == ffmpeg::media::Type::Audio {
71 if let Ok(audio) = codec.decoder().audio() {
72 println!("\tbit_rate: {}", audio.bit_rate());
73 println!("\tmax_rate: {}", audio.max_bit_rate());
74 println!("\tdelay: {}", audio.delay());
75 println!("\taudio.rate: {}", audio.rate());
76 println!("\taudio.channels: {}", audio.channels());
77 println!("\taudio.format: {:?}", audio.format());
78 println!("\taudio.frames: {}", audio.frames());
79 println!("\taudio.align: {}", audio.align());
80 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81 println!("\taudio.frame_start: {:?}", audio.frame_start());
82 }
83 }
84 }
85 }
86
87 Err(error) => println!("error: {}", error),
88 }
89}Sourcepub fn start_time(&self) -> i64
pub fn start_time(&self) -> i64
Examples found in repository?
examples/metadata.rs (line 34)
5fn main() {
6 ffmpeg::init().unwrap();
7
8 match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9 Ok(context) => {
10 for (k, v) in context.metadata().iter() {
11 println!("{}: {}", k, v);
12 }
13
14 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15 println!("Best video stream index: {}", stream.index());
16 }
17
18 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19 println!("Best audio stream index: {}", stream.index());
20 }
21
22 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23 println!("Best subtitle stream index: {}", stream.index());
24 }
25
26 println!(
27 "duration (seconds): {:.2}",
28 context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29 );
30
31 for stream in context.streams() {
32 println!("stream index {}:", stream.index());
33 println!("\ttime_base: {}", stream.time_base());
34 println!("\tstart_time: {}", stream.start_time());
35 println!("\tduration (stream timebase): {}", stream.duration());
36 println!(
37 "\tduration (seconds): {:.2}",
38 stream.duration() as f64 * f64::from(stream.time_base())
39 );
40 println!("\tframes: {}", stream.frames());
41 println!("\tdisposition: {:?}", stream.disposition());
42 println!("\tdiscard: {:?}", stream.discard());
43 println!("\trate: {}", stream.rate());
44
45 let codec = stream.codec();
46 println!("\tmedium: {:?}", codec.medium());
47 println!("\tid: {:?}", codec.id());
48
49 if codec.medium() == ffmpeg::media::Type::Video {
50 if let Ok(video) = codec.decoder().video() {
51 println!("\tbit_rate: {}", video.bit_rate());
52 println!("\tmax_rate: {}", video.max_bit_rate());
53 println!("\tdelay: {}", video.delay());
54 println!("\tvideo.width: {}", video.width());
55 println!("\tvideo.height: {}", video.height());
56 println!("\tvideo.format: {:?}", video.format());
57 println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58 println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59 println!("\tvideo.color_space: {:?}", video.color_space());
60 println!("\tvideo.color_range: {:?}", video.color_range());
61 println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62 println!(
63 "\tvideo.color_transfer_characteristic: {:?}",
64 video.color_transfer_characteristic()
65 );
66 println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67 println!("\tvideo.references: {}", video.references());
68 println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69 }
70 } else if codec.medium() == ffmpeg::media::Type::Audio {
71 if let Ok(audio) = codec.decoder().audio() {
72 println!("\tbit_rate: {}", audio.bit_rate());
73 println!("\tmax_rate: {}", audio.max_bit_rate());
74 println!("\tdelay: {}", audio.delay());
75 println!("\taudio.rate: {}", audio.rate());
76 println!("\taudio.channels: {}", audio.channels());
77 println!("\taudio.format: {:?}", audio.format());
78 println!("\taudio.frames: {}", audio.frames());
79 println!("\taudio.align: {}", audio.align());
80 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81 println!("\taudio.frame_start: {:?}", audio.frame_start());
82 }
83 }
84 }
85 }
86
87 Err(error) => println!("error: {}", error),
88 }
89}Sourcepub fn duration(&self) -> i64
pub fn duration(&self) -> i64
Examples found in repository?
examples/metadata.rs (line 35)
5fn main() {
6 ffmpeg::init().unwrap();
7
8 match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9 Ok(context) => {
10 for (k, v) in context.metadata().iter() {
11 println!("{}: {}", k, v);
12 }
13
14 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15 println!("Best video stream index: {}", stream.index());
16 }
17
18 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19 println!("Best audio stream index: {}", stream.index());
20 }
21
22 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23 println!("Best subtitle stream index: {}", stream.index());
24 }
25
26 println!(
27 "duration (seconds): {:.2}",
28 context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29 );
30
31 for stream in context.streams() {
32 println!("stream index {}:", stream.index());
33 println!("\ttime_base: {}", stream.time_base());
34 println!("\tstart_time: {}", stream.start_time());
35 println!("\tduration (stream timebase): {}", stream.duration());
36 println!(
37 "\tduration (seconds): {:.2}",
38 stream.duration() as f64 * f64::from(stream.time_base())
39 );
40 println!("\tframes: {}", stream.frames());
41 println!("\tdisposition: {:?}", stream.disposition());
42 println!("\tdiscard: {:?}", stream.discard());
43 println!("\trate: {}", stream.rate());
44
45 let codec = stream.codec();
46 println!("\tmedium: {:?}", codec.medium());
47 println!("\tid: {:?}", codec.id());
48
49 if codec.medium() == ffmpeg::media::Type::Video {
50 if let Ok(video) = codec.decoder().video() {
51 println!("\tbit_rate: {}", video.bit_rate());
52 println!("\tmax_rate: {}", video.max_bit_rate());
53 println!("\tdelay: {}", video.delay());
54 println!("\tvideo.width: {}", video.width());
55 println!("\tvideo.height: {}", video.height());
56 println!("\tvideo.format: {:?}", video.format());
57 println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58 println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59 println!("\tvideo.color_space: {:?}", video.color_space());
60 println!("\tvideo.color_range: {:?}", video.color_range());
61 println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62 println!(
63 "\tvideo.color_transfer_characteristic: {:?}",
64 video.color_transfer_characteristic()
65 );
66 println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67 println!("\tvideo.references: {}", video.references());
68 println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69 }
70 } else if codec.medium() == ffmpeg::media::Type::Audio {
71 if let Ok(audio) = codec.decoder().audio() {
72 println!("\tbit_rate: {}", audio.bit_rate());
73 println!("\tmax_rate: {}", audio.max_bit_rate());
74 println!("\tdelay: {}", audio.delay());
75 println!("\taudio.rate: {}", audio.rate());
76 println!("\taudio.channels: {}", audio.channels());
77 println!("\taudio.format: {:?}", audio.format());
78 println!("\taudio.frames: {}", audio.frames());
79 println!("\taudio.align: {}", audio.align());
80 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81 println!("\taudio.frame_start: {:?}", audio.frame_start());
82 }
83 }
84 }
85 }
86
87 Err(error) => println!("error: {}", error),
88 }
89}Sourcepub fn frames(&self) -> i64
pub fn frames(&self) -> i64
Examples found in repository?
examples/metadata.rs (line 40)
5fn main() {
6 ffmpeg::init().unwrap();
7
8 match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9 Ok(context) => {
10 for (k, v) in context.metadata().iter() {
11 println!("{}: {}", k, v);
12 }
13
14 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15 println!("Best video stream index: {}", stream.index());
16 }
17
18 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19 println!("Best audio stream index: {}", stream.index());
20 }
21
22 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23 println!("Best subtitle stream index: {}", stream.index());
24 }
25
26 println!(
27 "duration (seconds): {:.2}",
28 context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29 );
30
31 for stream in context.streams() {
32 println!("stream index {}:", stream.index());
33 println!("\ttime_base: {}", stream.time_base());
34 println!("\tstart_time: {}", stream.start_time());
35 println!("\tduration (stream timebase): {}", stream.duration());
36 println!(
37 "\tduration (seconds): {:.2}",
38 stream.duration() as f64 * f64::from(stream.time_base())
39 );
40 println!("\tframes: {}", stream.frames());
41 println!("\tdisposition: {:?}", stream.disposition());
42 println!("\tdiscard: {:?}", stream.discard());
43 println!("\trate: {}", stream.rate());
44
45 let codec = stream.codec();
46 println!("\tmedium: {:?}", codec.medium());
47 println!("\tid: {:?}", codec.id());
48
49 if codec.medium() == ffmpeg::media::Type::Video {
50 if let Ok(video) = codec.decoder().video() {
51 println!("\tbit_rate: {}", video.bit_rate());
52 println!("\tmax_rate: {}", video.max_bit_rate());
53 println!("\tdelay: {}", video.delay());
54 println!("\tvideo.width: {}", video.width());
55 println!("\tvideo.height: {}", video.height());
56 println!("\tvideo.format: {:?}", video.format());
57 println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58 println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59 println!("\tvideo.color_space: {:?}", video.color_space());
60 println!("\tvideo.color_range: {:?}", video.color_range());
61 println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62 println!(
63 "\tvideo.color_transfer_characteristic: {:?}",
64 video.color_transfer_characteristic()
65 );
66 println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67 println!("\tvideo.references: {}", video.references());
68 println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69 }
70 } else if codec.medium() == ffmpeg::media::Type::Audio {
71 if let Ok(audio) = codec.decoder().audio() {
72 println!("\tbit_rate: {}", audio.bit_rate());
73 println!("\tmax_rate: {}", audio.max_bit_rate());
74 println!("\tdelay: {}", audio.delay());
75 println!("\taudio.rate: {}", audio.rate());
76 println!("\taudio.channels: {}", audio.channels());
77 println!("\taudio.format: {:?}", audio.format());
78 println!("\taudio.frames: {}", audio.frames());
79 println!("\taudio.align: {}", audio.align());
80 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81 println!("\taudio.frame_start: {:?}", audio.frame_start());
82 }
83 }
84 }
85 }
86
87 Err(error) => println!("error: {}", error),
88 }
89}Sourcepub fn disposition(&self) -> Disposition
pub fn disposition(&self) -> Disposition
Examples found in repository?
examples/metadata.rs (line 41)
5fn main() {
6 ffmpeg::init().unwrap();
7
8 match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9 Ok(context) => {
10 for (k, v) in context.metadata().iter() {
11 println!("{}: {}", k, v);
12 }
13
14 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15 println!("Best video stream index: {}", stream.index());
16 }
17
18 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19 println!("Best audio stream index: {}", stream.index());
20 }
21
22 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23 println!("Best subtitle stream index: {}", stream.index());
24 }
25
26 println!(
27 "duration (seconds): {:.2}",
28 context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29 );
30
31 for stream in context.streams() {
32 println!("stream index {}:", stream.index());
33 println!("\ttime_base: {}", stream.time_base());
34 println!("\tstart_time: {}", stream.start_time());
35 println!("\tduration (stream timebase): {}", stream.duration());
36 println!(
37 "\tduration (seconds): {:.2}",
38 stream.duration() as f64 * f64::from(stream.time_base())
39 );
40 println!("\tframes: {}", stream.frames());
41 println!("\tdisposition: {:?}", stream.disposition());
42 println!("\tdiscard: {:?}", stream.discard());
43 println!("\trate: {}", stream.rate());
44
45 let codec = stream.codec();
46 println!("\tmedium: {:?}", codec.medium());
47 println!("\tid: {:?}", codec.id());
48
49 if codec.medium() == ffmpeg::media::Type::Video {
50 if let Ok(video) = codec.decoder().video() {
51 println!("\tbit_rate: {}", video.bit_rate());
52 println!("\tmax_rate: {}", video.max_bit_rate());
53 println!("\tdelay: {}", video.delay());
54 println!("\tvideo.width: {}", video.width());
55 println!("\tvideo.height: {}", video.height());
56 println!("\tvideo.format: {:?}", video.format());
57 println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58 println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59 println!("\tvideo.color_space: {:?}", video.color_space());
60 println!("\tvideo.color_range: {:?}", video.color_range());
61 println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62 println!(
63 "\tvideo.color_transfer_characteristic: {:?}",
64 video.color_transfer_characteristic()
65 );
66 println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67 println!("\tvideo.references: {}", video.references());
68 println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69 }
70 } else if codec.medium() == ffmpeg::media::Type::Audio {
71 if let Ok(audio) = codec.decoder().audio() {
72 println!("\tbit_rate: {}", audio.bit_rate());
73 println!("\tmax_rate: {}", audio.max_bit_rate());
74 println!("\tdelay: {}", audio.delay());
75 println!("\taudio.rate: {}", audio.rate());
76 println!("\taudio.channels: {}", audio.channels());
77 println!("\taudio.format: {:?}", audio.format());
78 println!("\taudio.frames: {}", audio.frames());
79 println!("\taudio.align: {}", audio.align());
80 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81 println!("\taudio.frame_start: {:?}", audio.frame_start());
82 }
83 }
84 }
85 }
86
87 Err(error) => println!("error: {}", error),
88 }
89}Sourcepub fn discard(&self) -> Discard
pub fn discard(&self) -> Discard
Examples found in repository?
examples/metadata.rs (line 42)
5fn main() {
6 ffmpeg::init().unwrap();
7
8 match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9 Ok(context) => {
10 for (k, v) in context.metadata().iter() {
11 println!("{}: {}", k, v);
12 }
13
14 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15 println!("Best video stream index: {}", stream.index());
16 }
17
18 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19 println!("Best audio stream index: {}", stream.index());
20 }
21
22 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23 println!("Best subtitle stream index: {}", stream.index());
24 }
25
26 println!(
27 "duration (seconds): {:.2}",
28 context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29 );
30
31 for stream in context.streams() {
32 println!("stream index {}:", stream.index());
33 println!("\ttime_base: {}", stream.time_base());
34 println!("\tstart_time: {}", stream.start_time());
35 println!("\tduration (stream timebase): {}", stream.duration());
36 println!(
37 "\tduration (seconds): {:.2}",
38 stream.duration() as f64 * f64::from(stream.time_base())
39 );
40 println!("\tframes: {}", stream.frames());
41 println!("\tdisposition: {:?}", stream.disposition());
42 println!("\tdiscard: {:?}", stream.discard());
43 println!("\trate: {}", stream.rate());
44
45 let codec = stream.codec();
46 println!("\tmedium: {:?}", codec.medium());
47 println!("\tid: {:?}", codec.id());
48
49 if codec.medium() == ffmpeg::media::Type::Video {
50 if let Ok(video) = codec.decoder().video() {
51 println!("\tbit_rate: {}", video.bit_rate());
52 println!("\tmax_rate: {}", video.max_bit_rate());
53 println!("\tdelay: {}", video.delay());
54 println!("\tvideo.width: {}", video.width());
55 println!("\tvideo.height: {}", video.height());
56 println!("\tvideo.format: {:?}", video.format());
57 println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58 println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59 println!("\tvideo.color_space: {:?}", video.color_space());
60 println!("\tvideo.color_range: {:?}", video.color_range());
61 println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62 println!(
63 "\tvideo.color_transfer_characteristic: {:?}",
64 video.color_transfer_characteristic()
65 );
66 println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67 println!("\tvideo.references: {}", video.references());
68 println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69 }
70 } else if codec.medium() == ffmpeg::media::Type::Audio {
71 if let Ok(audio) = codec.decoder().audio() {
72 println!("\tbit_rate: {}", audio.bit_rate());
73 println!("\tmax_rate: {}", audio.max_bit_rate());
74 println!("\tdelay: {}", audio.delay());
75 println!("\taudio.rate: {}", audio.rate());
76 println!("\taudio.channels: {}", audio.channels());
77 println!("\taudio.format: {:?}", audio.format());
78 println!("\taudio.frames: {}", audio.frames());
79 println!("\taudio.align: {}", audio.align());
80 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81 println!("\taudio.frame_start: {:?}", audio.frame_start());
82 }
83 }
84 }
85 }
86
87 Err(error) => println!("error: {}", error),
88 }
89}pub fn side_data(&self) -> SideDataIter<'_>
Sourcepub fn rate(&self) -> Rational
pub fn rate(&self) -> Rational
Examples found in repository?
examples/metadata.rs (line 43)
5fn main() {
6 ffmpeg::init().unwrap();
7
8 match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9 Ok(context) => {
10 for (k, v) in context.metadata().iter() {
11 println!("{}: {}", k, v);
12 }
13
14 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15 println!("Best video stream index: {}", stream.index());
16 }
17
18 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19 println!("Best audio stream index: {}", stream.index());
20 }
21
22 if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23 println!("Best subtitle stream index: {}", stream.index());
24 }
25
26 println!(
27 "duration (seconds): {:.2}",
28 context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29 );
30
31 for stream in context.streams() {
32 println!("stream index {}:", stream.index());
33 println!("\ttime_base: {}", stream.time_base());
34 println!("\tstart_time: {}", stream.start_time());
35 println!("\tduration (stream timebase): {}", stream.duration());
36 println!(
37 "\tduration (seconds): {:.2}",
38 stream.duration() as f64 * f64::from(stream.time_base())
39 );
40 println!("\tframes: {}", stream.frames());
41 println!("\tdisposition: {:?}", stream.disposition());
42 println!("\tdiscard: {:?}", stream.discard());
43 println!("\trate: {}", stream.rate());
44
45 let codec = stream.codec();
46 println!("\tmedium: {:?}", codec.medium());
47 println!("\tid: {:?}", codec.id());
48
49 if codec.medium() == ffmpeg::media::Type::Video {
50 if let Ok(video) = codec.decoder().video() {
51 println!("\tbit_rate: {}", video.bit_rate());
52 println!("\tmax_rate: {}", video.max_bit_rate());
53 println!("\tdelay: {}", video.delay());
54 println!("\tvideo.width: {}", video.width());
55 println!("\tvideo.height: {}", video.height());
56 println!("\tvideo.format: {:?}", video.format());
57 println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58 println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59 println!("\tvideo.color_space: {:?}", video.color_space());
60 println!("\tvideo.color_range: {:?}", video.color_range());
61 println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62 println!(
63 "\tvideo.color_transfer_characteristic: {:?}",
64 video.color_transfer_characteristic()
65 );
66 println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67 println!("\tvideo.references: {}", video.references());
68 println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69 }
70 } else if codec.medium() == ffmpeg::media::Type::Audio {
71 if let Ok(audio) = codec.decoder().audio() {
72 println!("\tbit_rate: {}", audio.bit_rate());
73 println!("\tmax_rate: {}", audio.max_bit_rate());
74 println!("\tdelay: {}", audio.delay());
75 println!("\taudio.rate: {}", audio.rate());
76 println!("\taudio.channels: {}", audio.channels());
77 println!("\taudio.format: {:?}", audio.format());
78 println!("\taudio.frames: {}", audio.frames());
79 println!("\taudio.align: {}", audio.align());
80 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81 println!("\taudio.frame_start: {:?}", audio.frame_start());
82 }
83 }
84 }
85 }
86
87 Err(error) => println!("error: {}", error),
88 }
89}pub fn avg_frame_rate(&self) -> Rational
pub fn metadata(&self) -> DictionaryRef<'_>
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Stream<'a>
impl<'a> RefUnwindSafe for Stream<'a>
impl<'a> !Send for Stream<'a>
impl<'a> !Sync for Stream<'a>
impl<'a> Unpin for Stream<'a>
impl<'a> UnwindSafe for Stream<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more