Struct Video

Source
pub struct Video(pub Opened);

Tuple Fields§

§0: Opened

Implementations§

Source§

impl Video

Source

pub fn decode<P: Ref>( &mut self, packet: &P, out: &mut Video, ) -> Result<bool, Error>

Source

pub fn width(&self) -> u32

Examples found in repository?
examples/metadata.rs (line 54)
5fn main() {
6    ffmpeg::init().unwrap();
7
8    match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9        Ok(context) => {
10            for (k, v) in context.metadata().iter() {
11                println!("{}: {}", k, v);
12            }
13
14            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15                println!("Best video stream index: {}", stream.index());
16            }
17
18            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19                println!("Best audio stream index: {}", stream.index());
20            }
21
22            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23                println!("Best subtitle stream index: {}", stream.index());
24            }
25
26            println!(
27                "duration (seconds): {:.2}",
28                context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29            );
30
31            for stream in context.streams() {
32                println!("stream index {}:", stream.index());
33                println!("\ttime_base: {}", stream.time_base());
34                println!("\tstart_time: {}", stream.start_time());
35                println!("\tduration (stream timebase): {}", stream.duration());
36                println!(
37                    "\tduration (seconds): {:.2}",
38                    stream.duration() as f64 * f64::from(stream.time_base())
39                );
40                println!("\tframes: {}", stream.frames());
41                println!("\tdisposition: {:?}", stream.disposition());
42                println!("\tdiscard: {:?}", stream.discard());
43                println!("\trate: {}", stream.rate());
44
45                let codec = stream.codec();
46                println!("\tmedium: {:?}", codec.medium());
47                println!("\tid: {:?}", codec.id());
48
49                if codec.medium() == ffmpeg::media::Type::Video {
50                    if let Ok(video) = codec.decoder().video() {
51                        println!("\tbit_rate: {}", video.bit_rate());
52                        println!("\tmax_rate: {}", video.max_bit_rate());
53                        println!("\tdelay: {}", video.delay());
54                        println!("\tvideo.width: {}", video.width());
55                        println!("\tvideo.height: {}", video.height());
56                        println!("\tvideo.format: {:?}", video.format());
57                        println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58                        println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59                        println!("\tvideo.color_space: {:?}", video.color_space());
60                        println!("\tvideo.color_range: {:?}", video.color_range());
61                        println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62                        println!(
63                            "\tvideo.color_transfer_characteristic: {:?}",
64                            video.color_transfer_characteristic()
65                        );
66                        println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67                        println!("\tvideo.references: {}", video.references());
68                        println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69                    }
70                } else if codec.medium() == ffmpeg::media::Type::Audio {
71                    if let Ok(audio) = codec.decoder().audio() {
72                        println!("\tbit_rate: {}", audio.bit_rate());
73                        println!("\tmax_rate: {}", audio.max_bit_rate());
74                        println!("\tdelay: {}", audio.delay());
75                        println!("\taudio.rate: {}", audio.rate());
76                        println!("\taudio.channels: {}", audio.channels());
77                        println!("\taudio.format: {:?}", audio.format());
78                        println!("\taudio.frames: {}", audio.frames());
79                        println!("\taudio.align: {}", audio.align());
80                        println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81                        println!("\taudio.frame_start: {:?}", audio.frame_start());
82                    }
83                }
84            }
85        }
86
87        Err(error) => println!("error: {}", error),
88    }
89}
Source

pub fn height(&self) -> u32

Examples found in repository?
examples/metadata.rs (line 55)
5fn main() {
6    ffmpeg::init().unwrap();
7
8    match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9        Ok(context) => {
10            for (k, v) in context.metadata().iter() {
11                println!("{}: {}", k, v);
12            }
13
14            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15                println!("Best video stream index: {}", stream.index());
16            }
17
18            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19                println!("Best audio stream index: {}", stream.index());
20            }
21
22            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23                println!("Best subtitle stream index: {}", stream.index());
24            }
25
26            println!(
27                "duration (seconds): {:.2}",
28                context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29            );
30
31            for stream in context.streams() {
32                println!("stream index {}:", stream.index());
33                println!("\ttime_base: {}", stream.time_base());
34                println!("\tstart_time: {}", stream.start_time());
35                println!("\tduration (stream timebase): {}", stream.duration());
36                println!(
37                    "\tduration (seconds): {:.2}",
38                    stream.duration() as f64 * f64::from(stream.time_base())
39                );
40                println!("\tframes: {}", stream.frames());
41                println!("\tdisposition: {:?}", stream.disposition());
42                println!("\tdiscard: {:?}", stream.discard());
43                println!("\trate: {}", stream.rate());
44
45                let codec = stream.codec();
46                println!("\tmedium: {:?}", codec.medium());
47                println!("\tid: {:?}", codec.id());
48
49                if codec.medium() == ffmpeg::media::Type::Video {
50                    if let Ok(video) = codec.decoder().video() {
51                        println!("\tbit_rate: {}", video.bit_rate());
52                        println!("\tmax_rate: {}", video.max_bit_rate());
53                        println!("\tdelay: {}", video.delay());
54                        println!("\tvideo.width: {}", video.width());
55                        println!("\tvideo.height: {}", video.height());
56                        println!("\tvideo.format: {:?}", video.format());
57                        println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58                        println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59                        println!("\tvideo.color_space: {:?}", video.color_space());
60                        println!("\tvideo.color_range: {:?}", video.color_range());
61                        println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62                        println!(
63                            "\tvideo.color_transfer_characteristic: {:?}",
64                            video.color_transfer_characteristic()
65                        );
66                        println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67                        println!("\tvideo.references: {}", video.references());
68                        println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69                    }
70                } else if codec.medium() == ffmpeg::media::Type::Audio {
71                    if let Ok(audio) = codec.decoder().audio() {
72                        println!("\tbit_rate: {}", audio.bit_rate());
73                        println!("\tmax_rate: {}", audio.max_bit_rate());
74                        println!("\tdelay: {}", audio.delay());
75                        println!("\taudio.rate: {}", audio.rate());
76                        println!("\taudio.channels: {}", audio.channels());
77                        println!("\taudio.format: {:?}", audio.format());
78                        println!("\taudio.frames: {}", audio.frames());
79                        println!("\taudio.align: {}", audio.align());
80                        println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81                        println!("\taudio.frame_start: {:?}", audio.frame_start());
82                    }
83                }
84            }
85        }
86
87        Err(error) => println!("error: {}", error),
88    }
89}
Source

pub fn format(&self) -> Pixel

Examples found in repository?
examples/metadata.rs (line 56)
5fn main() {
6    ffmpeg::init().unwrap();
7
8    match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9        Ok(context) => {
10            for (k, v) in context.metadata().iter() {
11                println!("{}: {}", k, v);
12            }
13
14            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15                println!("Best video stream index: {}", stream.index());
16            }
17
18            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19                println!("Best audio stream index: {}", stream.index());
20            }
21
22            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23                println!("Best subtitle stream index: {}", stream.index());
24            }
25
26            println!(
27                "duration (seconds): {:.2}",
28                context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29            );
30
31            for stream in context.streams() {
32                println!("stream index {}:", stream.index());
33                println!("\ttime_base: {}", stream.time_base());
34                println!("\tstart_time: {}", stream.start_time());
35                println!("\tduration (stream timebase): {}", stream.duration());
36                println!(
37                    "\tduration (seconds): {:.2}",
38                    stream.duration() as f64 * f64::from(stream.time_base())
39                );
40                println!("\tframes: {}", stream.frames());
41                println!("\tdisposition: {:?}", stream.disposition());
42                println!("\tdiscard: {:?}", stream.discard());
43                println!("\trate: {}", stream.rate());
44
45                let codec = stream.codec();
46                println!("\tmedium: {:?}", codec.medium());
47                println!("\tid: {:?}", codec.id());
48
49                if codec.medium() == ffmpeg::media::Type::Video {
50                    if let Ok(video) = codec.decoder().video() {
51                        println!("\tbit_rate: {}", video.bit_rate());
52                        println!("\tmax_rate: {}", video.max_bit_rate());
53                        println!("\tdelay: {}", video.delay());
54                        println!("\tvideo.width: {}", video.width());
55                        println!("\tvideo.height: {}", video.height());
56                        println!("\tvideo.format: {:?}", video.format());
57                        println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58                        println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59                        println!("\tvideo.color_space: {:?}", video.color_space());
60                        println!("\tvideo.color_range: {:?}", video.color_range());
61                        println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62                        println!(
63                            "\tvideo.color_transfer_characteristic: {:?}",
64                            video.color_transfer_characteristic()
65                        );
66                        println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67                        println!("\tvideo.references: {}", video.references());
68                        println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69                    }
70                } else if codec.medium() == ffmpeg::media::Type::Audio {
71                    if let Ok(audio) = codec.decoder().audio() {
72                        println!("\tbit_rate: {}", audio.bit_rate());
73                        println!("\tmax_rate: {}", audio.max_bit_rate());
74                        println!("\tdelay: {}", audio.delay());
75                        println!("\taudio.rate: {}", audio.rate());
76                        println!("\taudio.channels: {}", audio.channels());
77                        println!("\taudio.format: {:?}", audio.format());
78                        println!("\taudio.frames: {}", audio.frames());
79                        println!("\taudio.align: {}", audio.align());
80                        println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81                        println!("\taudio.frame_start: {:?}", audio.frame_start());
82                    }
83                }
84            }
85        }
86
87        Err(error) => println!("error: {}", error),
88    }
89}
Source

