pub struct CodecParameters { /* private fields */ }Implementations§
Source§impl CodecParameters
impl CodecParameters
pub fn new() -> Option<CodecParameters>
pub fn codec_type(&self) -> AVMediaType
Sourcepub fn codec_id(&self) -> AVCodecID
pub fn codec_id(&self) -> AVCodecID
Examples found in repository?
examples/decode_frame.rs (line 39)
11fn main() {
12 let url = if let Some(url) = std::env::args().skip(1).next() {
13 url
14 } else {
15 eprintln!("No input file!");
16 std::process::exit(1);
17 };
18
19 let mut format_context = FormatContext::open_input(&url).expect("Failed to open file!");
20
21 format_context.find_stream_info();
22
23 for i in format_context.streams() {
24 println!("{i:#?}");
25 }
26
27 let video_stream = format_context
28 .streams()
29 .filter(|x| x.codec_parameters().is_video())
30 .next()
31 .expect("Failed to find a video stream");
32
33 println!("CodecParams idx: {}", video_stream.index());
34 println!(
35 "CodecParams format: {}",
36 video_stream.codec_parameters().format()
37 );
38
39 let mut codec = CodecContext::from_decoder_id(video_stream.codec_parameters().codec_id())
40 .expect("Failed to create CodecContext");
41
42 codec.fill_from_parameters(&video_stream.codec_parameters());
43
44 codec.open(None).unwrap();
45
46 println!("Pixel format: {}", codec.get_pixel_format());
47
48 format_context.seek_msec(video_stream.index(), 4 * 60 * 1000);
49
50 let mut packet = Packet::new();
51
52 while format_context.read_frame(&mut packet) >= 0 {
53 println!("{}", packet.stream_index());
54
55 if packet.stream_index() == video_stream.index() {
56 codec.send_packet(&packet);
57
58 let mut frame = Frame::empty().expect("Failed to allocate a frame");
59
60 while codec.receive_frame(&mut frame) >= 0 {
61 println!("{}", frame.format());
62 {
63 let (width, height) = video_stream.codec_parameters().size();
64 println!("{width} x {height}");
65
66 let mut new_frame =
67 Frame::from_size_and_pixfmt(width, height, AVPixelFormat_AV_PIX_FMT_RGB24)
68 .unwrap();
69
70 let sws = Sws::new(
71 width,
72 height,
73 video_stream.codec_parameters().format(),
74 width,
75 height,
76 AVPixelFormat_AV_PIX_FMT_RGB24,
77 SWS_BILINEAR as _,
78 );
79
80 println!("{:?} {:?}", frame.linesize(), new_frame.linesize());
81
82 sws.scale(&frame, &mut new_frame);
83
84 let mut file = std::fs::OpenOptions::new()
85 .create(true)
86 .truncate(true)
87 .write(true)
88 .open("data.bin")
89 .unwrap();
90
91 file.write(new_frame.data_plane(0).unwrap()).unwrap();
92 }
93 }
94
95 break;
96 }
97 }
98
99 println!("Exit!");
100}Sourcepub fn codec_name(&self) -> &str
pub fn codec_name(&self) -> &str
Examples found in repository?
examples/dump_info.rs (line 25)
10fn main() {
11 let url = if let Some(url) = std::env::args().skip(1).next() {
12 url
13 } else {
14 eprintln!("No input file!");
15 std::process::exit(1);
16 };
17
18 let mut format_context = FormatContext::open_input(&url).expect("Failed to open file!");
19
20 format_context.find_stream_info();
21
22 for i in format_context.streams() {
23 let index = i.index();
24 let parameters = i.codec_parameters();
25 let name = parameters.codec_name();
26 let duration_ms = (i.duration_sec() * 1000.0) as i64;
27
28 let (hr, min, sec, msec) = {
29 const HOUR: i64 = 3600 * 1000;
30
31 (
32 duration_ms / HOUR,
33 (duration_ms % HOUR) / (60 * 1000),
34 (duration_ms % (60 * 1000)) / 1000,
35 duration_ms % 1000,
36 )
37 };
38
39 let s_type = if parameters.is_audio() {
40 "audio"
41 } else if parameters.is_video() {
42 "video"
43 } else {
44 "other"
45 };
46
47 println!("Stream #{index}: {s_type}, {name}, ({hr:02}:{min:02}:{sec:02}:{msec:03})");
48
49 if parameters.is_video() {
50 let (width, height) = parameters.size();
51 let bps = parameters.bitrate();
52
53 println!(" |- size: {width} x {height}; {bps} bps");
54 } else if parameters.is_audio() {
55 let bps = parameters.bitrate();
56
57 println!(" |- {bps} bps");
58
59 }
60 }
61}Sourcepub fn bitrate(&self) -> i64
pub fn bitrate(&self) -> i64
Examples found in repository?
examples/dump_info.rs (line 51)
10fn main() {
11 let url = if let Some(url) = std::env::args().skip(1).next() {
12 url
13 } else {
14 eprintln!("No input file!");
15 std::process::exit(1);
16 };
17
18 let mut format_context = FormatContext::open_input(&url).expect("Failed to open file!");
19
20 format_context.find_stream_info();
21
22 for i in format_context.streams() {
23 let index = i.index();
24 let parameters = i.codec_parameters();
25 let name = parameters.codec_name();
26 let duration_ms = (i.duration_sec() * 1000.0) as i64;
27
28 let (hr, min, sec, msec) = {
29 const HOUR: i64 = 3600 * 1000;
30
31 (
32 duration_ms / HOUR,
33 (duration_ms % HOUR) / (60 * 1000),
34 (duration_ms % (60 * 1000)) / 1000,
35 duration_ms % 1000,
36 )
37 };
38
39 let s_type = if parameters.is_audio() {
40 "audio"
41 } else if parameters.is_video() {
42 "video"
43 } else {
44 "other"
45 };
46
47 println!("Stream #{index}: {s_type}, {name}, ({hr:02}:{min:02}:{sec:02}:{msec:03})");
48
49 if parameters.is_video() {
50 let (width, height) = parameters.size();
51 let bps = parameters.bitrate();
52
53 println!(" |- size: {width} x {height}; {bps} bps");
54 } else if parameters.is_audio() {
55 let bps = parameters.bitrate();
56
57 println!(" |- {bps} bps");
58
59 }
60 }
61}Sourcepub fn size(&self) -> (i32, i32)
pub fn size(&self) -> (i32, i32)
Examples found in repository?
examples/dump_info.rs (line 50)
10fn main() {
11 let url = if let Some(url) = std::env::args().skip(1).next() {
12 url
13 } else {
14 eprintln!("No input file!");
15 std::process::exit(1);
16 };
17
18 let mut format_context = FormatContext::open_input(&url).expect("Failed to open file!");
19
20 format_context.find_stream_info();
21
22 for i in format_context.streams() {
23 let index = i.index();
24 let parameters = i.codec_parameters();
25 let name = parameters.codec_name();
26 let duration_ms = (i.duration_sec() * 1000.0) as i64;
27
28 let (hr, min, sec, msec) = {
29 const HOUR: i64 = 3600 * 1000;
30
31 (
32 duration_ms / HOUR,
33 (duration_ms % HOUR) / (60 * 1000),
34 (duration_ms % (60 * 1000)) / 1000,
35 duration_ms % 1000,
36 )
37 };
38
39 let s_type = if parameters.is_audio() {
40 "audio"
41 } else if parameters.is_video() {
42 "video"
43 } else {
44 "other"
45 };
46
47 println!("Stream #{index}: {s_type}, {name}, ({hr:02}:{min:02}:{sec:02}:{msec:03})");
48
49 if parameters.is_video() {
50 let (width, height) = parameters.size();
51 let bps = parameters.bitrate();
52
53 println!(" |- size: {width} x {height}; {bps} bps");
54 } else if parameters.is_audio() {
55 let bps = parameters.bitrate();
56
57 println!(" |- {bps} bps");
58
59 }
60 }
61}More examples
examples/decode_frame.rs (line 63)
11fn main() {
12 let url = if let Some(url) = std::env::args().skip(1).next() {
13 url
14 } else {
15 eprintln!("No input file!");
16 std::process::exit(1);
17 };
18
19 let mut format_context = FormatContext::open_input(&url).expect("Failed to open file!");
20
21 format_context.find_stream_info();
22
23 for i in format_context.streams() {
24 println!("{i:#?}");
25 }
26
27 let video_stream = format_context
28 .streams()
29 .filter(|x| x.codec_parameters().is_video())
30 .next()
31 .expect("Failed to find a video stream");
32
33 println!("CodecParams idx: {}", video_stream.index());
34 println!(
35 "CodecParams format: {}",
36 video_stream.codec_parameters().format()
37 );
38
39 let mut codec = CodecContext::from_decoder_id(video_stream.codec_parameters().codec_id())
40 .expect("Failed to create CodecContext");
41
42 codec.fill_from_parameters(&video_stream.codec_parameters());
43
44 codec.open(None).unwrap();
45
46 println!("Pixel format: {}", codec.get_pixel_format());
47
48 format_context.seek_msec(video_stream.index(), 4 * 60 * 1000);
49
50 let mut packet = Packet::new();
51
52 while format_context.read_frame(&mut packet) >= 0 {
53 println!("{}", packet.stream_index());
54
55 if packet.stream_index() == video_stream.index() {
56 codec.send_packet(&packet);
57
58 let mut frame = Frame::empty().expect("Failed to allocate a frame");
59
60 while codec.receive_frame(&mut frame) >= 0 {
61 println!("{}", frame.format());
62 {
63 let (width, height) = video_stream.codec_parameters().size();
64 println!("{width} x {height}");
65
66 let mut new_frame =
67 Frame::from_size_and_pixfmt(width, height, AVPixelFormat_AV_PIX_FMT_RGB24)
68 .unwrap();
69
70 let sws = Sws::new(
71 width,
72 height,
73 video_stream.codec_parameters().format(),
74 width,
75 height,
76 AVPixelFormat_AV_PIX_FMT_RGB24,
77 SWS_BILINEAR as _,
78 );
79
80 println!("{:?} {:?}", frame.linesize(), new_frame.linesize());
81
82 sws.scale(&frame, &mut new_frame);
83
84 let mut file = std::fs::OpenOptions::new()
85 .create(true)
86 .truncate(true)
87 .write(true)
88 .open("data.bin")
89 .unwrap();
90
91 file.write(new_frame.data_plane(0).unwrap()).unwrap();
92 }
93 }
94
95 break;
96 }
97 }
98
99 println!("Exit!");
100}pub fn aspect_ratio(&self) -> AVRational
pub fn framerate(&self) -> AVRational
pub fn color_range(&self) -> AVColorRange
Sourcepub fn format(&self) -> i32
pub fn format(&self) -> i32
Examples found in repository?
examples/decode_frame.rs (line 36)
11fn main() {
12 let url = if let Some(url) = std::env::args().skip(1).next() {
13 url
14 } else {
15 eprintln!("No input file!");
16 std::process::exit(1);
17 };
18
19 let mut format_context = FormatContext::open_input(&url).expect("Failed to open file!");
20
21 format_context.find_stream_info();
22
23 for i in format_context.streams() {
24 println!("{i:#?}");
25 }
26
27 let video_stream = format_context
28 .streams()
29 .filter(|x| x.codec_parameters().is_video())
30 .next()
31 .expect("Failed to find a video stream");
32
33 println!("CodecParams idx: {}", video_stream.index());
34 println!(
35 "CodecParams format: {}",
36 video_stream.codec_parameters().format()
37 );
38
39 let mut codec = CodecContext::from_decoder_id(video_stream.codec_parameters().codec_id())
40 .expect("Failed to create CodecContext");
41
42 codec.fill_from_parameters(&video_stream.codec_parameters());
43
44 codec.open(None).unwrap();
45
46 println!("Pixel format: {}", codec.get_pixel_format());
47
48 format_context.seek_msec(video_stream.index(), 4 * 60 * 1000);
49
50 let mut packet = Packet::new();
51
52 while format_context.read_frame(&mut packet) >= 0 {
53 println!("{}", packet.stream_index());
54
55 if packet.stream_index() == video_stream.index() {
56 codec.send_packet(&packet);
57
58 let mut frame = Frame::empty().expect("Failed to allocate a frame");
59
60 while codec.receive_frame(&mut frame) >= 0 {
61 println!("{}", frame.format());
62 {
63 let (width, height) = video_stream.codec_parameters().size();
64 println!("{width} x {height}");
65
66 let mut new_frame =
67 Frame::from_size_and_pixfmt(width, height, AVPixelFormat_AV_PIX_FMT_RGB24)
68 .unwrap();
69
70 let sws = Sws::new(
71 width,
72 height,
73 video_stream.codec_parameters().format(),
74 width,
75 height,
76 AVPixelFormat_AV_PIX_FMT_RGB24,
77 SWS_BILINEAR as _,
78 );
79
80 println!("{:?} {:?}", frame.linesize(), new_frame.linesize());
81
82 sws.scale(&frame, &mut new_frame);
83
84 let mut file = std::fs::OpenOptions::new()
85 .create(true)
86 .truncate(true)
87 .write(true)
88 .open("data.bin")
89 .unwrap();
90
91 file.write(new_frame.data_plane(0).unwrap()).unwrap();
92 }
93 }
94
95 break;
96 }
97 }
98
99 println!("Exit!");
100}pub fn sample_rate(&self) -> Option<i32>
Sourcepub fn is_audio(&self) -> bool
pub fn is_audio(&self) -> bool
Examples found in repository?
examples/dump_info.rs (line 39)
10fn main() {
11 let url = if let Some(url) = std::env::args().skip(1).next() {
12 url
13 } else {
14 eprintln!("No input file!");
15 std::process::exit(1);
16 };
17
18 let mut format_context = FormatContext::open_input(&url).expect("Failed to open file!");
19
20 format_context.find_stream_info();
21
22 for i in format_context.streams() {
23 let index = i.index();
24 let parameters = i.codec_parameters();
25 let name = parameters.codec_name();
26 let duration_ms = (i.duration_sec() * 1000.0) as i64;
27
28 let (hr, min, sec, msec) = {
29 const HOUR: i64 = 3600 * 1000;
30
31 (
32 duration_ms / HOUR,
33 (duration_ms % HOUR) / (60 * 1000),
34 (duration_ms % (60 * 1000)) / 1000,
35 duration_ms % 1000,
36 )
37 };
38
39 let s_type = if parameters.is_audio() {
40 "audio"
41 } else if parameters.is_video() {
42 "video"
43 } else {
44 "other"
45 };
46
47 println!("Stream #{index}: {s_type}, {name}, ({hr:02}:{min:02}:{sec:02}:{msec:03})");
48
49 if parameters.is_video() {
50 let (width, height) = parameters.size();
51 let bps = parameters.bitrate();
52
53 println!(" |- size: {width} x {height}; {bps} bps");
54 } else if parameters.is_audio() {
55 let bps = parameters.bitrate();
56
57 println!(" |- {bps} bps");
58
59 }
60 }
61}Sourcepub fn is_video(&self) -> bool
pub fn is_video(&self) -> bool
Examples found in repository?
examples/dump_info.rs (line 41)
10fn main() {
11 let url = if let Some(url) = std::env::args().skip(1).next() {
12 url
13 } else {
14 eprintln!("No input file!");
15 std::process::exit(1);
16 };
17
18 let mut format_context = FormatContext::open_input(&url).expect("Failed to open file!");
19
20 format_context.find_stream_info();
21
22 for i in format_context.streams() {
23 let index = i.index();
24 let parameters = i.codec_parameters();
25 let name = parameters.codec_name();
26 let duration_ms = (i.duration_sec() * 1000.0) as i64;
27
28 let (hr, min, sec, msec) = {
29 const HOUR: i64 = 3600 * 1000;
30
31 (
32 duration_ms / HOUR,
33 (duration_ms % HOUR) / (60 * 1000),
34 (duration_ms % (60 * 1000)) / 1000,
35 duration_ms % 1000,
36 )
37 };
38
39 let s_type = if parameters.is_audio() {
40 "audio"
41 } else if parameters.is_video() {
42 "video"
43 } else {
44 "other"
45 };
46
47 println!("Stream #{index}: {s_type}, {name}, ({hr:02}:{min:02}:{sec:02}:{msec:03})");
48
49 if parameters.is_video() {
50 let (width, height) = parameters.size();
51 let bps = parameters.bitrate();
52
53 println!(" |- size: {width} x {height}; {bps} bps");
54 } else if parameters.is_audio() {
55 let bps = parameters.bitrate();
56
57 println!(" |- {bps} bps");
58
59 }
60 }
61}More examples
examples/decode_frame.rs (line 29)
11fn main() {
12 let url = if let Some(url) = std::env::args().skip(1).next() {
13 url
14 } else {
15 eprintln!("No input file!");
16 std::process::exit(1);
17 };
18
19 let mut format_context = FormatContext::open_input(&url).expect("Failed to open file!");
20
21 format_context.find_stream_info();
22
23 for i in format_context.streams() {
24 println!("{i:#?}");
25 }
26
27 let video_stream = format_context
28 .streams()
29 .filter(|x| x.codec_parameters().is_video())
30 .next()
31 .expect("Failed to find a video stream");
32
33 println!("CodecParams idx: {}", video_stream.index());
34 println!(
35 "CodecParams format: {}",
36 video_stream.codec_parameters().format()
37 );
38
39 let mut codec = CodecContext::from_decoder_id(video_stream.codec_parameters().codec_id())
40 .expect("Failed to create CodecContext");
41
42 codec.fill_from_parameters(&video_stream.codec_parameters());
43
44 codec.open(None).unwrap();
45
46 println!("Pixel format: {}", codec.get_pixel_format());
47
48 format_context.seek_msec(video_stream.index(), 4 * 60 * 1000);
49
50 let mut packet = Packet::new();
51
52 while format_context.read_frame(&mut packet) >= 0 {
53 println!("{}", packet.stream_index());
54
55 if packet.stream_index() == video_stream.index() {
56 codec.send_packet(&packet);
57
58 let mut frame = Frame::empty().expect("Failed to allocate a frame");
59
60 while codec.receive_frame(&mut frame) >= 0 {
61 println!("{}", frame.format());
62 {
63 let (width, height) = video_stream.codec_parameters().size();
64 println!("{width} x {height}");
65
66 let mut new_frame =
67 Frame::from_size_and_pixfmt(width, height, AVPixelFormat_AV_PIX_FMT_RGB24)
68 .unwrap();
69
70 let sws = Sws::new(
71 width,
72 height,
73 video_stream.codec_parameters().format(),
74 width,
75 height,
76 AVPixelFormat_AV_PIX_FMT_RGB24,
77 SWS_BILINEAR as _,
78 );
79
80 println!("{:?} {:?}", frame.linesize(), new_frame.linesize());
81
82 sws.scale(&frame, &mut new_frame);
83
84 let mut file = std::fs::OpenOptions::new()
85 .create(true)
86 .truncate(true)
87 .write(true)
88 .open("data.bin")
89 .unwrap();
90
91 file.write(new_frame.data_plane(0).unwrap()).unwrap();
92 }
93 }
94
95 break;
96 }
97 }
98
99 println!("Exit!");
100}pub fn raw(&self) -> *const AVCodecParameters
pub fn raw_mut(&self) -> *mut AVCodecParameters
Trait Implementations§
Source§impl Clone for CodecParameters
impl Clone for CodecParameters
Auto Trait Implementations§
impl !Send for CodecParameters
impl !Sync for CodecParameters
impl Freeze for CodecParameters
impl RefUnwindSafe for CodecParameters
impl Unpin for CodecParameters
impl UnsafeUnpin for CodecParameters
impl UnwindSafe for CodecParameters
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more