pub struct Mut<'a> { /* private fields */ }
Implementations§
Source§impl<'a> Ref<'a>
impl<'a> Ref<'a>
pub unsafe fn wrap(ptr: *mut AVDictionary) -> Self
pub unsafe fn as_mut_ptr(&self) -> *mut AVDictionary
Methods from Deref<Target = Ref<'a>>§
pub unsafe fn as_ptr(&self) -> *const AVDictionary
Sourcepub fn get(&'a self, key: &str) -> Option<&'a str>
pub fn get(&'a self, key: &str) -> Option<&'a str>
Examples found in repository?
examples/chapters.rs (line 26)
5fn main() {
6 ffmpeg::init().unwrap();
7
8 match ffmpeg::format::input(&env::args().nth(1).expect("missing input file name")) {
9 Ok(ictx) => {
10 println!("Nb chapters: {}", ictx.nb_chapters());
11
12 for chapter in ictx.chapters() {
13 println!("chapter id {}:", chapter.id());
14 println!("\ttime_base: {}", chapter.time_base());
15 println!("\tstart: {}", chapter.start());
16 println!("\tend: {}", chapter.end());
17
18 for (k, v) in chapter.metadata().iter() {
19 println!("\t{}: {}", k, v);
20 }
21 }
22
23 let mut octx = ffmpeg::format::output(&"test.mkv").expect("Couldn't open test file");
24
25 for chapter in ictx.chapters() {
26 let title = match chapter.metadata().get("title") {
27 Some(title) => String::from(title),
28 None => String::new(),
29 };
30
31 match octx.add_chapter(
32 chapter.id(),
33 chapter.time_base(),
34 chapter.start(),
35 chapter.end(),
36 &title,
37 ) {
38 Ok(chapter) => println!("Added chapter with id {} to output", chapter.id()),
39 Err(error) => {
40 println!("Error adding chapter with id: {} - {}", chapter.id(), error)
41 }
42 }
43 }
44
45 println!("\nOuput: nb chapters: {}", octx.nb_chapters());
46 for chapter in octx.chapters() {
47 println!("chapter id {}:", chapter.id());
48 println!("\ttime_base: {}", chapter.time_base());
49 println!("\tstart: {}", chapter.start());
50 println!("\tend: {}", chapter.end());
51 for (k, v) in chapter.metadata().iter() {
52 println!("\t{}: {}", k, v);
53 }
54 }
55 }
56
57 Err(error) => println!("error: {}", error),
58 }
59}
Sourcepub fn iter(&self) -> Iter<'_> ⓘ
pub fn iter(&self) -> Iter<'_> ⓘ
Examples found in repository?
examples/chapters.rs (line 18)
5fn main() {
6 ffmpeg::init().unwrap();
7
8 match ffmpeg::format::input(&env::args().nth(1).expect("missing input file name")) {
9 Ok(ictx) => {
10 println!("Nb chapters: {}", ictx.nb_chapters());
11
12 for chapter in ictx.chapters() {
13 println!("chapter id {}:", chapter.id());
14 println!("\ttime_base: {}", chapter.time_base());
15 println!("\tstart: {}", chapter.start());
16 println!("\tend: {}", chapter.end());
17
18 for (k, v) in chapter.metadata().iter() {
19 println!("\t{}: {}", k, v);
20 }
21 }
22
23 let mut octx = ffmpeg::format::output(&"test.mkv").expect("Couldn't open test file");
24
25 for chapter in ictx.chapters() {
26 let title = match chapter.metadata().get("title") {
27 Some(title) => String::from(title),
28 None => String::new(),
29 };
30
31 match octx.add_chapter(
32 chapter.id(),
33 chapter.time_base(),
34 chapter.start(),
35 chapter.end(),
36 &title,
37 ) {
38 Ok(chapter) => println!("Added chapter with id {} to output", chapter.id()),
39 Err(error) => {
40 println!("Error adding chapter with id: {} - {}", chapter.id(), error)
41 }
42 }
43 }
44
45 println!("\nOuput: nb chapters: {}", octx.nb_chapters());
46 for chapter in octx.chapters() {
47 println!("chapter id {}:", chapter.id());
48 println!("\ttime_base: {}", chapter.time_base());
49 println!("\tstart: {}", chapter.start());
50 println!("\tend: {}", chapter.end());
51 for (k, v) in chapter.metadata().iter() {
52 println!("\t{}: {}", k, v);
53 }
54 }
55 }
56
57 Err(error) => println!("error: {}", error),
58 }
59}
More examples
examples/metadata.rs (line 10)
5fn main() -> Result<(), ffmpeg::Error> {
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 = ffmpeg::codec::context::Context::from_parameters(stream.parameters())?;
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 }
82 }
83 }
84 }
85
86 Err(error) => println!("error: {}", error),
87 }
88 Ok(())
89}
Sourcepub fn to_owned<'b>(&self) -> Owned<'b>
pub fn to_owned<'b>(&self) -> Owned<'b>
Examples found in repository?
examples/transcode-audio.rs (line 228)
208fn main() {
209 ffmpeg::init().unwrap();
210
211 let input = env::args().nth(1).expect("missing input");
212 let output = env::args().nth(2).expect("missing output");
213 let filter = env::args().nth(3).unwrap_or_else(|| "anull".to_owned());
214 let seek = env::args().nth(4).and_then(|s| s.parse::<i64>().ok());
215
216 let mut ictx = format::input(&input).unwrap();
217 let mut octx = format::output(&output).unwrap();
218 let mut transcoder = transcoder(&mut ictx, &mut octx, &output, &filter).unwrap();
219
220 if let Some(position) = seek {
221 // If the position was given in seconds, rescale it to ffmpegs base timebase.
222 let position = position.rescale((1, 1), rescale::TIME_BASE);
223 // If this seek was embedded in the transcoding loop, a call of `flush()`
224 // for every opened buffer after the successful seek would be advisable.
225 ictx.seek(position, ..position).unwrap();
226 }
227
228 octx.set_metadata(ictx.metadata().to_owned());
229 octx.write_header().unwrap();
230
231 for (stream, mut packet) in ictx.packets() {
232 if stream.index() == transcoder.stream {
233 packet.rescale_ts(stream.time_base(), transcoder.in_time_base);
234 transcoder.send_packet_to_decoder(&packet);
235 transcoder.receive_and_process_decoded_frames(&mut octx);
236 }
237 }
238
239 transcoder.send_eof_to_decoder();
240 transcoder.receive_and_process_decoded_frames(&mut octx);
241
242 transcoder.flush_filter();
243 transcoder.get_and_process_filtered_frames(&mut octx);
244
245 transcoder.send_eof_to_encoder();
246 transcoder.receive_and_process_encoded_packets(&mut octx);
247
248 octx.write_trailer().unwrap();
249}
More examples
examples/remux.rs (line 42)
7fn main() {
8 let input_file = env::args().nth(1).expect("missing input file");
9 let output_file = env::args().nth(2).expect("missing output file");
10
11 ffmpeg::init().unwrap();
12 log::set_level(log::Level::Warning);
13
14 let mut ictx = format::input(&input_file).unwrap();
15 let mut octx = format::output(&output_file).unwrap();
16
17 let mut stream_mapping = vec![0; ictx.nb_streams() as _];
18 let mut ist_time_bases = vec![Rational(0, 1); ictx.nb_streams() as _];
19 let mut ost_index = 0;
20 for (ist_index, ist) in ictx.streams().enumerate() {
21 let ist_medium = ist.parameters().medium();
22 if ist_medium != media::Type::Audio
23 && ist_medium != media::Type::Video
24 && ist_medium != media::Type::Subtitle
25 {
26 stream_mapping[ist_index] = -1;
27 continue;
28 }
29 stream_mapping[ist_index] = ost_index;
30 ist_time_bases[ist_index] = ist.time_base();
31 ost_index += 1;
32 let mut ost = octx.add_stream(encoder::find(codec::Id::None)).unwrap();
33 ost.set_parameters(ist.parameters());
34 // We need to set codec_tag to 0 lest we run into incompatible codec tag
35 // issues when muxing into a different container format. Unfortunately
36 // there's no high level API to do this (yet).
37 unsafe {
38 (*ost.parameters().as_mut_ptr()).codec_tag = 0;
39 }
40 }
41
42 octx.set_metadata(ictx.metadata().to_owned());
43 octx.write_header().unwrap();
44
45 for (stream, mut packet) in ictx.packets() {
46 let ist_index = stream.index();
47 let ost_index = stream_mapping[ist_index];
48 if ost_index < 0 {
49 continue;
50 }
51 let ost = octx.stream(ost_index as _).unwrap();
52 packet.rescale_ts(ist_time_bases[ist_index], ost.time_base());
53 packet.set_position(-1);
54 packet.set_stream(ost_index as _);
55 packet.write_interleaved(&mut octx).unwrap();
56 }
57
58 octx.write_trailer().unwrap();
59}
examples/transcode-x264.rs (line 236)
169fn main() {
170 let input_file = env::args().nth(1).expect("missing input file");
171 let output_file = env::args().nth(2).expect("missing output file");
172 let x264_opts = parse_opts(
173 env::args()
174 .nth(3)
175 .unwrap_or_else(|| DEFAULT_X264_OPTS.to_string()),
176 )
177 .expect("invalid x264 options string");
178
179 eprintln!("x264 options: {:?}", x264_opts);
180
181 ffmpeg::init().unwrap();
182 log::set_level(log::Level::Info);
183
184 let mut ictx = format::input(&input_file).unwrap();
185 let mut octx = format::output(&output_file).unwrap();
186
187 format::context::input::dump(&ictx, 0, Some(&input_file));
188
189 let best_video_stream_index = ictx
190 .streams()
191 .best(media::Type::Video)
192 .map(|stream| stream.index());
193 let mut stream_mapping: Vec<isize> = vec![0; ictx.nb_streams() as _];
194 let mut ist_time_bases = vec![Rational(0, 0); ictx.nb_streams() as _];
195 let mut ost_time_bases = vec![Rational(0, 0); ictx.nb_streams() as _];
196 let mut transcoders = HashMap::new();
197 let mut ost_index = 0;
198 for (ist_index, ist) in ictx.streams().enumerate() {
199 let ist_medium = ist.parameters().medium();
200 if ist_medium != media::Type::Audio
201 && ist_medium != media::Type::Video
202 && ist_medium != media::Type::Subtitle
203 {
204 stream_mapping[ist_index] = -1;
205 continue;
206 }
207 stream_mapping[ist_index] = ost_index;
208 ist_time_bases[ist_index] = ist.time_base();
209 if ist_medium == media::Type::Video {
210 // Initialize transcoder for video stream.
211 transcoders.insert(
212 ist_index,
213 Transcoder::new(
214 &ist,
215 &mut octx,
216 ost_index as _,
217 x264_opts.to_owned(),
218 Some(ist_index) == best_video_stream_index,
219 )
220 .unwrap(),
221 );
222 } else {
223 // Set up for stream copy for non-video stream.
224 let mut ost = octx.add_stream(encoder::find(codec::Id::None)).unwrap();
225 ost.set_parameters(ist.parameters());
226 // We need to set codec_tag to 0 lest we run into incompatible codec tag
227 // issues when muxing into a different container format. Unfortunately
228 // there's no high level API to do this (yet).
229 unsafe {
230 (*ost.parameters().as_mut_ptr()).codec_tag = 0;
231 }
232 }
233 ost_index += 1;
234 }
235
236 octx.set_metadata(ictx.metadata().to_owned());
237 format::context::output::dump(&octx, 0, Some(&output_file));
238 octx.write_header().unwrap();
239
240 for (ost_index, _) in octx.streams().enumerate() {
241 ost_time_bases[ost_index] = octx.stream(ost_index as _).unwrap().time_base();
242 }
243
244 for (stream, mut packet) in ictx.packets() {
245 let ist_index = stream.index();
246 let ost_index = stream_mapping[ist_index];
247 if ost_index < 0 {
248 continue;
249 }
250 let ost_time_base = ost_time_bases[ost_index as usize];
251 match transcoders.get_mut(&ist_index) {
252 Some(transcoder) => {
253 transcoder.send_packet_to_decoder(&packet);
254 transcoder.receive_and_process_decoded_frames(&mut octx, ost_time_base);
255 }
256 None => {
257 // Do stream copy on non-video streams.
258 packet.rescale_ts(ist_time_bases[ist_index], ost_time_base);
259 packet.set_position(-1);
260 packet.set_stream(ost_index as _);
261 packet.write_interleaved(&mut octx).unwrap();
262 }
263 }
264 }
265
266 // Flush encoders and decoders.
267 for (ost_index, transcoder) in transcoders.iter_mut() {
268 let ost_time_base = ost_time_bases[*ost_index];
269 transcoder.send_eof_to_decoder();
270 transcoder.receive_and_process_decoded_frames(&mut octx, ost_time_base);
271 transcoder.send_eof_to_encoder();
272 transcoder.receive_and_process_encoded_packets(&mut octx, ost_time_base);
273 }
274
275 octx.write_trailer().unwrap();
276}
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Ref<'a>
impl<'a> RefUnwindSafe for Ref<'a>
impl<'a> !Send for Ref<'a>
impl<'a> !Sync for Ref<'a>
impl<'a> Unpin for Ref<'a>
impl<'a> UnwindSafe for Ref<'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