pub fn has_b_frames(&self) -> bool

Examples found in repository?
examples/metadata.rs (line 57)
5fn main() {
6    ffmpeg::init().unwrap();
7
8    match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9        Ok(context) => {
10            for (k, v) in context.metadata().iter() {
11                println!("{}: {}", k, v);
12            }
13
14            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15                println!("Best video stream index: {}", stream.index());
16            }
17
18            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19                println!("Best audio stream index: {}", stream.index());
20            }
21
22            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23                println!("Best subtitle stream index: {}", stream.index());
24            }
25
26            println!(
27                "duration (seconds): {:.2}",
28                context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29            );
30
31            for stream in context.streams() {
32                println!("stream index {}:", stream.index());
33                println!("\ttime_base: {}", stream.time_base());
34                println!("\tstart_time: {}", stream.start_time());
35                println!("\tduration (stream timebase): {}", stream.duration());
36                println!(
37                    "\tduration (seconds): {:.2}",
38                    stream.duration() as f64 * f64::from(stream.time_base())
39                );
40                println!("\tframes: {}", stream.frames());
41                println!("\tdisposition: {:?}", stream.disposition());
42                println!("\tdiscard: {:?}", stream.discard());
43                println!("\trate: {}", stream.rate());
44
45                let codec = stream.codec();
46                println!("\tmedium: {:?}", codec.medium());
47                println!("\tid: {:?}", codec.id());
48
49                if codec.medium() == ffmpeg::media::Type::Video {
50                    if let Ok(video) = codec.decoder().video() {
51                        println!("\tbit_rate: {}", video.bit_rate());
52                        println!("\tmax_rate: {}", video.max_bit_rate());
53                        println!("\tdelay: {}", video.delay());
54                        println!("\tvideo.width: {}", video.width());
55                        println!("\tvideo.height: {}", video.height());
56                        println!("\tvideo.format: {:?}", video.format());
57                        println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58                        println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59                        println!("\tvideo.color_space: {:?}", video.color_space());
60                        println!("\tvideo.color_range: {:?}", video.color_range());
61                        println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62                        println!(
63                            "\tvideo.color_transfer_characteristic: {:?}",
64                            video.color_transfer_characteristic()
65                        );
66                        println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67                        println!("\tvideo.references: {}", video.references());
68                        println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69                    }
70                } else if codec.medium() == ffmpeg::media::Type::Audio {
71                    if let Ok(audio) = codec.decoder().audio() {
72                        println!("\tbit_rate: {}", audio.bit_rate());
73                        println!("\tmax_rate: {}", audio.max_bit_rate());
74                        println!("\tdelay: {}", audio.delay());
75                        println!("\taudio.rate: {}", audio.rate());
76                        println!("\taudio.channels: {}", audio.channels());
77                        println!("\taudio.format: {:?}", audio.format());
78                        println!("\taudio.frames: {}", audio.frames());
79                        println!("\taudio.align: {}", audio.align());
80                        println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81                        println!("\taudio.frame_start: {:?}", audio.frame_start());
82                    }
83                }
84            }
85        }
86
87        Err(error) => println!("error: {}", error),
88    }
89}
Source

pub fn aspect_ratio(&self) -> Rational

Examples found in repository?
examples/metadata.rs (line 58)
5fn main() {
6    ffmpeg::init().unwrap();
7
8    match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9        Ok(context) => {
10            for (k, v) in context.metadata().iter() {
11                println!("{}: {}", k, v);
12            }
13
14            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15                println!("Best video stream index: {}", stream.index());
16            }
17
18            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19                println!("Best audio stream index: {}", stream.index());
20            }
21
22            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23                println!("Best subtitle stream index: {}", stream.index());
24            }
25
26            println!(
27                "duration (seconds): {:.2}",
28                context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29            );
30
31            for stream in context.streams() {
32                println!("stream index {}:", stream.index());
33                println!("\ttime_base: {}", stream.time_base());
34                println!("\tstart_time: {}", stream.start_time());
35                println!("\tduration (stream timebase): {}", stream.duration());
36                println!(
37                    "\tduration (seconds): {:.2}",
38                    stream.duration() as f64 * f64::from(stream.time_base())
39                );
40                println!("\tframes: {}", stream.frames());
41                println!("\tdisposition: {:?}", stream.disposition());
42                println!("\tdiscard: {:?}", stream.discard());
43                println!("\trate: {}", stream.rate());
44
45                let codec = stream.codec();
46                println!("\tmedium: {:?}", codec.medium());
47                println!("\tid: {:?}", codec.id());
48
49                if codec.medium() == ffmpeg::media::Type::Video {
50                    if let Ok(video) = codec.decoder().video() {
51                        println!("\tbit_rate: {}", video.bit_rate());
52                        println!("\tmax_rate: {}", video.max_bit_rate());
53                        println!("\tdelay: {}", video.delay());
54                        println!("\tvideo.width: {}", video.width());
55                        println!("\tvideo.height: {}", video.height());
56                        println!("\tvideo.format: {:?}", video.format());
57                        println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58                        println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59                        println!("\tvideo.color_space: {:?}", video.color_space());
60                        println!("\tvideo.color_range: {:?}", video.color_range());
61                        println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62                        println!(
63                            "\tvideo.color_transfer_characteristic: {:?}",
64                            video.color_transfer_characteristic()
65                        );
66                        println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67                        println!("\tvideo.references: {}", video.references());
68                        println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69                    }
70                } else if codec.medium() == ffmpeg::media::Type::Audio {
71                    if let Ok(audio) = codec.decoder().audio() {
72                        println!("\tbit_rate: {}", audio.bit_rate());
73                        println!("\tmax_rate: {}", audio.max_bit_rate());
74                        println!("\tdelay: {}", audio.delay());
75                        println!("\taudio.rate: {}", audio.rate());
76                        println!("\taudio.channels: {}", audio.channels());
77                        println!("\taudio.format: {:?}", audio.format());
78                        println!("\taudio.frames: {}", audio.frames());
79                        println!("\taudio.align: {}", audio.align());
80                        println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81                        println!("\taudio.frame_start: {:?}", audio.frame_start());
82                    }
83                }
84            }
85        }
86
87        Err(error) => println!("error: {}", error),
88    }
89}
Source

pub fn color_space(&self) -> Space

