pub struct Sws { /* private fields */ }Implementations§
Source§impl Sws
impl Sws
Sourcepub fn new(
src_width: i32,
src_height: i32,
src_format: i32,
dst_width: i32,
dst_height: i32,
dst_format: i32,
flags: i32,
) -> Self
pub fn new( src_width: i32, src_height: i32, src_format: i32, dst_width: i32, dst_height: i32, dst_format: i32, flags: i32, ) -> Self
Examples found in repository?
examples/decode_frame.rs (lines 70-78)
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 scale(&self, in_frame: &Frame, out_frame: &mut Frame) -> i32
pub fn scale(&self, in_frame: &Frame, out_frame: &mut Frame) -> i32
Examples found in repository?
examples/decode_frame.rs (line 82)
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}Trait Implementations§
Auto Trait Implementations§
impl !Send for Sws
impl !Sync for Sws
impl Freeze for Sws
impl RefUnwindSafe for Sws
impl Unpin for Sws
impl UnsafeUnpin for Sws
impl UnwindSafe for Sws
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