pub struct Video(pub Opened);Tuple Fields§
§0: OpenedImplementations§
Source§impl Video
impl Video
Sourcepub fn width(&self) -> u32
pub fn width(&self) -> u32
Examples found in repository?
examples/dump-frames.rs (line 26)
11fn main() -> Result<(), ffmpeg::Error> {
12 ffmpeg::init().unwrap();
13
14 if let Ok(mut ictx) = input(&env::args().nth(1).expect("Cannot open file.")) {
15 let input = ictx
16 .streams()
17 .best(Type::Video)
18 .ok_or(ffmpeg::Error::StreamNotFound)?;
19 let video_stream_index = input.index();
20
21 let context_decoder = ffmpeg::codec::context::Context::from_parameters(input.parameters())?;
22 let mut decoder = context_decoder.decoder().video()?;
23
24 let mut scaler = Context::get(
25 decoder.format(),
26 decoder.width(),
27 decoder.height(),
28 Pixel::RGB24,
29 decoder.width(),
30 decoder.height(),
31 Flags::BILINEAR,
32 )?;
33
34 let mut frame_index = 0;
35
36 let mut receive_and_process_decoded_frames =
37 |decoder: &mut ffmpeg::decoder::Video| -> Result<(), ffmpeg::Error> {
38 let mut decoded = Video::empty();
39 while decoder.receive_frame(&mut decoded).is_ok() {
40 let mut rgb_frame = Video::empty();
41 scaler.run(&decoded, &mut rgb_frame)?;
42 save_file(&rgb_frame, frame_index).unwrap();
43 frame_index += 1;
44 }
45 Ok(())
46 };
47
48 for (stream, packet) in ictx.packets() {
49 if stream.index() == video_stream_index {
50 decoder.send_packet(&packet)?;
51 receive_and_process_decoded_frames(&mut decoder)?;
52 }
53 }
54 decoder.send_eof()?;
55 receive_and_process_decoded_frames(&mut decoder)?;
56 }
57
58 Ok(())
59}More examples
examples/transcode-x264.rs (line 64)
43 fn new(
44 ist: &format::stream::Stream,
45 octx: &mut format::context::Output,
46 ost_index: usize,
47 x264_opts: Dictionary,
48 enable_logging: bool,
49 ) -> Result<Self, ffmpeg::Error> {
50 let global_header = octx.format().flags().contains(format::Flags::GLOBAL_HEADER);
51 let decoder = ffmpeg::codec::context::Context::from_parameters(ist.parameters())?
52 .decoder()
53 .video()?;
54
55 let codec = encoder::find(codec::Id::H264);
56 let mut ost = octx.add_stream(codec)?;
57
58 let mut encoder =
59 codec::context::Context::new_with_codec(codec.ok_or(ffmpeg::Error::InvalidData)?)
60 .encoder()
61 .video()?;
62 ost.set_parameters(&encoder);
63 encoder.set_height(decoder.height());
64 encoder.set_width(decoder.width());
65 encoder.set_aspect_ratio(decoder.aspect_ratio());
66 encoder.set_format(decoder.format());
67 encoder.set_frame_rate(decoder.frame_rate());
68 encoder.set_time_base(ist.time_base());
69
70 if global_header {
71 encoder.set_flags(codec::Flags::GLOBAL_HEADER);
72 }
73
74 let opened_encoder = encoder
75 .open_with(x264_opts)
76 .expect("error opening x264 with supplied settings");
77 ost.set_parameters(&opened_encoder);
78 Ok(Self {
79 ost_index,
80 decoder,
81 input_time_base: ist.time_base(),
82 encoder: opened_encoder,
83 logging_enabled: enable_logging,
84 frame_count: 0,
85 last_log_frame_count: 0,
86 starting_time: Instant::now(),
87 last_log_time: Instant::now(),
88 })
89 }examples/metadata.rs (line 54)
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 && let Ok(audio) = codec.decoder().audio()
72 {
73 println!("\tbit_rate: {}", audio.bit_rate());
74 println!("\tmax_rate: {}", audio.max_bit_rate());
75 println!("\tdelay: {}", audio.delay());
76 println!("\taudio.rate: {}", audio.rate());
77 println!("\taudio.channels: {}", audio.channels());
78 println!("\taudio.format: {:?}", audio.format());
79 println!("\taudio.frames: {}", audio.frames());
80 println!("\taudio.align: {}", audio.align());
81 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
82 }
83 }
84 }
85
86 Err(error) => println!("error: {}", error),
87 }
88 Ok(())
89}Sourcepub fn height(&self) -> u32
pub fn height(&self) -> u32
Examples found in repository?
examples/dump-frames.rs (line 27)
11fn main() -> Result<(), ffmpeg::Error> {
12 ffmpeg::init().unwrap();
13
14 if let Ok(mut ictx) = input(&env::args().nth(1).expect("Cannot open file.")) {
15 let input = ictx
16 .streams()
17 .best(Type::Video)
18 .ok_or(ffmpeg::Error::StreamNotFound)?;
19 let video_stream_index = input.index();
20
21 let context_decoder = ffmpeg::codec::context::Context::from_parameters(input.parameters())?;
22 let mut decoder = context_decoder.decoder().video()?;
23
24 let mut scaler = Context::get(
25 decoder.format(),
26 decoder.width(),
27 decoder.height(),
28 Pixel::RGB24,
29 decoder.width(),
30 decoder.height(),
31 Flags::BILINEAR,
32 )?;
33
34 let mut frame_index = 0;
35
36 let mut receive_and_process_decoded_frames =
37 |decoder: &mut ffmpeg::decoder::Video| -> Result<(), ffmpeg::Error> {
38 let mut decoded = Video::empty();
39 while decoder.receive_frame(&mut decoded).is_ok() {
40 let mut rgb_frame = Video::empty();
41 scaler.run(&decoded, &mut rgb_frame)?;
42 save_file(&rgb_frame, frame_index).unwrap();
43 frame_index += 1;
44 }
45 Ok(())
46 };
47
48 for (stream, packet) in ictx.packets() {
49 if stream.index() == video_stream_index {
50 decoder.send_packet(&packet)?;
51 receive_and_process_decoded_frames(&mut decoder)?;
52 }
53 }
54 decoder.send_eof()?;
55 receive_and_process_decoded_frames(&mut decoder)?;
56 }
57
58 Ok(())
59}More examples
examples/transcode-x264.rs (line 63)
43 fn new(
44 ist: &format::stream::Stream,
45 octx: &mut format::context::Output,
46 ost_index: usize,
47 x264_opts: Dictionary,
48 enable_logging: bool,
49 ) -> Result<Self, ffmpeg::Error> {
50 let global_header = octx.format().flags().contains(format::Flags::GLOBAL_HEADER);
51 let decoder = ffmpeg::codec::context::Context::from_parameters(ist.parameters())?
52 .decoder()
53 .video()?;
54
55 let codec = encoder::find(codec::Id::H264);
56 let mut ost = octx.add_stream(codec)?;
57
58 let mut encoder =
59 codec::context::Context::new_with_codec(codec.ok_or(ffmpeg::Error::InvalidData)?)
60 .encoder()
61 .video()?;
62 ost.set_parameters(&encoder);
63 encoder.set_height(decoder.height());
64 encoder.set_width(decoder.width());
65 encoder.set_aspect_ratio(decoder.aspect_ratio());
66 encoder.set_format(decoder.format());
67 encoder.set_frame_rate(decoder.frame_rate());
68 encoder.set_time_base(ist.time_base());
69
70 if global_header {
71 encoder.set_flags(codec::Flags::GLOBAL_HEADER);
72 }
73
74 let opened_encoder = encoder
75 .open_with(x264_opts)
76 .expect("error opening x264 with supplied settings");
77 ost.set_parameters(&opened_encoder);
78 Ok(Self {
79 ost_index,
80 decoder,
81 input_time_base: ist.time_base(),
82 encoder: opened_encoder,
83 logging_enabled: enable_logging,
84 frame_count: 0,
85 last_log_frame_count: 0,
86 starting_time: Instant::now(),
87 last_log_time: Instant::now(),
88 })
89 }examples/metadata.rs (line 55)
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 && let Ok(audio) = codec.decoder().audio()
72 {
73 println!("\tbit_rate: {}", audio.bit_rate());
74 println!("\tmax_rate: {}", audio.max_bit_rate());
75 println!("\tdelay: {}", audio.delay());
76 println!("\taudio.rate: {}", audio.rate());
77 println!("\taudio.channels: {}", audio.channels());
78 println!("\taudio.format: {:?}", audio.format());
79 println!("\taudio.frames: {}", audio.frames());
80 println!("\taudio.align: {}", audio.align());
81 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
82 }
83 }
84 }
85
86 Err(error) => println!("error: {}", error),
87 }
88 Ok(())
89}Sourcepub fn format(&self) -> Pixel
pub fn format(&self) -> Pixel
Examples found in repository?
examples/dump-frames.rs (line 25)
11fn main() -> Result<(), ffmpeg::Error> {
12 ffmpeg::init().unwrap();
13
14 if let Ok(mut ictx) = input(&env::args().nth(1).expect("Cannot open file.")) {
15 let input = ictx
16 .streams()
17 .best(Type::Video)
18 .ok_or(ffmpeg::Error::StreamNotFound)?;
19 let video_stream_index = input.index();
20
21 let context_decoder = ffmpeg::codec::context::Context::from_parameters(input.parameters())?;
22 let mut decoder = context_decoder.decoder().video()?;
23
24 let mut scaler = Context::get(
25 decoder.format(),
26 decoder.width(),
27 decoder.height(),
28 Pixel::RGB24,
29 decoder.width(),
30 decoder.height(),
31 Flags::BILINEAR,
32 )?;
33
34 let mut frame_index = 0;
35
36 let mut receive_and_process_decoded_frames =
37 |decoder: &mut ffmpeg::decoder::Video| -> Result<(), ffmpeg::Error> {
38 let mut decoded = Video::empty();
39 while decoder.receive_frame(&mut decoded).is_ok() {
40 let mut rgb_frame = Video::empty();
41 scaler.run(&decoded, &mut rgb_frame)?;
42 save_file(&rgb_frame, frame_index).unwrap();
43 frame_index += 1;
44 }
45 Ok(())
46 };
47
48 for (stream, packet) in ictx.packets() {
49 if stream.index() == video_stream_index {
50 decoder.send_packet(&packet)?;
51 receive_and_process_decoded_frames(&mut decoder)?;
52 }
53 }
54 decoder.send_eof()?;
55 receive_and_process_decoded_frames(&mut decoder)?;
56 }
57
58 Ok(())
59}More examples
examples/transcode-x264.rs (line 66)
43 fn new(
44 ist: &format::stream::Stream,
45 octx: &mut format::context::Output,
46 ost_index: usize,
47 x264_opts: Dictionary,
48 enable_logging: bool,
49 ) -> Result<Self, ffmpeg::Error> {
50 let global_header = octx.format().flags().contains(format::Flags::GLOBAL_HEADER);
51 let decoder = ffmpeg::codec::context::Context::from_parameters(ist.parameters())?
52 .decoder()
53 .video()?;
54
55 let codec = encoder::find(codec::Id::H264);
56 let mut ost = octx.add_stream(codec)?;
57
58 let mut encoder =
59 codec::context::Context::new_with_codec(codec.ok_or(ffmpeg::Error::InvalidData)?)
60 .encoder()
61 .video()?;
62 ost.set_parameters(&encoder);
63 encoder.set_height(decoder.height());
64 encoder.set_width(decoder.width());
65 encoder.set_aspect_ratio(decoder.aspect_ratio());
66 encoder.set_format(decoder.format());
67 encoder.set_frame_rate(decoder.frame_rate());
68 encoder.set_time_base(ist.time_base());
69
70 if global_header {
71 encoder.set_flags(codec::Flags::GLOBAL_HEADER);
72 }
73
74 let opened_encoder = encoder
75 .open_with(x264_opts)
76 .expect("error opening x264 with supplied settings");
77 ost.set_parameters(&opened_encoder);
78 Ok(Self {
79 ost_index,
80 decoder,
81 input_time_base: ist.time_base(),
82 encoder: opened_encoder,
83 logging_enabled: enable_logging,
84 frame_count: 0,
85 last_log_frame_count: 0,
86 starting_time: Instant::now(),
87 last_log_time: Instant::now(),
88 })
89 }examples/metadata.rs (line 56)
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 && let Ok(audio) = codec.decoder().audio()
72 {
73 println!("\tbit_rate: {}", audio.bit_rate());
74 println!("\tmax_rate: {}", audio.max_bit_rate());
75 println!("\tdelay: {}", audio.delay());
76 println!("\taudio.rate: {}", audio.rate());
77 println!("\taudio.channels: {}", audio.channels());
78 println!("\taudio.format: {:?}", audio.format());
79 println!("\taudio.frames: {}", audio.frames());
80 println!("\taudio.align: {}", audio.align());
81 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
82 }
83 }
84 }
85
86 Err(error) => println!("error: {}", error),
87 }
88 Ok(())
89}Sourcepub fn has_b_frames(&self) -> bool
pub fn has_b_frames(&self) -> bool
Examples found in repository?
examples/metadata.rs (line 57)
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 && let Ok(audio) = codec.decoder().audio()
72 {
73 println!("\tbit_rate: {}", audio.bit_rate());
74 println!("\tmax_rate: {}", audio.max_bit_rate());
75 println!("\tdelay: {}", audio.delay());
76 println!("\taudio.rate: {}", audio.rate());
77 println!("\taudio.channels: {}", audio.channels());
78 println!("\taudio.format: {:?}", audio.format());
79 println!("\taudio.frames: {}", audio.frames());
80 println!("\taudio.align: {}", audio.align());
81 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
82 }
83 }
84 }
85
86 Err(error) => println!("error: {}", error),
87 }
88 Ok(())
89}Sourcepub fn aspect_ratio(&self) -> Rational
pub fn aspect_ratio(&self) -> Rational
Examples found in repository?
examples/transcode-x264.rs (line 65)
43 fn new(
44 ist: &format::stream::Stream,
45 octx: &mut format::context::Output,
46 ost_index: usize,
47 x264_opts: Dictionary,
48 enable_logging: bool,
49 ) -> Result<Self, ffmpeg::Error> {
50 let global_header = octx.format().flags().contains(format::Flags::GLOBAL_HEADER);
51 let decoder = ffmpeg::codec::context::Context::from_parameters(ist.parameters())?
52 .decoder()
53 .video()?;
54
55 let codec = encoder::find(codec::Id::H264);
56 let mut ost = octx.add_stream(codec)?;
57
58 let mut encoder =
59 codec::context::Context::new_with_codec(codec.ok_or(ffmpeg::Error::InvalidData)?)
60 .encoder()
61 .video()?;
62 ost.set_parameters(&encoder);
63 encoder.set_height(decoder.height());
64 encoder.set_width(decoder.width());
65 encoder.set_aspect_ratio(decoder.aspect_ratio());
66 encoder.set_format(decoder.format());
67 encoder.set_frame_rate(decoder.frame_rate());
68 encoder.set_time_base(ist.time_base());
69
70 if global_header {
71 encoder.set_flags(codec::Flags::GLOBAL_HEADER);
72 }
73
74 let opened_encoder = encoder
75 .open_with(x264_opts)
76 .expect("error opening x264 with supplied settings");
77 ost.set_parameters(&opened_encoder);
78 Ok(Self {
79 ost_index,
80 decoder,
81 input_time_base: ist.time_base(),
82 encoder: opened_encoder,
83 logging_enabled: enable_logging,
84 frame_count: 0,
85 last_log_frame_count: 0,
86 starting_time: Instant::now(),
87 last_log_time: Instant::now(),
88 })
89 }More examples
examples/metadata.rs (line 58)
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 && let Ok(audio) = codec.decoder().audio()
72 {
73 println!("\tbit_rate: {}", audio.bit_rate());
74 println!("\tmax_rate: {}", audio.max_bit_rate());
75 println!("\tdelay: {}", audio.delay());
76 println!("\taudio.rate: {}", audio.rate());
77 println!("\taudio.channels: {}", audio.channels());
78 println!("\taudio.format: {:?}", audio.format());
79 println!("\taudio.frames: {}", audio.frames());
80 println!("\taudio.align: {}", audio.align());
81 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
82 }
83 }
84 }
85
86 Err(error) => println!("error: {}", error),
87 }
88 Ok(())
89}Sourcepub fn color_space(&self) -> Space
pub fn color_space(&self) -> Space
Examples found in repository?
examples/metadata.rs (line 59)
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 && let Ok(audio) = codec.decoder().audio()
72 {
73 println!("\tbit_rate: {}", audio.bit_rate());
74 println!("\tmax_rate: {}", audio.max_bit_rate());
75 println!("\tdelay: {}", audio.delay());
76 println!("\taudio.rate: {}", audio.rate());
77 println!("\taudio.channels: {}", audio.channels());
78 println!("\taudio.format: {:?}", audio.format());
79 println!("\taudio.frames: {}", audio.frames());
80 println!("\taudio.align: {}", audio.align());
81 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
82 }
83 }
84 }
85
86 Err(error) => println!("error: {}", error),
87 }
88 Ok(())
89}Sourcepub fn color_range(&self) -> Range
pub fn color_range(&self) -> Range
Examples found in repository?
examples/metadata.rs (line 60)
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 && let Ok(audio) = codec.decoder().audio()
72 {
73 println!("\tbit_rate: {}", audio.bit_rate());
74 println!("\tmax_rate: {}", audio.max_bit_rate());
75 println!("\tdelay: {}", audio.delay());
76 println!("\taudio.rate: {}", audio.rate());
77 println!("\taudio.channels: {}", audio.channels());
78 println!("\taudio.format: {:?}", audio.format());
79 println!("\taudio.frames: {}", audio.frames());
80 println!("\taudio.align: {}", audio.align());
81 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
82 }
83 }
84 }
85
86 Err(error) => println!("error: {}", error),
87 }
88 Ok(())
89}Sourcepub fn color_primaries(&self) -> Primaries
pub fn color_primaries(&self) -> Primaries
Examples found in repository?
examples/metadata.rs (line 61)
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 && let Ok(audio) = codec.decoder().audio()
72 {
73 println!("\tbit_rate: {}", audio.bit_rate());
74 println!("\tmax_rate: {}", audio.max_bit_rate());
75 println!("\tdelay: {}", audio.delay());
76 println!("\taudio.rate: {}", audio.rate());
77 println!("\taudio.channels: {}", audio.channels());
78 println!("\taudio.format: {:?}", audio.format());
79 println!("\taudio.frames: {}", audio.frames());
80 println!("\taudio.align: {}", audio.align());
81 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
82 }
83 }
84 }
85
86 Err(error) => println!("error: {}", error),
87 }
88 Ok(())
89}Sourcepub fn color_transfer_characteristic(&self) -> TransferCharacteristic
pub fn color_transfer_characteristic(&self) -> TransferCharacteristic
Examples found in repository?
examples/metadata.rs (line 64)
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 && let Ok(audio) = codec.decoder().audio()
72 {
73 println!("\tbit_rate: {}", audio.bit_rate());
74 println!("\tmax_rate: {}", audio.max_bit_rate());
75 println!("\tdelay: {}", audio.delay());
76 println!("\taudio.rate: {}", audio.rate());
77 println!("\taudio.channels: {}", audio.channels());
78 println!("\taudio.format: {:?}", audio.format());
79 println!("\taudio.frames: {}", audio.frames());
80 println!("\taudio.align: {}", audio.align());
81 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
82 }
83 }
84 }
85
86 Err(error) => println!("error: {}", error),
87 }
88 Ok(())
89}Sourcepub fn chroma_location(&self) -> Location
pub fn chroma_location(&self) -> Location
Examples found in repository?
examples/metadata.rs (line 66)
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 && let Ok(audio) = codec.decoder().audio()
72 {
73 println!("\tbit_rate: {}", audio.bit_rate());
74 println!("\tmax_rate: {}", audio.max_bit_rate());
75 println!("\tdelay: {}", audio.delay());
76 println!("\taudio.rate: {}", audio.rate());
77 println!("\taudio.channels: {}", audio.channels());
78 println!("\taudio.format: {:?}", audio.format());
79 println!("\taudio.frames: {}", audio.frames());
80 println!("\taudio.align: {}", audio.align());
81 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
82 }
83 }
84 }
85
86 Err(error) => println!("error: {}", error),
87 }
88 Ok(())
89}pub fn set_slice_flags(&mut self, value: Flags)
pub fn skip_top(&mut self, value: usize)
pub fn skip_bottom(&mut self, value: usize)
Sourcepub fn references(&self) -> usize
pub fn references(&self) -> usize
Examples found in repository?
examples/metadata.rs (line 67)
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 && let Ok(audio) = codec.decoder().audio()
72 {
73 println!("\tbit_rate: {}", audio.bit_rate());
74 println!("\tmax_rate: {}", audio.max_bit_rate());
75 println!("\tdelay: {}", audio.delay());
76 println!("\taudio.rate: {}", audio.rate());
77 println!("\taudio.channels: {}", audio.channels());
78 println!("\taudio.format: {:?}", audio.format());
79 println!("\taudio.frames: {}", audio.frames());
80 println!("\taudio.align: {}", audio.align());
81 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
82 }
83 }
84 }
85
86 Err(error) => println!("error: {}", error),
87 }
88 Ok(())
89}pub fn set_field_order(&mut self, value: FieldOrder)
Sourcepub fn intra_dc_precision(&self) -> u8
pub fn intra_dc_precision(&self) -> u8
Examples found in repository?
examples/metadata.rs (line 68)
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 && let Ok(audio) = codec.decoder().audio()
72 {
73 println!("\tbit_rate: {}", audio.bit_rate());
74 println!("\tmax_rate: {}", audio.max_bit_rate());
75 println!("\tdelay: {}", audio.delay());
76 println!("\taudio.rate: {}", audio.rate());
77 println!("\taudio.channels: {}", audio.channels());
78 println!("\taudio.format: {:?}", audio.format());
79 println!("\taudio.frames: {}", audio.frames());
80 println!("\taudio.align: {}", audio.align());
81 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
82 }
83 }
84 }
85
86 Err(error) => println!("error: {}", error),
87 }
88 Ok(())
89}Sourcepub fn max_bit_rate(&self) -> usize
pub fn max_bit_rate(&self) -> usize
Examples found in repository?
examples/metadata.rs (line 52)
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 && let Ok(audio) = codec.decoder().audio()
72 {
73 println!("\tbit_rate: {}", audio.bit_rate());
74 println!("\tmax_rate: {}", audio.max_bit_rate());
75 println!("\tdelay: {}", audio.delay());
76 println!("\taudio.rate: {}", audio.rate());
77 println!("\taudio.channels: {}", audio.channels());
78 println!("\taudio.format: {:?}", audio.format());
79 println!("\taudio.frames: {}", audio.frames());
80 println!("\taudio.align: {}", audio.align());
81 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
82 }
83 }
84 }
85
86 Err(error) => println!("error: {}", error),
87 }
88 Ok(())
89}Methods from Deref<Target = Opened>§
Sourcepub fn send_packet<P: Ref>(&mut self, packet: &P) -> Result<(), Error>
pub fn send_packet<P: Ref>(&mut self, packet: &P) -> Result<(), Error>
Examples found in repository?
More examples
examples/dump-frames.rs (line 50)
11fn main() -> Result<(), ffmpeg::Error> {
12 ffmpeg::init().unwrap();
13
14 if let Ok(mut ictx) = input(&env::args().nth(1).expect("Cannot open file.")) {
15 let input = ictx
16 .streams()
17 .best(Type::Video)
18 .ok_or(ffmpeg::Error::StreamNotFound)?;
19 let video_stream_index = input.index();
20
21 let context_decoder = ffmpeg::codec::context::Context::from_parameters(input.parameters())?;
22 let mut decoder = context_decoder.decoder().video()?;
23
24 let mut scaler = Context::get(
25 decoder.format(),
26 decoder.width(),
27 decoder.height(),
28 Pixel::RGB24,
29 decoder.width(),
30 decoder.height(),
31 Flags::BILINEAR,
32 )?;
33
34 let mut frame_index = 0;
35
36 let mut receive_and_process_decoded_frames =
37 |decoder: &mut ffmpeg::decoder::Video| -> Result<(), ffmpeg::Error> {
38 let mut decoded = Video::empty();
39 while decoder.receive_frame(&mut decoded).is_ok() {
40 let mut rgb_frame = Video::empty();
41 scaler.run(&decoded, &mut rgb_frame)?;
42 save_file(&rgb_frame, frame_index).unwrap();
43 frame_index += 1;
44 }
45 Ok(())
46 };
47
48 for (stream, packet) in ictx.packets() {
49 if stream.index() == video_stream_index {
50 decoder.send_packet(&packet)?;
51 receive_and_process_decoded_frames(&mut decoder)?;
52 }
53 }
54 decoder.send_eof()?;
55 receive_and_process_decoded_frames(&mut decoder)?;
56 }
57
58 Ok(())
59}Sourcepub fn send_eof(&mut self) -> Result<(), Error>
pub fn send_eof(&mut self) -> Result<(), Error>
Sends a NULL packet to the decoder to signal end of stream and enter draining mode.
Examples found in repository?
More examples
examples/dump-frames.rs (line 54)
11fn main() -> Result<(), ffmpeg::Error> {
12 ffmpeg::init().unwrap();
13
14 if let Ok(mut ictx) = input(&env::args().nth(1).expect("Cannot open file.")) {
15 let input = ictx
16 .streams()
17 .best(Type::Video)
18 .ok_or(ffmpeg::Error::StreamNotFound)?;
19 let video_stream_index = input.index();
20
21 let context_decoder = ffmpeg::codec::context::Context::from_parameters(input.parameters())?;
22 let mut decoder = context_decoder.decoder().video()?;
23
24 let mut scaler = Context::get(
25 decoder.format(),
26 decoder.width(),
27 decoder.height(),
28 Pixel::RGB24,
29 decoder.width(),
30 decoder.height(),
31 Flags::BILINEAR,
32 )?;
33
34 let mut frame_index = 0;
35
36 let mut receive_and_process_decoded_frames =
37 |decoder: &mut ffmpeg::decoder::Video| -> Result<(), ffmpeg::Error> {
38 let mut decoded = Video::empty();
39 while decoder.receive_frame(&mut decoded).is_ok() {
40 let mut rgb_frame = Video::empty();
41 scaler.run(&decoded, &mut rgb_frame)?;
42 save_file(&rgb_frame, frame_index).unwrap();
43 frame_index += 1;
44 }
45 Ok(())
46 };
47
48 for (stream, packet) in ictx.packets() {
49 if stream.index() == video_stream_index {
50 decoder.send_packet(&packet)?;
51 receive_and_process_decoded_frames(&mut decoder)?;
52 }
53 }
54 decoder.send_eof()?;
55 receive_and_process_decoded_frames(&mut decoder)?;
56 }
57
58 Ok(())
59}Sourcepub fn receive_frame(&mut self, frame: &mut Frame) -> Result<(), Error>
pub fn receive_frame(&mut self, frame: &mut Frame) -> Result<(), Error>
Examples found in repository?
More examples
examples/transcode-x264.rs (line 105)
99 fn receive_and_process_decoded_frames(
100 &mut self,
101 octx: &mut format::context::Output,
102 ost_time_base: Rational,
103 ) {
104 let mut frame = frame::Video::empty();
105 while self.decoder.receive_frame(&mut frame).is_ok() {
106 self.frame_count += 1;
107 let timestamp = frame.timestamp();
108 self.log_progress(f64::from(
109 Rational(timestamp.unwrap_or(0) as i32, 1) * self.input_time_base,
110 ));
111 frame.set_pts(timestamp);
112 frame.set_kind(picture::Type::None);
113 self.send_frame_to_encoder(&frame);
114 self.receive_and_process_encoded_packets(octx, ost_time_base);
115 }
116 }examples/dump-frames.rs (line 39)
11fn main() -> Result<(), ffmpeg::Error> {
12 ffmpeg::init().unwrap();
13
14 if let Ok(mut ictx) = input(&env::args().nth(1).expect("Cannot open file.")) {
15 let input = ictx
16 .streams()
17 .best(Type::Video)
18 .ok_or(ffmpeg::Error::StreamNotFound)?;
19 let video_stream_index = input.index();
20
21 let context_decoder = ffmpeg::codec::context::Context::from_parameters(input.parameters())?;
22 let mut decoder = context_decoder.decoder().video()?;
23
24 let mut scaler = Context::get(
25 decoder.format(),
26 decoder.width(),
27 decoder.height(),
28 Pixel::RGB24,
29 decoder.width(),
30 decoder.height(),
31 Flags::BILINEAR,
32 )?;
33
34 let mut frame_index = 0;
35
36 let mut receive_and_process_decoded_frames =
37 |decoder: &mut ffmpeg::decoder::Video| -> Result<(), ffmpeg::Error> {
38 let mut decoded = Video::empty();
39 while decoder.receive_frame(&mut decoded).is_ok() {
40 let mut rgb_frame = Video::empty();
41 scaler.run(&decoded, &mut rgb_frame)?;
42 save_file(&rgb_frame, frame_index).unwrap();
43 frame_index += 1;
44 }
45 Ok(())
46 };
47
48 for (stream, packet) in ictx.packets() {
49 if stream.index() == video_stream_index {
50 decoder.send_packet(&packet)?;
51 receive_and_process_decoded_frames(&mut decoder)?;
52 }
53 }
54 decoder.send_eof()?;
55 receive_and_process_decoded_frames(&mut decoder)?;
56 }
57
58 Ok(())
59}Sourcepub fn bit_rate(&self) -> usize
pub fn bit_rate(&self) -> usize
Examples found in repository?
examples/transcode-audio.rs (line 112)
64fn transcoder<P: AsRef<Path> + ?Sized>(
65 ictx: &mut format::context::Input,
66 octx: &mut format::context::Output,
67 path: &P,
68 filter_spec: &str,
69) -> Result<Transcoder, ffmpeg::Error> {
70 let input = ictx
71 .streams()
72 .best(media::Type::Audio)
73 .expect("could not find best audio stream");
74 let context = ffmpeg::codec::context::Context::from_parameters(input.parameters())?;
75 let mut decoder = context.decoder().audio()?;
76 let codec = ffmpeg::encoder::find(octx.format().codec(path, media::Type::Audio))
77 .expect("failed to find encoder")
78 .audio()?;
79 let global = octx
80 .format()
81 .flags()
82 .contains(ffmpeg::format::flag::Flags::GLOBAL_HEADER);
83
84 decoder.set_parameters(input.parameters())?;
85
86 let mut output = octx.add_stream(codec)?;
87 let context = ffmpeg::codec::context::Context::from_parameters(output.parameters())?;
88 let mut encoder = context.encoder().audio()?;
89
90 let channel_layout = codec
91 .channel_layouts()
92 .map(|cls| cls.best(decoder.channel_layout().channels()))
93 .unwrap_or(ffmpeg::channel_layout::ChannelLayout::STEREO);
94
95 if global {
96 encoder.set_flags(ffmpeg::codec::flag::Flags::GLOBAL_HEADER);
97 }
98
99 encoder.set_rate(decoder.rate() as i32);
100 encoder.set_channel_layout(channel_layout);
101 #[cfg(not(feature = "ffmpeg_7_0"))]
102 {
103 encoder.set_channels(channel_layout.channels());
104 }
105 encoder.set_format(
106 codec
107 .formats()
108 .expect("unknown supported formats")
109 .next()
110 .unwrap(),
111 );
112 encoder.set_bit_rate(decoder.bit_rate());
113 encoder.set_max_bit_rate(decoder.max_bit_rate());
114
115 encoder.set_time_base((1, decoder.rate() as i32));
116 output.set_time_base((1, decoder.rate() as i32));
117
118 let encoder = encoder.open_as(codec)?;
119 output.set_parameters(&encoder);
120
121 let filter = filter(filter_spec, &decoder, &encoder)?;
122
123 let in_time_base = decoder.time_base();
124 let out_time_base = output.time_base();
125
126 Ok(Transcoder {
127 stream: input.index(),
128 filter,
129 decoder,
130 encoder,
131 in_time_base,
132 out_time_base,
133 })
134}More examples
examples/metadata.rs (line 51)
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 && let Ok(audio) = codec.decoder().audio()
72 {
73 println!("\tbit_rate: {}", audio.bit_rate());
74 println!("\tmax_rate: {}", audio.max_bit_rate());
75 println!("\tdelay: {}", audio.delay());
76 println!("\taudio.rate: {}", audio.rate());
77 println!("\taudio.channels: {}", audio.channels());
78 println!("\taudio.format: {:?}", audio.format());
79 println!("\taudio.frames: {}", audio.frames());
80 println!("\taudio.align: {}", audio.align());
81 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
82 }
83 }
84 }
85
86 Err(error) => println!("error: {}", error),
87 }
88 Ok(())
89}Sourcepub fn delay(&self) -> usize
pub fn delay(&self) -> usize
Examples found in repository?
examples/metadata.rs (line 53)
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 && let Ok(audio) = codec.decoder().audio()
72 {
73 println!("\tbit_rate: {}", audio.bit_rate());
74 println!("\tmax_rate: {}", audio.max_bit_rate());
75 println!("\tdelay: {}", audio.delay());
76 println!("\taudio.rate: {}", audio.rate());
77 println!("\taudio.channels: {}", audio.channels());
78 println!("\taudio.format: {:?}", audio.format());
79 println!("\taudio.frames: {}", audio.frames());
80 println!("\taudio.align: {}", audio.align());
81 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
82 }
83 }
84 }
85
86 Err(error) => println!("error: {}", error),
87 }
88 Ok(())
89}pub fn profile(&self) -> Profile
Sourcepub fn frame_rate(&self) -> Option<Rational>
pub fn frame_rate(&self) -> Option<Rational>
Examples found in repository?
examples/transcode-x264.rs (line 67)
43 fn new(
44 ist: &format::stream::Stream,
45 octx: &mut format::context::Output,
46 ost_index: usize,
47 x264_opts: Dictionary,
48 enable_logging: bool,
49 ) -> Result<Self, ffmpeg::Error> {
50 let global_header = octx.format().flags().contains(format::Flags::GLOBAL_HEADER);
51 let decoder = ffmpeg::codec::context::Context::from_parameters(ist.parameters())?
52 .decoder()
53 .video()?;
54
55 let codec = encoder::find(codec::Id::H264);
56 let mut ost = octx.add_stream(codec)?;
57
58 let mut encoder =
59 codec::context::Context::new_with_codec(codec.ok_or(ffmpeg::Error::InvalidData)?)
60 .encoder()
61 .video()?;
62 ost.set_parameters(&encoder);
63 encoder.set_height(decoder.height());
64 encoder.set_width(decoder.width());
65 encoder.set_aspect_ratio(decoder.aspect_ratio());
66 encoder.set_format(decoder.format());
67 encoder.set_frame_rate(decoder.frame_rate());
68 encoder.set_time_base(ist.time_base());
69
70 if global_header {
71 encoder.set_flags(codec::Flags::GLOBAL_HEADER);
72 }
73
74 let opened_encoder = encoder
75 .open_with(x264_opts)
76 .expect("error opening x264 with supplied settings");
77 ost.set_parameters(&opened_encoder);
78 Ok(Self {
79 ost_index,
80 decoder,
81 input_time_base: ist.time_base(),
82 encoder: opened_encoder,
83 logging_enabled: enable_logging,
84 frame_count: 0,
85 last_log_frame_count: 0,
86 starting_time: Instant::now(),
87 last_log_time: Instant::now(),
88 })
89 }pub fn flush(&mut self)
Methods from Deref<Target = Decoder>§
pub fn conceal(&mut self, value: Conceal)
pub fn check(&mut self, value: Check)
pub fn skip_loop_filter(&mut self, value: Discard)
pub fn skip_idct(&mut self, value: Discard)
pub fn skip_frame(&mut self, value: Discard)
pub fn packet_time_base(&self) -> Rational
pub fn set_packet_time_base<R: Into<Rational>>(&mut self, value: R)
Methods from Deref<Target = Context>§
pub unsafe fn as_ptr(&self) -> *const AVCodecContext
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVCodecContext
Sourcepub fn codec(&self) -> Option<Codec>
pub fn codec(&self) -> Option<Codec>
Examples found in repository?
examples/transcode-audio.rs (line 40)
9fn filter(
10 spec: &str,
11 decoder: &codec::decoder::Audio,
12 encoder: &codec::encoder::Audio,
13) -> Result<filter::Graph, ffmpeg::Error> {
14 let mut filter = filter::Graph::new();
15
16 let args = format!(
17 "time_base={}:sample_rate={}:sample_fmt={}:channel_layout=0x{:x}",
18 decoder.time_base(),
19 decoder.rate(),
20 decoder.format().name(),
21 decoder.channel_layout().bits()
22 );
23
24 filter.add(&filter::find("abuffer").unwrap(), "in", &args)?;
25 filter.add(&filter::find("abuffersink").unwrap(), "out", "")?;
26
27 {
28 let mut out = filter.get("out").unwrap();
29
30 out.set_sample_format(encoder.format());
31 out.set_channel_layout(encoder.channel_layout());
32 out.set_sample_rate(encoder.rate());
33 }
34
35 filter.output("in", 0)?.input("out", 0)?.parse(spec)?;
36 filter.validate()?;
37
38 println!("{}", filter.dump());
39
40 if let Some(codec) = encoder.codec()
41 && !codec
42 .capabilities()
43 .contains(ffmpeg::codec::capabilities::Capabilities::VARIABLE_FRAME_SIZE)
44 {
45 filter
46 .get("out")
47 .unwrap()
48 .sink()
49 .set_frame_size(encoder.frame_size());
50 }
51
52 Ok(filter)
53}Sourcepub fn medium(&self) -> Type
pub fn medium(&self) -> Type
Examples found in repository?
examples/metadata.rs (line 46)
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 && let Ok(audio) = codec.decoder().audio()
72 {
73 println!("\tbit_rate: {}", audio.bit_rate());
74 println!("\tmax_rate: {}", audio.max_bit_rate());
75 println!("\tdelay: {}", audio.delay());
76 println!("\taudio.rate: {}", audio.rate());
77 println!("\taudio.channels: {}", audio.channels());
78 println!("\taudio.format: {:?}", audio.format());
79 println!("\taudio.frames: {}", audio.frames());
80 println!("\taudio.align: {}", audio.align());
81 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
82 }
83 }
84 }
85
86 Err(error) => println!("error: {}", error),
87 }
88 Ok(())
89}Sourcepub fn set_flags(&mut self, value: Flags)
pub fn set_flags(&mut self, value: Flags)
Examples found in repository?
examples/transcode-x264.rs (line 71)
43 fn new(
44 ist: &format::stream::Stream,
45 octx: &mut format::context::Output,
46 ost_index: usize,
47 x264_opts: Dictionary,
48 enable_logging: bool,
49 ) -> Result<Self, ffmpeg::Error> {
50 let global_header = octx.format().flags().contains(format::Flags::GLOBAL_HEADER);
51 let decoder = ffmpeg::codec::context::Context::from_parameters(ist.parameters())?
52 .decoder()
53 .video()?;
54
55 let codec = encoder::find(codec::Id::H264);
56 let mut ost = octx.add_stream(codec)?;
57
58 let mut encoder =
59 codec::context::Context::new_with_codec(codec.ok_or(ffmpeg::Error::InvalidData)?)
60 .encoder()
61 .video()?;
62 ost.set_parameters(&encoder);
63 encoder.set_height(decoder.height());
64 encoder.set_width(decoder.width());
65 encoder.set_aspect_ratio(decoder.aspect_ratio());
66 encoder.set_format(decoder.format());
67 encoder.set_frame_rate(decoder.frame_rate());
68 encoder.set_time_base(ist.time_base());
69
70 if global_header {
71 encoder.set_flags(codec::Flags::GLOBAL_HEADER);
72 }
73
74 let opened_encoder = encoder
75 .open_with(x264_opts)
76 .expect("error opening x264 with supplied settings");
77 ost.set_parameters(&opened_encoder);
78 Ok(Self {
79 ost_index,
80 decoder,
81 input_time_base: ist.time_base(),
82 encoder: opened_encoder,
83 logging_enabled: enable_logging,
84 frame_count: 0,
85 last_log_frame_count: 0,
86 starting_time: Instant::now(),
87 last_log_time: Instant::now(),
88 })
89 }More examples
examples/transcode-audio.rs (line 96)
64fn transcoder<P: AsRef<Path> + ?Sized>(
65 ictx: &mut format::context::Input,
66 octx: &mut format::context::Output,
67 path: &P,
68 filter_spec: &str,
69) -> Result<Transcoder, ffmpeg::Error> {
70 let input = ictx
71 .streams()
72 .best(media::Type::Audio)
73 .expect("could not find best audio stream");
74 let context = ffmpeg::codec::context::Context::from_parameters(input.parameters())?;
75 let mut decoder = context.decoder().audio()?;
76 let codec = ffmpeg::encoder::find(octx.format().codec(path, media::Type::Audio))
77 .expect("failed to find encoder")
78 .audio()?;
79 let global = octx
80 .format()
81 .flags()
82 .contains(ffmpeg::format::flag::Flags::GLOBAL_HEADER);
83
84 decoder.set_parameters(input.parameters())?;
85
86 let mut output = octx.add_stream(codec)?;
87 let context = ffmpeg::codec::context::Context::from_parameters(output.parameters())?;
88 let mut encoder = context.encoder().audio()?;
89
90 let channel_layout = codec
91 .channel_layouts()
92 .map(|cls| cls.best(decoder.channel_layout().channels()))
93 .unwrap_or(ffmpeg::channel_layout::ChannelLayout::STEREO);
94
95 if global {
96 encoder.set_flags(ffmpeg::codec::flag::Flags::GLOBAL_HEADER);
97 }
98
99 encoder.set_rate(decoder.rate() as i32);
100 encoder.set_channel_layout(channel_layout);
101 #[cfg(not(feature = "ffmpeg_7_0"))]
102 {
103 encoder.set_channels(channel_layout.channels());
104 }
105 encoder.set_format(
106 codec
107 .formats()
108 .expect("unknown supported formats")
109 .next()
110 .unwrap(),
111 );
112 encoder.set_bit_rate(decoder.bit_rate());
113 encoder.set_max_bit_rate(decoder.max_bit_rate());
114
115 encoder.set_time_base((1, decoder.rate() as i32));
116 output.set_time_base((1, decoder.rate() as i32));
117
118 let encoder = encoder.open_as(codec)?;
119 output.set_parameters(&encoder);
120
121 let filter = filter(filter_spec, &decoder, &encoder)?;
122
123 let in_time_base = decoder.time_base();
124 let out_time_base = output.time_base();
125
126 Ok(Transcoder {
127 stream: input.index(),
128 filter,
129 decoder,
130 encoder,
131 in_time_base,
132 out_time_base,
133 })
134}Sourcepub fn id(&self) -> Id
pub fn id(&self) -> Id
Examples found in repository?
examples/metadata.rs (line 47)
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 && let Ok(audio) = codec.decoder().audio()
72 {
73 println!("\tbit_rate: {}", audio.bit_rate());
74 println!("\tmax_rate: {}", audio.max_bit_rate());
75 println!("\tdelay: {}", audio.delay());
76 println!("\taudio.rate: {}", audio.rate());
77 println!("\taudio.channels: {}", audio.channels());
78 println!("\taudio.format: {:?}", audio.format());
79 println!("\taudio.frames: {}", audio.frames());
80 println!("\taudio.align: {}", audio.align());
81 println!("\taudio.channel_layout: {:?}", audio.channel_layout());
82 }
83 }
84 }
85
86 Err(error) => println!("error: {}", error),
87 }
88 Ok(())
89}pub fn compliance(&mut self, value: Compliance)
pub fn debug(&mut self, value: Debug)
pub fn set_threading(&mut self, config: Config)
pub fn threading(&self) -> Config
Sourcepub fn set_parameters<P: Into<Parameters>>(
&mut self,
parameters: P,
) -> Result<(), Error>
pub fn set_parameters<P: Into<Parameters>>( &mut self, parameters: P, ) -> Result<(), Error>
Examples found in repository?
examples/transcode-audio.rs (line 84)
64fn transcoder<P: AsRef<Path> + ?Sized>(
65 ictx: &mut format::context::Input,
66 octx: &mut format::context::Output,
67 path: &P,
68 filter_spec: &str,
69) -> Result<Transcoder, ffmpeg::Error> {
70 let input = ictx
71 .streams()
72 .best(media::Type::Audio)
73 .expect("could not find best audio stream");
74 let context = ffmpeg::codec::context::Context::from_parameters(input.parameters())?;
75 let mut decoder = context.decoder().audio()?;
76 let codec = ffmpeg::encoder::find(octx.format().codec(path, media::Type::Audio))
77 .expect("failed to find encoder")
78 .audio()?;
79 let global = octx
80 .format()
81 .flags()
82 .contains(ffmpeg::format::flag::Flags::GLOBAL_HEADER);
83
84 decoder.set_parameters(input.parameters())?;
85
86 let mut output = octx.add_stream(codec)?;
87 let context = ffmpeg::codec::context::Context::from_parameters(output.parameters())?;
88 let mut encoder = context.encoder().audio()?;
89
90 let channel_layout = codec
91 .channel_layouts()
92 .map(|cls| cls.best(decoder.channel_layout().channels()))
93 .unwrap_or(ffmpeg::channel_layout::ChannelLayout::STEREO);
94
95 if global {
96 encoder.set_flags(ffmpeg::codec::flag::Flags::GLOBAL_HEADER);
97 }
98
99 encoder.set_rate(decoder.rate() as i32);
100 encoder.set_channel_layout(channel_layout);
101 #[cfg(not(feature = "ffmpeg_7_0"))]
102 {
103 encoder.set_channels(channel_layout.channels());
104 }
105 encoder.set_format(
106 codec
107 .formats()
108 .expect("unknown supported formats")
109 .next()
110 .unwrap(),
111 );
112 encoder.set_bit_rate(decoder.bit_rate());
113 encoder.set_max_bit_rate(decoder.max_bit_rate());
114
115 encoder.set_time_base((1, decoder.rate() as i32));
116 output.set_time_base((1, decoder.rate() as i32));
117
118 let encoder = encoder.open_as(codec)?;
119 output.set_parameters(&encoder);
120
121 let filter = filter(filter_spec, &decoder, &encoder)?;
122
123 let in_time_base = decoder.time_base();
124 let out_time_base = output.time_base();
125
126 Ok(Transcoder {
127 stream: input.index(),
128 filter,
129 decoder,
130 encoder,
131 in_time_base,
132 out_time_base,
133 })
134}Sourcepub fn time_base(&self) -> Rational
pub fn time_base(&self) -> Rational
Examples found in repository?
examples/transcode-audio.rs (line 18)
9fn filter(
10 spec: &str,
11 decoder: &codec::decoder::Audio,
12 encoder: &codec::encoder::Audio,
13) -> Result<filter::Graph, ffmpeg::Error> {
14 let mut filter = filter::Graph::new();
15
16 let args = format!(
17 "time_base={}:sample_rate={}:sample_fmt={}:channel_layout=0x{:x}",
18 decoder.time_base(),
19 decoder.rate(),
20 decoder.format().name(),
21 decoder.channel_layout().bits()
22 );
23
24 filter.add(&filter::find("abuffer").unwrap(), "in", &args)?;
25 filter.add(&filter::find("abuffersink").unwrap(), "out", "")?;
26
27 {
28 let mut out = filter.get("out").unwrap();
29
30 out.set_sample_format(encoder.format());
31 out.set_channel_layout(encoder.channel_layout());
32 out.set_sample_rate(encoder.rate());
33 }
34
35 filter.output("in", 0)?.input("out", 0)?.parse(spec)?;
36 filter.validate()?;
37
38 println!("{}", filter.dump());
39
40 if let Some(codec) = encoder.codec()
41 && !codec
42 .capabilities()
43 .contains(ffmpeg::codec::capabilities::Capabilities::VARIABLE_FRAME_SIZE)
44 {
45 filter
46 .get("out")
47 .unwrap()
48 .sink()
49 .set_frame_size(encoder.frame_size());
50 }
51
52 Ok(filter)
53}
54
55struct Transcoder {
56 stream: usize,
57 filter: filter::Graph,
58 decoder: codec::decoder::Audio,
59 encoder: codec::encoder::Audio,
60 in_time_base: ffmpeg::Rational,
61 out_time_base: ffmpeg::Rational,
62}
63
64fn transcoder<P: AsRef<Path> + ?Sized>(
65 ictx: &mut format::context::Input,
66 octx: &mut format::context::Output,
67 path: &P,
68 filter_spec: &str,
69) -> Result<Transcoder, ffmpeg::Error> {
70 let input = ictx
71 .streams()
72 .best(media::Type::Audio)
73 .expect("could not find best audio stream");
74 let context = ffmpeg::codec::context::Context::from_parameters(input.parameters())?;
75 let mut decoder = context.decoder().audio()?;
76 let codec = ffmpeg::encoder::find(octx.format().codec(path, media::Type::Audio))
77 .expect("failed to find encoder")
78 .audio()?;
79 let global = octx
80 .format()
81 .flags()
82 .contains(ffmpeg::format::flag::Flags::GLOBAL_HEADER);
83
84 decoder.set_parameters(input.parameters())?;
85
86 let mut output = octx.add_stream(codec)?;
87 let context = ffmpeg::codec::context::Context::from_parameters(output.parameters())?;
88 let mut encoder = context.encoder().audio()?;
89
90 let channel_layout = codec
91 .channel_layouts()
92 .map(|cls| cls.best(decoder.channel_layout().channels()))
93 .unwrap_or(ffmpeg::channel_layout::ChannelLayout::STEREO);
94
95 if global {
96 encoder.set_flags(ffmpeg::codec::flag::Flags::GLOBAL_HEADER);
97 }
98
99 encoder.set_rate(decoder.rate() as i32);
100 encoder.set_channel_layout(channel_layout);
101 #[cfg(not(feature = "ffmpeg_7_0"))]
102 {
103 encoder.set_channels(channel_layout.channels());
104 }
105 encoder.set_format(
106 codec
107 .formats()
108 .expect("unknown supported formats")
109 .next()
110 .unwrap(),
111 );
112 encoder.set_bit_rate(decoder.bit_rate());
113 encoder.set_max_bit_rate(decoder.max_bit_rate());
114
115 encoder.set_time_base((1, decoder.rate() as i32));
116 output.set_time_base((1, decoder.rate() as i32));
117
118 let encoder = encoder.open_as(codec)?;
119 output.set_parameters(&encoder);
120
121 let filter = filter(filter_spec, &decoder, &encoder)?;
122
123 let in_time_base = decoder.time_base();
124 let out_time_base = output.time_base();
125
126 Ok(Transcoder {
127 stream: input.index(),
128 filter,
129 decoder,
130 encoder,
131 in_time_base,
132 out_time_base,
133 })
134}Sourcepub fn set_time_base<R: Into<Rational>>(&mut self, value: R)
pub fn set_time_base<R: Into<Rational>>(&mut self, value: R)
Examples found in repository?
examples/transcode-x264.rs (line 68)
43 fn new(
44 ist: &format::stream::Stream,
45 octx: &mut format::context::Output,
46 ost_index: usize,
47 x264_opts: Dictionary,
48 enable_logging: bool,
49 ) -> Result<Self, ffmpeg::Error> {
50 let global_header = octx.format().flags().contains(format::Flags::GLOBAL_HEADER);
51 let decoder = ffmpeg::codec::context::Context::from_parameters(ist.parameters())?
52 .decoder()
53 .video()?;
54
55 let codec = encoder::find(codec::Id::H264);
56 let mut ost = octx.add_stream(codec)?;
57
58 let mut encoder =
59 codec::context::Context::new_with_codec(codec.ok_or(ffmpeg::Error::InvalidData)?)
60 .encoder()
61 .video()?;
62 ost.set_parameters(&encoder);
63 encoder.set_height(decoder.height());
64 encoder.set_width(decoder.width());
65 encoder.set_aspect_ratio(decoder.aspect_ratio());
66 encoder.set_format(decoder.format());
67 encoder.set_frame_rate(decoder.frame_rate());
68 encoder.set_time_base(ist.time_base());
69
70 if global_header {
71 encoder.set_flags(codec::Flags::GLOBAL_HEADER);
72 }
73
74 let opened_encoder = encoder
75 .open_with(x264_opts)
76 .expect("error opening x264 with supplied settings");
77 ost.set_parameters(&opened_encoder);
78 Ok(Self {
79 ost_index,
80 decoder,
81 input_time_base: ist.time_base(),
82 encoder: opened_encoder,
83 logging_enabled: enable_logging,
84 frame_count: 0,
85 last_log_frame_count: 0,
86 starting_time: Instant::now(),
87 last_log_time: Instant::now(),
88 })
89 }More examples
examples/transcode-audio.rs (line 115)
64fn transcoder<P: AsRef<Path> + ?Sized>(
65 ictx: &mut format::context::Input,
66 octx: &mut format::context::Output,
67 path: &P,
68 filter_spec: &str,
69) -> Result<Transcoder, ffmpeg::Error> {
70 let input = ictx
71 .streams()
72 .best(media::Type::Audio)
73 .expect("could not find best audio stream");
74 let context = ffmpeg::codec::context::Context::from_parameters(input.parameters())?;
75 let mut decoder = context.decoder().audio()?;
76 let codec = ffmpeg::encoder::find(octx.format().codec(path, media::Type::Audio))
77 .expect("failed to find encoder")
78 .audio()?;
79 let global = octx
80 .format()
81 .flags()
82 .contains(ffmpeg::format::flag::Flags::GLOBAL_HEADER);
83
84 decoder.set_parameters(input.parameters())?;
85
86 let mut output = octx.add_stream(codec)?;
87 let context = ffmpeg::codec::context::Context::from_parameters(output.parameters())?;
88 let mut encoder = context.encoder().audio()?;
89
90 let channel_layout = codec
91 .channel_layouts()
92 .map(|cls| cls.best(decoder.channel_layout().channels()))
93 .unwrap_or(ffmpeg::channel_layout::ChannelLayout::STEREO);
94
95 if global {
96 encoder.set_flags(ffmpeg::codec::flag::Flags::GLOBAL_HEADER);
97 }
98
99 encoder.set_rate(decoder.rate() as i32);
100 encoder.set_channel_layout(channel_layout);
101 #[cfg(not(feature = "ffmpeg_7_0"))]
102 {
103 encoder.set_channels(channel_layout.channels());
104 }
105 encoder.set_format(
106 codec
107 .formats()
108 .expect("unknown supported formats")
109 .next()
110 .unwrap(),
111 );
112 encoder.set_bit_rate(decoder.bit_rate());
113 encoder.set_max_bit_rate(decoder.max_bit_rate());
114
115 encoder.set_time_base((1, decoder.rate() as i32));
116 output.set_time_base((1, decoder.rate() as i32));
117
118 let encoder = encoder.open_as(codec)?;
119 output.set_parameters(&encoder);
120
121 let filter = filter(filter_spec, &decoder, &encoder)?;
122
123 let in_time_base = decoder.time_base();
124 let out_time_base = output.time_base();
125
126 Ok(Transcoder {
127 stream: input.index(),
128 filter,
129 decoder,
130 encoder,
131 in_time_base,
132 out_time_base,
133 })
134}pub fn frame_rate(&self) -> Rational
Sourcepub fn set_frame_rate<R: Into<Rational>>(&mut self, value: Option<R>)
pub fn set_frame_rate<R: Into<Rational>>(&mut self, value: Option<R>)
Examples found in repository?
examples/transcode-x264.rs (line 67)
43 fn new(
44 ist: &format::stream::Stream,
45 octx: &mut format::context::Output,
46 ost_index: usize,
47 x264_opts: Dictionary,
48 enable_logging: bool,
49 ) -> Result<Self, ffmpeg::Error> {
50 let global_header = octx.format().flags().contains(format::Flags::GLOBAL_HEADER);
51 let decoder = ffmpeg::codec::context::Context::from_parameters(ist.parameters())?
52 .decoder()
53 .video()?;
54
55 let codec = encoder::find(codec::Id::H264);
56 let mut ost = octx.add_stream(codec)?;
57
58 let mut encoder =
59 codec::context::Context::new_with_codec(codec.ok_or(ffmpeg::Error::InvalidData)?)
60 .encoder()
61 .video()?;
62 ost.set_parameters(&encoder);
63 encoder.set_height(decoder.height());
64 encoder.set_width(decoder.width());
65 encoder.set_aspect_ratio(decoder.aspect_ratio());
66 encoder.set_format(decoder.format());
67 encoder.set_frame_rate(decoder.frame_rate());
68 encoder.set_time_base(ist.time_base());
69
70 if global_header {
71 encoder.set_flags(codec::Flags::GLOBAL_HEADER);
72 }
73
74 let opened_encoder = encoder
75 .open_with(x264_opts)
76 .expect("error opening x264 with supplied settings");
77 ost.set_parameters(&opened_encoder);
78 Ok(Self {
79 ost_index,
80 decoder,
81 input_time_base: ist.time_base(),
82 encoder: opened_encoder,
83 logging_enabled: enable_logging,
84 frame_count: 0,
85 last_log_frame_count: 0,
86 starting_time: Instant::now(),
87 last_log_time: Instant::now(),
88 })
89 }Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Video
impl !Sync for Video
impl !UnwindSafe for Video
impl Freeze for Video
impl Send for Video
impl Unpin for Video
impl UnsafeUnpin for Video
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