Examples found in repository?
examples/metadata.rs (line 59)
5fn main() {
6    ffmpeg::init().unwrap();
7
8    match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9        Ok(context) => {
10            for (k, v) in context.metadata().iter() {
11                println!("{}: {}", k, v);
12            }
13
14            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15                println!("Best video stream index: {}", stream.index());
16            }
17
18            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19                println!("Best audio stream index: {}", stream.index());
20            }
21
22            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23                println!("Best subtitle stream index: {}", stream.index());
24            }
25
26            println!(
27                "duration (seconds): {:.2}",
28                context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29            );
30
31            for stream in context.streams() {
32                println!("stream index {}:", stream.index());
33                println!("\ttime_base: {}", stream.time_base());
34                println!("\tstart_time: {}", stream.start_time());
35                println!("\tduration (stream timebase): {}", stream.duration());
36                println!(
37                    "\tduration (seconds): {:.2}",
38                    stream.duration() as f64 * f64::from(stream.time_base())
39                );
40                println!("\tframes: {}", stream.frames());
41                println!("\tdisposition: {:?}", stream.disposition());
42                println!("\tdiscard: {:?}", stream.discard());
43                println!("\trate: {}", stream.rate());
44
45                let codec = stream.codec();
46                println!("\tmedium: {:?}", codec.medium());
47                println!("\tid: {:?}", codec.id());
48
49                if codec.medium() == ffmpeg::media::Type::Video {
50                    if let Ok(video) = codec.decoder().video() {
51                        println!("\tbit_rate: {}", video.bit_rate());
52                        println!("\tmax_rate: {}", video.max_bit_rate());
53                        println!("\tdelay: {}", video.delay());
54                        println!("\tvideo.width: {}", video.width());
55                        println!("\tvideo.height: {}", video.height());
56                        println!("\tvideo.format: {:?}", video.format());
57                        println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58                        println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59                        println!("\tvideo.color_space: {:?}", video.color_space());
60                        println!("\tvideo.color_range: {:?}", video.color_range());
61                        println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62                        println!(
63                            "\tvideo.color_transfer_characteristic: {:?}",
64                            video.color_transfer_characteristic()
65                        );
66                        println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67                        println!("\tvideo.references: {}", video.references());
68                        println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69                    }
70                } else if codec.medium() == ffmpeg::media::Type::Audio {
71                    if let Ok(audio) = codec.decoder().audio() {
72                        println!("\tbit_rate: {}", audio.bit_rate());
73                        println!("\tmax_rate: {}", audio.max_bit_rate());
74                        println!("\tdelay: {}", audio.delay());
75                        println!("\taudio.rate: {}", audio.rate());
76                        println!("\taudio.channels: {}", audio.channels());
77                        println!("\taudio.format: {:?}", audio.format());
78                        println!("\taudio.frames: {}", audio.frames());
79                        println!("\taudio.align: {}", audio.align());
80                        println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81                        println!("\taudio.frame_start: {:?}", audio.frame_start());
82                    }
83                }
84            }
85        }
86
87        Err(error) => println!("error: {}", error),
88    }
89}
Source

pub fn color_range(&self) -> Range

Examples found in repository?
examples/metadata.rs (line 60)
5fn main() {
6    ffmpeg::init().unwrap();
7
8    match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9        Ok(context) => {
10            for (k, v) in context.metadata().iter() {
11                println!("{}: {}", k, v);
12            }
13
14            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15                println!("Best video stream index: {}", stream.index());
16            }
17
18            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19                println!("Best audio stream index: {}", stream.index());
20            }
21
22            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23                println!("Best subtitle stream index: {}", stream.index());
24            }
25
26            println!(
27                "duration (seconds): {:.2}",
28                context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29            );
30
31            for stream in context.streams() {
32                println!("stream index {}:", stream.index());
33                println!("\ttime_base: {}", stream.time_base());
34                println!("\tstart_time: {}", stream.start_time());
35                println!("\tduration (stream timebase): {}", stream.duration());
36                println!(
37                    "\tduration (seconds): {:.2}",
38                    stream.duration() as f64 * f64::from(stream.time_base())
39                );
40                println!("\tframes: {}", stream.frames());
41                println!("\tdisposition: {:?}", stream.disposition());
42                println!("\tdiscard: {:?}", stream.discard());
43                println!("\trate: {}", stream.rate());
44
45                let codec = stream.codec();
46                println!("\tmedium: {:?}", codec.medium());
47                println!("\tid: {:?}", codec.id());
48
49                if codec.medium() == ffmpeg::media::Type::Video {
50                    if let Ok(video) = codec.decoder().video() {
51                        println!("\tbit_rate: {}", video.bit_rate());
52                        println!("\tmax_rate: {}", video.max_bit_rate());
53                        println!("\tdelay: {}", video.delay());
54                        println!("\tvideo.width: {}", video.width());
55                        println!("\tvideo.height: {}", video.height());
56                        println!("\tvideo.format: {:?}", video.format());
57                        println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58                        println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59                        println!("\tvideo.color_space: {:?}", video.color_space());
60                        println!("\tvideo.color_range: {:?}", video.color_range());
61                        println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62                        println!(
63                            "\tvideo.color_transfer_characteristic: {:?}",
64                            video.color_transfer_characteristic()
65                        );
66                        println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67                        println!("\tvideo.references: {}", video.references());
68                        println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69                    }
70                } else if codec.medium() == ffmpeg::media::Type::Audio {
71                    if let Ok(audio) = codec.decoder().audio() {
72                        println!("\tbit_rate: {}", audio.bit_rate());
73                        println!("\tmax_rate: {}", audio.max_bit_rate());
74                        println!("\tdelay: {}", audio.delay());
75                        println!("\taudio.rate: {}", audio.rate());
76                        println!("\taudio.channels: {}", audio.channels());
77                        println!("\taudio.format: {:?}", audio.format());
78                        println!("\taudio.frames: {}", audio.frames());
79                        println!("\taudio.align: {}", audio.align());
80                        println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81                        println!("\taudio.frame_start: {:?}", audio.frame_start());
82                    }
83                }
84            }
85        }
86
87        Err(error) => println!("error: {}", error),
88    }
89}
Source

pub fn color_primaries(&self) -> Primaries

Examples found in repository?
examples/metadata.rs (line 61)
5fn main() {
6    ffmpeg::init().unwrap();
7
8    match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9        Ok(context) => {
10            for (k, v) in context.metadata().iter() {
11                println!("{}: {}", k, v);
12            }
13
14            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15                println!("Best video stream index: {}", stream.index());
16            }
17
18            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19                println!("Best audio stream index: {}", stream.index());
20            }
21
22            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23                println!("Best subtitle stream index: {}", stream.index());
24            }
25
26            println!(
27                "duration (seconds): {:.2}",
28                context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29            );
30
31            for stream in context.streams() {
32                println!("stream index {}:", stream.index());
33                println!("\ttime_base: {}", stream.time_base());
34                println!("\tstart_time: {}", stream.start_time());
35                println!("\tduration (stream timebase): {}", stream.duration());
36                println!(
37                    "\tduration (seconds): {:.2}",
38                    stream.duration() as f64 * f64::from(stream.time_base())
39                );
40                println!("\tframes: {}", stream.frames());
41                println!("\tdisposition: {:?}", stream.disposition());
42                println!("\tdiscard: {:?}", stream.discard());
43                println!("\trate: {}", stream.rate());
44
45                let codec = stream.codec();
46                println!("\tmedium: {:?}", codec.medium());
47                println!("\tid: {:?}", codec.id());
48
49                if codec.medium() == ffmpeg::media::Type::Video {
50                    if let Ok(video) = codec.decoder().video() {
51                        println!("\tbit_rate: {}", video.bit_rate());
52                        println!("\tmax_rate: {}", video.max_bit_rate());
53                        println!("\tdelay: {}", video.delay());
54                        println!("\tvideo.width: {}", video.width());
55                        println!("\tvideo.height: {}", video.height());
56                        println!("\tvideo.format: {:?}", video.format());
57                        println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58                        println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59                        println!("\tvideo.color_space: {:?}", video.color_space());
60                        println!("\tvideo.color_range: {:?}", video.color_range());
61                        println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62                        println!(
63                            "\tvideo.color_transfer_characteristic: {:?}",
64                            video.color_transfer_characteristic()
65                        );
66                        println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67                        println!("\tvideo.references: {}", video.references());
68                        println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69                    }
70                } else if codec.medium() == ffmpeg::media::Type::Audio {
71                    if let Ok(audio) = codec.decoder().audio() {
72                        println!("\tbit_rate: {}", audio.bit_rate());
73                        println!("\tmax_rate: {}", audio.max_bit_rate());
74                        println!("\tdelay: {}", audio.delay());
75                        println!("\taudio.rate: {}", audio.rate());
76                        println!("\taudio.channels: {}", audio.channels());
77                        println!("\taudio.format: {:?}", audio.format());
78                        println!("\taudio.frames: {}", audio.frames());
79                        println!("\taudio.align: {}", audio.align());
80                        println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81                        println!("\taudio.frame_start: {:?}", audio.frame_start());
82                    }
83                }
84            }
85        }
86
87        Err(error) => println!("error: {}", error),
88    }
89}
Source

pub fn color_transfer_characteristic(&self) -> TransferCharacteristic

