Skip to main content

CodecParameters

Struct CodecParameters 

Source
pub struct CodecParameters { /* private fields */ }

Implementations§

Source§

impl CodecParameters

Source

pub fn new() -> Option<CodecParameters>

Source

pub fn codec_type(&self) -> AVMediaType

Source

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}
Source

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}
Source

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}
Source

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
Hide additional 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}
Source

pub fn aspect_ratio(&self) -> AVRational

Source

pub fn framerate(&self) -> AVRational

Source

pub fn color_range(&self) -> AVColorRange

Source

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}
Source

pub fn sample_rate(&self) -> Option<i32>

Source

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}
Source

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
Hide additional 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}
Source

pub fn raw(&self) -> *const AVCodecParameters

Source

pub fn raw_mut(&self) -> *mut AVCodecParameters

Trait Implementations§

Source§

impl Clone for CodecParameters

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CodecParameters

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.