Examples found in repository?
examples/metadata.rs (line 64)
5fn main() {
6    ffmpeg::init().unwrap();
7
8    match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9        Ok(context) => {
10            for (k, v) in context.metadata().iter() {
11                println!("{}: {}", k, v);
12            }
13
14            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15                println!("Best video stream index: {}", stream.index());
16            }
17
18            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19                println!("Best audio stream index: {}", stream.index());
20            }
21
22            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23                println!("Best subtitle stream index: {}", stream.index());
24            }
25
26            println!(
27                "duration (seconds): {:.2}",
28                context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29            );
30
31            for stream in context.streams() {
32                println!("stream index {}:", stream.index());
33                println!("\ttime_base: {}", stream.time_base());
34                println!("\tstart_time: {}", stream.start_time());
35                println!("\tduration (stream timebase): {}", stream.duration());
36                println!(
37                    "\tduration (seconds): {:.2}",
38                    stream.duration() as f64 * f64::from(stream.time_base())
39                );
40                println!("\tframes: {}", stream.frames());
41                println!("\tdisposition: {:?}", stream.disposition());
42                println!("\tdiscard: {:?}", stream.discard());
43                println!("\trate: {}", stream.rate());
44
45                let codec = stream.codec();
46                println!("\tmedium: {:?}", codec.medium());
47                println!("\tid: {:?}", codec.id());
48
49                if codec.medium() == ffmpeg::media::Type::Video {
50                    if let Ok(video) = codec.decoder().video() {
51                        println!("\tbit_rate: {}", video.bit_rate());
52                        println!("\tmax_rate: {}", video.max_bit_rate());
53                        println!("\tdelay: {}", video.delay());
54                        println!("\tvideo.width: {}", video.width());
55                        println!("\tvideo.height: {}", video.height());
56                        println!("\tvideo.format: {:?}", video.format());
57                        println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58                        println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59                        println!("\tvideo.color_space: {:?}", video.color_space());
60                        println!("\tvideo.color_range: {:?}", video.color_range());
61                        println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62                        println!(
63                            "\tvideo.color_transfer_characteristic: {:?}",
64                            video.color_transfer_characteristic()
65                        );
66                        println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67                        println!("\tvideo.references: {}", video.references());
68                        println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69                    }
70                } else if codec.medium() == ffmpeg::media::Type::Audio {
71                    if let Ok(audio) = codec.decoder().audio() {
72                        println!("\tbit_rate: {}", audio.bit_rate());
73                        println!("\tmax_rate: {}", audio.max_bit_rate());
74                        println!("\tdelay: {}", audio.delay());
75                        println!("\taudio.rate: {}", audio.rate());
76                        println!("\taudio.channels: {}", audio.channels());
77                        println!("\taudio.format: {:?}", audio.format());
78                        println!("\taudio.frames: {}", audio.frames());
79                        println!("\taudio.align: {}", audio.align());
80                        println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81                        println!("\taudio.frame_start: {:?}", audio.frame_start());
82                    }
83                }
84            }
85        }
86
87        Err(error) => println!("error: {}", error),
88    }
89}
Source

pub fn chroma_location(&self) -> Location

Examples found in repository?
examples/metadata.rs (line 66)
5fn main() {
6    ffmpeg::init().unwrap();
7
8    match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9        Ok(context) => {
10            for (k, v) in context.metadata().iter() {
11                println!("{}: {}", k, v);
12            }
13
14            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15                println!("Best video stream index: {}", stream.index());
16            }
17
18            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19                println!("Best audio stream index: {}", stream.index());
20            }
21
22            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23                println!("Best subtitle stream index: {}", stream.index());
24            }
25
26            println!(
27                "duration (seconds): {:.2}",
28                context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29            );
30
31            for stream in context.streams() {
32                println!("stream index {}:", stream.index());
33                println!("\ttime_base: {}", stream.time_base());
34                println!("\tstart_time: {}", stream.start_time());
35                println!("\tduration (stream timebase): {}", stream.duration());
36                println!(
37                    "\tduration (seconds): {:.2}",
38                    stream.duration() as f64 * f64::from(stream.time_base())
39                );
40                println!("\tframes: {}", stream.frames());
41                println!("\tdisposition: {:?}", stream.disposition());
42                println!("\tdiscard: {:?}", stream.discard());
43                println!("\trate: {}", stream.rate());
44
45                let codec = stream.codec();
46                println!("\tmedium: {:?}", codec.medium());
47                println!("\tid: {:?}", codec.id());
48
49                if codec.medium() == ffmpeg::media::Type::Video {
50                    if let Ok(video) = codec.decoder().video() {
51                        println!("\tbit_rate: {}", video.bit_rate());
52                        println!("\tmax_rate: {}", video.max_bit_rate());
53                        println!("\tdelay: {}", video.delay());
54                        println!("\tvideo.width: {}", video.width());
55                        println!("\tvideo.height: {}", video.height());
56                        println!("\tvideo.format: {:?}", video.format());
57                        println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58                        println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59                        println!("\tvideo.color_space: {:?}", video.color_space());
60                        println!("\tvideo.color_range: {:?}", video.color_range());
61                        println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62                        println!(
63                            "\tvideo.color_transfer_characteristic: {:?}",
64                            video.color_transfer_characteristic()
65                        );
66                        println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67                        println!("\tvideo.references: {}", video.references());
68                        println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69                    }
70                } else if codec.medium() == ffmpeg::media::Type::Audio {
71                    if let Ok(audio) = codec.decoder().audio() {
72                        println!("\tbit_rate: {}", audio.bit_rate());
73                        println!("\tmax_rate: {}", audio.max_bit_rate());
74                        println!("\tdelay: {}", audio.delay());
75                        println!("\taudio.rate: {}", audio.rate());
76                        println!("\taudio.channels: {}", audio.channels());
77                        println!("\taudio.format: {:?}", audio.format());
78                        println!("\taudio.frames: {}", audio.frames());
79                        println!("\taudio.align: {}", audio.align());
80                        println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81                        println!("\taudio.frame_start: {:?}", audio.frame_start());
82                    }
83                }
84            }
85        }
86
87        Err(error) => println!("error: {}", error),
88    }
89}
Source

pub fn set_slice_count(&mut self, value: usize)

Source

pub fn set_slice_flags(&mut self, value: Flags)

Source

pub fn skip_top(&mut self, value: usize)

Source

pub fn skip_bottom(&mut self, value: usize)

Source

pub fn references(&self) -> usize

Examples found in repository?
examples/metadata.rs (line 67)
5fn main() {
6    ffmpeg::init().unwrap();
7
8    match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9        Ok(context) => {
10            for (k, v) in context.metadata().iter() {
11                println!("{}: {}", k, v);
12            }
13
14            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15                println!("Best video stream index: {}", stream.index());
16            }
17
18            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19                println!("Best audio stream index: {}", stream.index());
20            }
21
22            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23                println!("Best subtitle stream index: {}", stream.index());
24            }
25
26            println!(
27                "duration (seconds): {:.2}",
28                context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29            );
30
31            for stream in context.streams() {
32                println!("stream index {}:", stream.index());
33                println!("\ttime_base: {}", stream.time_base());
34                println!("\tstart_time: {}", stream.start_time());
35                println!("\tduration (stream timebase): {}", stream.duration());
36                println!(
37                    "\tduration (seconds): {:.2}",
38                    stream.duration() as f64 * f64::from(stream.time_base())
39                );
40                println!("\tframes: {}", stream.frames());
41                println!("\tdisposition: {:?}", stream.disposition());
42                println!("\tdiscard: {:?}", stream.discard());
43                println!("\trate: {}", stream.rate());
44
45                let codec = stream.codec();
46                println!("\tmedium: {:?}", codec.medium());
47                println!("\tid: {:?}", codec.id());
48
49                if codec.medium() == ffmpeg::media::Type::Video {
50                    if let Ok(video) = codec.decoder().video() {
51                        println!("\tbit_rate: {}", video.bit_rate());
52                        println!("\tmax_rate: {}", video.max_bit_rate());
53                        println!("\tdelay: {}", video.delay());
54                        println!("\tvideo.width: {}", video.width());
55                        println!("\tvideo.height: {}", video.height());
56                        println!("\tvideo.format: {:?}", video.format());
57                        println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58                        println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59                        println!("\tvideo.color_space: {:?}", video.color_space());
60                        println!("\tvideo.color_range: {:?}", video.color_range());
61                        println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62                        println!(
63                            "\tvideo.color_transfer_characteristic: {:?}",
64                            video.color_transfer_characteristic()
65                        );
66                        println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67                        println!("\tvideo.references: {}", video.references());
68                        println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69                    }
70                } else if codec.medium() == ffmpeg::media::Type::Audio {
71                    if let Ok(audio) = codec.decoder().audio() {
72                        println!("\tbit_rate: {}", audio.bit_rate());
73                        println!("\tmax_rate: {}", audio.max_bit_rate());
74                        println!("\tdelay: {}", audio.delay());
75                        println!("\taudio.rate: {}", audio.rate());
76                        println!("\taudio.channels: {}", audio.channels());
77                        println!("\taudio.format: {:?}", audio.format());
78                        println!("\taudio.frames: {}", audio.frames());
79                        println!("\taudio.align: {}", audio.align());
80                        println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81                        println!("\taudio.frame_start: {:?}", audio.frame_start());
82                    }
83                }
84            }
85        }
86
87        Err(error) => println!("error: {}", error),
88    }
89}
Source

pub fn set_field_order(&mut self, value: FieldOrder)

Source

pub fn intra_dc_precision(&self) -> u8

Examples found in repository?
examples/metadata.rs (line 68)
5fn main() {
6    ffmpeg::init().unwrap();
7
8    match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9        Ok(context) => {
10            for (k, v) in context.metadata().iter() {
11                println!("{}: {}", k, v);
12            }
13
14            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15                println!("Best video stream index: {}", stream.index());
16            }
17
18            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19                println!("Best audio stream index: {}", stream.index());
20            }
21
22            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23                println!("Best subtitle stream index: {}", stream.index());
24            }
25
26            println!(
27                "duration (seconds): {:.2}",
28                context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29            );
30
31            for stream in context.streams() {
32                println!("stream index {}:", stream.index());
33                println!("\ttime_base: {}", stream.time_base());
34                println!("\tstart_time: {}", stream.start_time());
35                println!("\tduration (stream timebase): {}", stream.duration());
36                println!(
37                    "\tduration (seconds): {:.2}",
38                    stream.duration() as f64 * f64::from(stream.time_base())
39                );
40                println!("\tframes: {}", stream.frames());
41                println!("\tdisposition: {:?}", stream.disposition());
42                println!("\tdiscard: {:?}", stream.discard());
43                println!("\trate: {}", stream.rate());
44
45                let codec = stream.codec();
46                println!("\tmedium: {:?}", codec.medium());
47                println!("\tid: {:?}", codec.id());
48
49                if codec.medium() == ffmpeg::media::Type::Video {
50                    if let Ok(video) = codec.decoder().video() {
51                        println!("\tbit_rate: {}", video.bit_rate());
52                        println!("\tmax_rate: {}", video.max_bit_rate());
53                        println!("\tdelay: {}", video.delay());
54                        println!("\tvideo.width: {}", video.width());
55                        println!("\tvideo.height: {}", video.height());
56                        println!("\tvideo.format: {:?}", video.format());
57                        println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58                        println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59                        println!("\tvideo.color_space: {:?}", video.color_space());
60                        println!("\tvideo.color_range: {:?}", video.color_range());
61                        println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62                        println!(
63                            "\tvideo.color_transfer_characteristic: {:?}",
64                            video.color_transfer_characteristic()
65                        );
66                        println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67                        println!("\tvideo.references: {}", video.references());
68                        println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69                    }
70                } else if codec.medium() == ffmpeg::media::Type::Audio {
71                    if let Ok(audio) = codec.decoder().audio() {
72                        println!("\tbit_rate: {}", audio.bit_rate());
73                        println!("\tmax_rate: {}", audio.max_bit_rate());
74                        println!("\tdelay: {}", audio.delay());
75                        println!("\taudio.rate: {}", audio.rate());
76                        println!("\taudio.channels: {}", audio.channels());
77                        println!("\taudio.format: {:?}", audio.format());
78                        println!("\taudio.frames: {}", audio.frames());
79                        println!("\taudio.align: {}", audio.align());
80                        println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81                        println!("\taudio.frame_start: {:?}", audio.frame_start());
82                    }
83                }
84            }
85        }
86
87        Err(error) => println!("error: {}", error),
88    }
89}
Source

pub fn max_bit_rate(&self) -> usize

Examples found in repository?
examples/metadata.rs (line 52)
5fn main() {
6    ffmpeg::init().unwrap();
7
8    match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9        Ok(context) => {
10            for (k, v) in context.metadata().iter() {
11                println!("{}: {}", k, v);
12            }
13
14            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15                println!("Best video stream index: {}", stream.index());
16            }
17
18            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19                println!("Best audio stream index: {}", stream.index());
20            }
21
22            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23                println!("Best subtitle stream index: {}", stream.index());
24            }
25
26            println!(
27                "duration (seconds): {:.2}",
28                context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29            );
30
31            for stream in context.streams() {
32                println!("stream index {}:", stream.index());
33                println!("\ttime_base: {}", stream.time_base());
34                println!("\tstart_time: {}", stream.start_time());
35                println!("\tduration (stream timebase): {}", stream.duration());
36                println!(
37                    "\tduration (seconds): {:.2}",
38                    stream.duration() as f64 * f64::from(stream.time_base())
39                );
40                println!("\tframes: {}", stream.frames());
41                println!("\tdisposition: {:?}", stream.disposition());
42                println!("\tdiscard: {:?}", stream.discard());
43                println!("\trate: {}", stream.rate());
44
45                let codec = stream.codec();
46                println!("\tmedium: {:?}", codec.medium());
47                println!("\tid: {:?}", codec.id());
48
49                if codec.medium() == ffmpeg::media::Type::Video {
50                    if let Ok(video) = codec.decoder().video() {
51                        println!("\tbit_rate: {}", video.bit_rate());
52                        println!("\tmax_rate: {}", video.max_bit_rate());
53                        println!("\tdelay: {}", video.delay());
54                        println!("\tvideo.width: {}", video.width());
55                        println!("\tvideo.height: {}", video.height());
56                        println!("\tvideo.format: {:?}", video.format());
57                        println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58                        println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59                        println!("\tvideo.color_space: {:?}", video.color_space());
60                        println!("\tvideo.color_range: {:?}", video.color_range());
61                        println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62                        println!(
63                            "\tvideo.color_transfer_characteristic: {:?}",
64                            video.color_transfer_characteristic()
65                        );
66                        println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67                        println!("\tvideo.references: {}", video.references());
68                        println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69                    }
70                } else if codec.medium() == ffmpeg::media::Type::Audio {
71                    if let Ok(audio) = codec.decoder().audio() {
72                        println!("\tbit_rate: {}", audio.bit_rate());
73                        println!("\tmax_rate: {}", audio.max_bit_rate());
74                        println!("\tdelay: {}", audio.delay());
75                        println!("\taudio.rate: {}", audio.rate());
76                        println!("\taudio.channels: {}", audio.channels());
77                        println!("\taudio.format: {:?}", audio.format());
78                        println!("\taudio.frames: {}", audio.frames());
79                        println!("\taudio.align: {}", audio.align());
80                        println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81                        println!("\taudio.frame_start: {:?}", audio.frame_start());
82                    }
83                }
84            }
85        }
86
87        Err(error) => println!("error: {}", error),
88    }
89}
Source§

impl Video

Source

pub fn scaler( &self, width: u32, height: u32, flags: Flags, ) -> Result<Context, Error>

Source

pub fn converter(&self, format: Pixel) -> Result<Context, Error>

Methods from Deref<Target = Opened>§

Source

pub fn bit_rate(&self) -> usize

Examples found in repository?
examples/transcode-audio.rs (line 106)
63fn transcoder<P: AsRef<Path>>(
64    ictx: &mut format::context::Input,
65    octx: &mut format::context::Output,
66    path: &P,
67    filter_spec: &str,
68) -> Result<Transcoder, ffmpeg::Error> {
69    let input = ictx
70        .streams()
71        .best(media::Type::Audio)
72        .expect("could not find best audio stream");
73    let mut decoder = input.codec().decoder().audio()?;
74    let codec = ffmpeg::encoder::find(octx.format().codec(path, media::Type::Audio))
75        .expect("failed to find encoder")
76        .audio()?;
77    let global = octx
78        .format()
79        .flags()
80        .contains(ffmpeg::format::flag::Flags::GLOBAL_HEADER);
81
82    decoder.set_parameters(input.parameters())?;
83
84    let mut output = octx.add_stream(codec)?;
85    let mut encoder = output.codec().encoder().audio()?;
86
87    let channel_layout = codec
88        .channel_layouts()
89        .map(|cls| cls.best(decoder.channel_layout().channels()))
90        .unwrap_or(ffmpeg::channel_layout::ChannelLayout::STEREO);
91
92    if global {
93        encoder.set_flags(ffmpeg::codec::flag::Flags::GLOBAL_HEADER);
94    }
95
96    encoder.set_rate(decoder.rate() as i32);
97    encoder.set_channel_layout(channel_layout);
98    encoder.set_channels(channel_layout.channels());
99    encoder.set_format(
100        codec
101            .formats()
102            .expect("unknown supported formats")
103            .next()
104            .unwrap(),
105    );
106    encoder.set_bit_rate(decoder.bit_rate());
107    encoder.set_max_bit_rate(decoder.max_bit_rate());
108
109    encoder.set_time_base((1, decoder.rate() as i32));
110    output.set_time_base((1, decoder.rate() as i32));
111
112    let encoder = encoder.open_as(codec)?;
113    output.set_parameters(&encoder);
114
115    let filter = filter(filter_spec, &decoder, &encoder)?;
116
117    Ok(Transcoder {
118        stream: input.index(),
119        filter: filter,
120        decoder: decoder,
121        encoder: encoder,
122    })
123}
More examples
Hide additional examples
examples/metadata.rs (line 51)
5fn main() {
6    ffmpeg::init().unwrap();
7
8    match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9        Ok(context) => {
10            for (k, v) in context.metadata().iter() {
11                println!("{}: {}", k, v);
12            }
13
14            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15                println!("Best video stream index: {}", stream.index());
16            }
17
18            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19                println!("Best audio stream index: {}", stream.index());
20            }
21
22            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23                println!("Best subtitle stream index: {}", stream.index());
24            }
25
26            println!(
27                "duration (seconds): {:.2}",
28                context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29            );
30
31            for stream in context.streams() {
32                println!("stream index {}:", stream.index());
33                println!("\ttime_base: {}", stream.time_base());
34                println!("\tstart_time: {}", stream.start_time());
35                println!("\tduration (stream timebase): {}", stream.duration());
36                println!(
37                    "\tduration (seconds): {:.2}",
38                    stream.duration() as f64 * f64::from(stream.time_base())
39                );
40                println!("\tframes: {}", stream.frames());
41                println!("\tdisposition: {:?}", stream.disposition());
42                println!("\tdiscard: {:?}", stream.discard());
43                println!("\trate: {}", stream.rate());
44
45                let codec = stream.codec();
46                println!("\tmedium: {:?}", codec.medium());
47                println!("\tid: {:?}", codec.id());
48
49                if codec.medium() == ffmpeg::media::Type::Video {
50                    if let Ok(video) = codec.decoder().video() {
51                        println!("\tbit_rate: {}", video.bit_rate());
52                        println!("\tmax_rate: {}", video.max_bit_rate());
53                        println!("\tdelay: {}", video.delay());
54                        println!("\tvideo.width: {}", video.width());
55                        println!("\tvideo.height: {}", video.height());
56                        println!("\tvideo.format: {:?}", video.format());
57                        println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58                        println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59                        println!("\tvideo.color_space: {:?}", video.color_space());
60                        println!("\tvideo.color_range: {:?}", video.color_range());
61                        println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62                        println!(
63                            "\tvideo.color_transfer_characteristic: {:?}",
64                            video.color_transfer_characteristic()
65                        );
66                        println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67                        println!("\tvideo.references: {}", video.references());
68                        println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69                    }
70                } else if codec.medium() == ffmpeg::media::Type::Audio {
71                    if let Ok(audio) = codec.decoder().audio() {
72                        println!("\tbit_rate: {}", audio.bit_rate());
73                        println!("\tmax_rate: {}", audio.max_bit_rate());
74                        println!("\tdelay: {}", audio.delay());
75                        println!("\taudio.rate: {}", audio.rate());
76                        println!("\taudio.channels: {}", audio.channels());
77                        println!("\taudio.format: {:?}", audio.format());
78                        println!("\taudio.frames: {}", audio.frames());
79                        println!("\taudio.align: {}", audio.align());
80                        println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81                        println!("\taudio.frame_start: {:?}", audio.frame_start());
82                    }
83                }
84            }
85        }
86
87        Err(error) => println!("error: {}", error),
88    }
89}
Source

pub fn delay(&self) -> usize

Examples found in repository?
examples/metadata.rs (line 53)
5fn main() {
6    ffmpeg::init().unwrap();
7
8    match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9        Ok(context) => {
10            for (k, v) in context.metadata().iter() {
11                println!("{}: {}", k, v);
12            }
13
14            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15                println!("Best video stream index: {}", stream.index());
16            }
17
18            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19                println!("Best audio stream index: {}", stream.index());
20            }
21
22            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23                println!("Best subtitle stream index: {}", stream.index());
24            }
25
26            println!(
27                "duration (seconds): {:.2}",
28                context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29            );
30
31            for stream in context.streams() {
32                println!("stream index {}:", stream.index());
33                println!("\ttime_base: {}", stream.time_base());
34                println!("\tstart_time: {}", stream.start_time());
35                println!("\tduration (stream timebase): {}", stream.duration());
36                println!(
37                    "\tduration (seconds): {:.2}",
38                    stream.duration() as f64 * f64::from(stream.time_base())
39                );
40                println!("\tframes: {}", stream.frames());
41                println!("\tdisposition: {:?}", stream.disposition());
42                println!("\tdiscard: {:?}", stream.discard());
43                println!("\trate: {}", stream.rate());
44
45                let codec = stream.codec();
46                println!("\tmedium: {:?}", codec.medium());
47                println!("\tid: {:?}", codec.id());
48
49                if codec.medium() == ffmpeg::media::Type::Video {
50                    if let Ok(video) = codec.decoder().video() {
51                        println!("\tbit_rate: {}", video.bit_rate());
52                        println!("\tmax_rate: {}", video.max_bit_rate());
53                        println!("\tdelay: {}", video.delay());
54                        println!("\tvideo.width: {}", video.width());
55                        println!("\tvideo.height: {}", video.height());
56                        println!("\tvideo.format: {:?}", video.format());
57                        println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58                        println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59                        println!("\tvideo.color_space: {:?}", video.color_space());
60                        println!("\tvideo.color_range: {:?}", video.color_range());
61                        println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62                        println!(
63                            "\tvideo.color_transfer_characteristic: {:?}",
64                            video.color_transfer_characteristic()
65                        );
66                        println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67                        println!("\tvideo.references: {}", video.references());
68                        println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69                    }
70                } else if codec.medium() == ffmpeg::media::Type::Audio {
71                    if let Ok(audio) = codec.decoder().audio() {
72                        println!("\tbit_rate: {}", audio.bit_rate());
73                        println!("\tmax_rate: {}", audio.max_bit_rate());
74                        println!("\tdelay: {}", audio.delay());
75                        println!("\taudio.rate: {}", audio.rate());
76                        println!("\taudio.channels: {}", audio.channels());
77                        println!("\taudio.format: {:?}", audio.format());
78                        println!("\taudio.frames: {}", audio.frames());
79                        println!("\taudio.align: {}", audio.align());
80                        println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81                        println!("\taudio.frame_start: {:?}", audio.frame_start());
82                    }
83                }
84            }
85        }
86
87        Err(error) => println!("error: {}", error),
88    }
89}
Source

pub fn profile(&self) -> Profile

Source

pub fn frame_rate(&self) -> Option<Rational>

Source

pub fn flush(&mut self)

Methods from Deref<Target = Decoder>§

Source

pub fn conceal(&mut self, value: Conceal)

Source

pub fn check(&mut self, value: Check)

Source

pub fn skip_loop_filter(&mut self, value: Discard)

Source

pub fn skip_idct(&mut self, value: Discard)

Source

pub fn skip_frame(&mut self, value: Discard)

Source

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        if !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
53    Ok(filter)
54}
55
56struct Transcoder {
57    stream: usize,
58    filter: filter::Graph,
59    decoder: codec::decoder::Audio,
60    encoder: codec::encoder::Audio,
61}
62
63fn transcoder<P: AsRef<Path>>(
64    ictx: &mut format::context::Input,
65    octx: &mut format::context::Output,
66    path: &P,
67    filter_spec: &str,
68) -> Result<Transcoder, ffmpeg::Error> {
69    let input = ictx
70        .streams()
71        .best(media::Type::Audio)
72        .expect("could not find best audio stream");
73    let mut decoder = input.codec().decoder().audio()?;
74    let codec = ffmpeg::encoder::find(octx.format().codec(path, media::Type::Audio))
75        .expect("failed to find encoder")
76        .audio()?;
77    let global = octx
78        .format()
79        .flags()
80        .contains(ffmpeg::format::flag::Flags::GLOBAL_HEADER);
81
82    decoder.set_parameters(input.parameters())?;
83
84    let mut output = octx.add_stream(codec)?;
85    let mut encoder = output.codec().encoder().audio()?;
86
87    let channel_layout = codec
88        .channel_layouts()
89        .map(|cls| cls.best(decoder.channel_layout().channels()))
90        .unwrap_or(ffmpeg::channel_layout::ChannelLayout::STEREO);
91
92    if global {
93        encoder.set_flags(ffmpeg::codec::flag::Flags::GLOBAL_HEADER);
94    }
95
96    encoder.set_rate(decoder.rate() as i32);
97    encoder.set_channel_layout(channel_layout);
98    encoder.set_channels(channel_layout.channels());
99    encoder.set_format(
100        codec
101            .formats()
102            .expect("unknown supported formats")
103            .next()
104            .unwrap(),
105    );
106    encoder.set_bit_rate(decoder.bit_rate());
107    encoder.set_max_bit_rate(decoder.max_bit_rate());
108
109    encoder.set_time_base((1, decoder.rate() as i32));
110    output.set_time_base((1, decoder.rate() as i32));
111
112    let encoder = encoder.open_as(codec)?;
113    output.set_parameters(&encoder);
114
115    let filter = filter(filter_spec, &decoder, &encoder)?;
116
117    Ok(Transcoder {
118        stream: input.index(),
119        filter: filter,
120        decoder: decoder,
121        encoder: encoder,
122    })
123}
124
125// Transcode the `best` audio stream of the input file into a the output file while applying a
126// given filter. If no filter was specified the stream gets copied (`anull` filter).
127//
128// Example 1: Transcode *.mp3 file to *.wmv while speeding it up
129// transcode-audio in.mp3 out.wmv "atempo=1.2"
130//
131// Example 2: Overlay an audio file
132// transcode-audio in.mp3 out.mp3 "amovie=overlay.mp3 [ov]; [in][ov] amerge [out]"
133//
134// Example 3: Seek to a specified position (in seconds)
135// transcode-audio in.mp3 out.mp3 anull 30
136fn main() {
137    ffmpeg::init().unwrap();
138
139    let input = env::args().nth(1).expect("missing input");
140    let output = env::args().nth(2).expect("missing output");
141    let filter = env::args().nth(3).unwrap_or_else(|| "anull".to_owned());
142    let seek = env::args().nth(4).and_then(|s| s.parse::<i64>().ok());
143
144    let mut ictx = format::input(&input).unwrap();
145    let mut octx = format::output(&output).unwrap();
146    let mut transcoder = transcoder(&mut ictx, &mut octx, &output, &filter).unwrap();
147
148    if let Some(position) = seek {
149        // If the position was given in seconds, rescale it to ffmpegs base timebase.
150        let position = position.rescale((1, 1), rescale::TIME_BASE);
151        // If this seek was embedded in the transcoding loop, a call of `flush()`
152        // for every opened buffer after the successful seek would be advisable.
153        ictx.seek(position, ..position).unwrap();
154    }
155
156    octx.set_metadata(ictx.metadata().to_owned());
157    octx.write_header().unwrap();
158
159    let in_time_base = transcoder.decoder.time_base();
160    let out_time_base = octx.stream(0).unwrap().time_base();
161
162    let mut decoded = frame::Audio::empty();
163    let mut encoded = ffmpeg::Packet::empty();
164
165    for (stream, mut packet) in ictx.packets() {
166        if stream.index() == transcoder.stream {
167            packet.rescale_ts(stream.time_base(), in_time_base);
168
169            if let Ok(true) = transcoder.decoder.decode(&packet, &mut decoded) {
170                let timestamp = decoded.timestamp();
171                decoded.set_pts(timestamp);
172
173                transcoder
174                    .filter
175                    .get("in")
176                    .unwrap()
177                    .source()
178                    .add(&decoded)
179                    .unwrap();
180
181                while let Ok(..) = transcoder
182                    .filter
183                    .get("out")
184                    .unwrap()
185                    .sink()
186                    .frame(&mut decoded)
187                {
188                    if let Ok(true) = transcoder.encoder.encode(&decoded, &mut encoded) {
189                        encoded.set_stream(0);
190                        encoded.rescale_ts(in_time_base, out_time_base);
191                        encoded.write_interleaved(&mut octx).unwrap();
192                    }
193                }
194            }
195        }
196    }
197
198    transcoder
199        .filter
200        .get("in")
201        .unwrap()
202        .source()
203        .flush()
204        .unwrap();
205
206    while let Ok(..) = transcoder
207        .filter
208        .get("out")
209        .unwrap()
210        .sink()
211        .frame(&mut decoded)
212    {
213        if let Ok(true) = transcoder.encoder.encode(&decoded, &mut encoded) {
214            encoded.set_stream(0);
215            encoded.rescale_ts(in_time_base, out_time_base);
216            encoded.write_interleaved(&mut octx).unwrap();
217        }
218    }
219
220    if let Ok(true) = transcoder.encoder.flush(&mut encoded) {
221        encoded.set_stream(0);
222        encoded.rescale_ts(in_time_base, out_time_base);
223        encoded.write_interleaved(&mut octx).unwrap();
224    }
225
226    octx.write_trailer().unwrap();
227}

Methods from Deref<Target = Context>§

Source

pub unsafe fn as_ptr(&self) -> *const AVCodecContext

Source

pub unsafe fn as_mut_ptr(&mut self) -> *mut AVCodecContext

Source

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        if !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
53    Ok(filter)
54}
Source

pub fn medium(&self) -> Type

Examples found in repository?
examples/metadata.rs (line 46)
5fn main() {
6    ffmpeg::init().unwrap();
7
8    match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9        Ok(context) => {
10            for (k, v) in context.metadata().iter() {
11                println!("{}: {}", k, v);
12            }
13
14            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15                println!("Best video stream index: {}", stream.index());
16            }
17
18            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19                println!("Best audio stream index: {}", stream.index());
20            }
21
22            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23                println!("Best subtitle stream index: {}", stream.index());
24            }
25
26            println!(
27                "duration (seconds): {:.2}",
28                context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29            );
30
31            for stream in context.streams() {
32                println!("stream index {}:", stream.index());
33                println!("\ttime_base: {}", stream.time_base());
34                println!("\tstart_time: {}", stream.start_time());
35                println!("\tduration (stream timebase): {}", stream.duration());
36                println!(
37                    "\tduration (seconds): {:.2}",
38                    stream.duration() as f64 * f64::from(stream.time_base())
39                );
40                println!("\tframes: {}", stream.frames());
41                println!("\tdisposition: {:?}", stream.disposition());
42                println!("\tdiscard: {:?}", stream.discard());
43                println!("\trate: {}", stream.rate());
44
45                let codec = stream.codec();
46                println!("\tmedium: {:?}", codec.medium());
47                println!("\tid: {:?}", codec.id());
48
49                if codec.medium() == ffmpeg::media::Type::Video {
50                    if let Ok(video) = codec.decoder().video() {
51                        println!("\tbit_rate: {}", video.bit_rate());
52                        println!("\tmax_rate: {}", video.max_bit_rate());
53                        println!("\tdelay: {}", video.delay());
54                        println!("\tvideo.width: {}", video.width());
55                        println!("\tvideo.height: {}", video.height());
56                        println!("\tvideo.format: {:?}", video.format());
57                        println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58                        println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59                        println!("\tvideo.color_space: {:?}", video.color_space());
60                        println!("\tvideo.color_range: {:?}", video.color_range());
61                        println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62                        println!(
63                            "\tvideo.color_transfer_characteristic: {:?}",
64                            video.color_transfer_characteristic()
65                        );
66                        println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67                        println!("\tvideo.references: {}", video.references());
68                        println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69                    }
70                } else if codec.medium() == ffmpeg::media::Type::Audio {
71                    if let Ok(audio) = codec.decoder().audio() {
72                        println!("\tbit_rate: {}", audio.bit_rate());
73                        println!("\tmax_rate: {}", audio.max_bit_rate());
74                        println!("\tdelay: {}", audio.delay());
75                        println!("\taudio.rate: {}", audio.rate());
76                        println!("\taudio.channels: {}", audio.channels());
77                        println!("\taudio.format: {:?}", audio.format());
78                        println!("\taudio.frames: {}", audio.frames());
79                        println!("\taudio.align: {}", audio.align());
80                        println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81                        println!("\taudio.frame_start: {:?}", audio.frame_start());
82                    }
83                }
84            }
85        }
86
87        Err(error) => println!("error: {}", error),
88    }
89}
Source

pub fn set_flags(&mut self, value: Flags)

Examples found in repository?
examples/transcode-audio.rs (line 93)
63fn transcoder<P: AsRef<Path>>(
64    ictx: &mut format::context::Input,
65    octx: &mut format::context::Output,
66    path: &P,
67    filter_spec: &str,
68) -> Result<Transcoder, ffmpeg::Error> {
69    let input = ictx
70        .streams()
71        .best(media::Type::Audio)
72        .expect("could not find best audio stream");
73    let mut decoder = input.codec().decoder().audio()?;
74    let codec = ffmpeg::encoder::find(octx.format().codec(path, media::Type::Audio))
75        .expect("failed to find encoder")
76        .audio()?;
77    let global = octx
78        .format()
79        .flags()
80        .contains(ffmpeg::format::flag::Flags::GLOBAL_HEADER);
81
82    decoder.set_parameters(input.parameters())?;
83
84    let mut output = octx.add_stream(codec)?;
85    let mut encoder = output.codec().encoder().audio()?;
86
87    let channel_layout = codec
88        .channel_layouts()
89        .map(|cls| cls.best(decoder.channel_layout().channels()))
90        .unwrap_or(ffmpeg::channel_layout::ChannelLayout::STEREO);
91
92    if global {
93        encoder.set_flags(ffmpeg::codec::flag::Flags::GLOBAL_HEADER);
94    }
95
96    encoder.set_rate(decoder.rate() as i32);
97    encoder.set_channel_layout(channel_layout);
98    encoder.set_channels(channel_layout.channels());
99    encoder.set_format(
100        codec
101            .formats()
102            .expect("unknown supported formats")
103            .next()
104            .unwrap(),
105    );
106    encoder.set_bit_rate(decoder.bit_rate());
107    encoder.set_max_bit_rate(decoder.max_bit_rate());
108
109    encoder.set_time_base((1, decoder.rate() as i32));
110    output.set_time_base((1, decoder.rate() as i32));
111
112    let encoder = encoder.open_as(codec)?;
113    output.set_parameters(&encoder);
114
115    let filter = filter(filter_spec, &decoder, &encoder)?;
116
117    Ok(Transcoder {
118        stream: input.index(),
119        filter: filter,
120        decoder: decoder,
121        encoder: encoder,
122    })
123}
Source

pub fn id(&self) -> Id

Examples found in repository?
examples/metadata.rs (line 47)
5fn main() {
6    ffmpeg::init().unwrap();
7
8    match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9        Ok(context) => {
10            for (k, v) in context.metadata().iter() {
11                println!("{}: {}", k, v);
12            }
13
14            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15                println!("Best video stream index: {}", stream.index());
16            }
17
18            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19                println!("Best audio stream index: {}", stream.index());
20            }
21
22            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23                println!("Best subtitle stream index: {}", stream.index());
24            }
25
26            println!(
27                "duration (seconds): {:.2}",
28                context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29            );
30
31            for stream in context.streams() {
32                println!("stream index {}:", stream.index());
33                println!("\ttime_base: {}", stream.time_base());
34                println!("\tstart_time: {}", stream.start_time());
35                println!("\tduration (stream timebase): {}", stream.duration());
36                println!(
37                    "\tduration (seconds): {:.2}",
38                    stream.duration() as f64 * f64::from(stream.time_base())
39                );
40                println!("\tframes: {}", stream.frames());
41                println!("\tdisposition: {:?}", stream.disposition());
42                println!("\tdiscard: {:?}", stream.discard());
43                println!("\trate: {}", stream.rate());
44
45                let codec = stream.codec();
46                println!("\tmedium: {:?}", codec.medium());
47                println!("\tid: {:?}", codec.id());
48
49                if codec.medium() == ffmpeg::media::Type::Video {
50                    if let Ok(video) = codec.decoder().video() {
51                        println!("\tbit_rate: {}", video.bit_rate());
52                        println!("\tmax_rate: {}", video.max_bit_rate());
53                        println!("\tdelay: {}", video.delay());
54                        println!("\tvideo.width: {}", video.width());
55                        println!("\tvideo.height: {}", video.height());
56                        println!("\tvideo.format: {:?}", video.format());
57                        println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58                        println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59                        println!("\tvideo.color_space: {:?}", video.color_space());
60                        println!("\tvideo.color_range: {:?}", video.color_range());
61                        println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62                        println!(
63                            "\tvideo.color_transfer_characteristic: {:?}",
64                            video.color_transfer_characteristic()
65                        );
66                        println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67                        println!("\tvideo.references: {}", video.references());
68                        println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69                    }
70                } else if codec.medium() == ffmpeg::media::Type::Audio {
71                    if let Ok(audio) = codec.decoder().audio() {
72                        println!("\tbit_rate: {}", audio.bit_rate());
73                        println!("\tmax_rate: {}", audio.max_bit_rate());
74                        println!("\tdelay: {}", audio.delay());
75                        println!("\taudio.rate: {}", audio.rate());
76                        println!("\taudio.channels: {}", audio.channels());
77                        println!("\taudio.format: {:?}", audio.format());
78                        println!("\taudio.frames: {}", audio.frames());
79                        println!("\taudio.align: {}", audio.align());
80                        println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81                        println!("\taudio.frame_start: {:?}", audio.frame_start());
82                    }
83                }
84            }
85        }
86
87        Err(error) => println!("error: {}", error),
88    }
89}
Source

pub fn compliance(&mut self, value: Compliance)

Source

pub fn debug(&mut self, value: Debug)

Source

pub fn set_threading(&mut self, config: Config)

Source

pub fn threading(&self) -> Config

Source

pub fn set_parameters<P: Into<Parameters>>( &mut self, parameters: P, ) -> Result<(), Error>

Examples found in repository?
examples/transcode-audio.rs (line 82)
63fn transcoder<P: AsRef<Path>>(
64    ictx: &mut format::context::Input,
65    octx: &mut format::context::Output,
66    path: &P,
67    filter_spec: &str,
68) -> Result<Transcoder, ffmpeg::Error> {
69    let input = ictx
70        .streams()
71        .best(media::Type::Audio)
72        .expect("could not find best audio stream");
73    let mut decoder = input.codec().decoder().audio()?;
74    let codec = ffmpeg::encoder::find(octx.format().codec(path, media::Type::Audio))
75        .expect("failed to find encoder")
76        .audio()?;
77    let global = octx
78        .format()
79        .flags()
80        .contains(ffmpeg::format::flag::Flags::GLOBAL_HEADER);
81
82    decoder.set_parameters(input.parameters())?;
83
84    let mut output = octx.add_stream(codec)?;
85    let mut encoder = output.codec().encoder().audio()?;
86
87    let channel_layout = codec
88        .channel_layouts()
89        .map(|cls| cls.best(decoder.channel_layout().channels()))
90        .unwrap_or(ffmpeg::channel_layout::ChannelLayout::STEREO);
91
92    if global {
93        encoder.set_flags(ffmpeg::codec::flag::Flags::GLOBAL_HEADER);
94    }
95
96    encoder.set_rate(decoder.rate() as i32);
97    encoder.set_channel_layout(channel_layout);
98    encoder.set_channels(channel_layout.channels());
99    encoder.set_format(
100        codec
101            .formats()
102            .expect("unknown supported formats")
103            .next()
104            .unwrap(),
105    );
106    encoder.set_bit_rate(decoder.bit_rate());
107    encoder.set_max_bit_rate(decoder.max_bit_rate());
108
109    encoder.set_time_base((1, decoder.rate() as i32));
110    output.set_time_base((1, decoder.rate() as i32));
111
112    let encoder = encoder.open_as(codec)?;
113    output.set_parameters(&encoder);
114
115    let filter = filter(filter_spec, &decoder, &encoder)?;
116
117    Ok(Transcoder {
118        stream: input.index(),
119        filter: filter,
120        decoder: decoder,
121        encoder: encoder,
122    })
123}

Trait Implementations§

Source§

impl AsMut<Context> for Video

Source§

fn as_mut(&mut self) -> &mut Context

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<Context> for Video

Source§

fn as_ref(&self) -> &Context

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Deref for Video

Source§

type Target = Opened

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<Self as Deref>::Target

Dereferences the value.
Source§

impl DerefMut for Video

Source§

fn deref_mut(&mut self) -> &mut <Self as Deref>::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl Freeze for Video

§

impl !RefUnwindSafe for Video

§

impl Send for Video

§

impl !Sync for Video

§

impl Unpin for Video

§

impl !UnwindSafe for Video

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.