pub struct Vp9Decoder { /* private fields */ }Available on crate feature
decode only.Expand description
The decoder.
Implementations§
Source§impl Vp9Decoder
impl Vp9Decoder
Sourcepub fn new() -> Self
pub fn new() -> Self
A decoder waiting for a keyframe.
Examples found in repository?
examples/vp9_yuv_dump.rs (line 30)
11fn main() {
12 let a: Vec<String> = std::env::args().collect();
13 if a.len() < 3 {
14 eprintln!("usage: vp9_yuv_dump IN.webm|IN.ivf OUT.yuv");
15 std::process::exit(2);
16 }
17 let data = std::fs::read(&a[1]).expect("read");
18 let packets: Vec<Vec<u8>> = if data.starts_with(b"DKIF") {
19 parse_ivf(&data)
20 .expect("ivf")
21 .4
22 .into_iter()
23 .map(|(_, d)| d)
24 .collect()
25 } else {
26 let mkv = Mkv::parse(&data).expect("mkv");
27 let t = mkv.track(TrackKind::Video).expect("no video track");
28 mkv.frames_of(t.number).map(|f| f.data.clone()).collect()
29 };
30 let mut dec = Vp9Decoder::new();
31 let mut out = std::io::BufWriter::new(std::fs::File::create(&a[2]).expect("create"));
32 let mut n = 0;
33 let mut desc = String::new();
34 for p in &packets {
35 let frames = match dec.decode(p) {
36 Ok(f) => f,
37 Err(e) => {
38 println!("ERROR {e} (after {n} frames)");
39 std::process::exit(2);
40 }
41 };
42 for f in frames {
43 for pl in 0..3 {
44 let (s, _, _) = f.cropped(pl);
45 if f.bpp == 8 {
46 out.write_all(&s.iter().map(|&v| v as u8).collect::<Vec<_>>())
47 .unwrap();
48 } else {
49 out.write_all(&s.iter().flat_map(|&v| v.to_le_bytes()).collect::<Vec<_>>())
50 .unwrap();
51 }
52 }
53 desc = format!(
54 "{}x{} {}-bit ss {}{}",
55 f.width, f.height, f.bpp, f.ss_h, f.ss_v
56 );
57 n += 1;
58 }
59 }
60 println!("{n} frames, {desc}");
61}Sourcepub fn set_accel(&mut self, accel: Box<dyn Vp9Accel>)
pub fn set_accel(&mut self, accel: Box<dyn Vp9Accel>)
Decode one packet (a frame or superframe); returns the frames to show.
Hand reconstruction to accel (see Vp9Accel).
Sourcepub fn accel_read(&mut self, frame: &Frame) -> Result<DecodedFrame, String>
pub fn accel_read(&mut self, frame: &Frame) -> Result<DecodedFrame, String>
The samples of frame, from the accelerator that decoded it.
Sourcepub fn decode(&mut self, packet: &[u8]) -> Result<Vec<Arc<Frame>>, String>
pub fn decode(&mut self, packet: &[u8]) -> Result<Vec<Arc<Frame>>, String>
Decode one packet (a frame or a superframe) and return the frames it shows.
Examples found in repository?
examples/vp9_yuv_dump.rs (line 35)
11fn main() {
12 let a: Vec<String> = std::env::args().collect();
13 if a.len() < 3 {
14 eprintln!("usage: vp9_yuv_dump IN.webm|IN.ivf OUT.yuv");
15 std::process::exit(2);
16 }
17 let data = std::fs::read(&a[1]).expect("read");
18 let packets: Vec<Vec<u8>> = if data.starts_with(b"DKIF") {
19 parse_ivf(&data)
20 .expect("ivf")
21 .4
22 .into_iter()
23 .map(|(_, d)| d)
24 .collect()
25 } else {
26 let mkv = Mkv::parse(&data).expect("mkv");
27 let t = mkv.track(TrackKind::Video).expect("no video track");
28 mkv.frames_of(t.number).map(|f| f.data.clone()).collect()
29 };
30 let mut dec = Vp9Decoder::new();
31 let mut out = std::io::BufWriter::new(std::fs::File::create(&a[2]).expect("create"));
32 let mut n = 0;
33 let mut desc = String::new();
34 for p in &packets {
35 let frames = match dec.decode(p) {
36 Ok(f) => f,
37 Err(e) => {
38 println!("ERROR {e} (after {n} frames)");
39 std::process::exit(2);
40 }
41 };
42 for f in frames {
43 for pl in 0..3 {
44 let (s, _, _) = f.cropped(pl);
45 if f.bpp == 8 {
46 out.write_all(&s.iter().map(|&v| v as u8).collect::<Vec<_>>())
47 .unwrap();
48 } else {
49 out.write_all(&s.iter().flat_map(|&v| v.to_le_bytes()).collect::<Vec<_>>())
50 .unwrap();
51 }
52 }
53 desc = format!(
54 "{}x{} {}-bit ss {}{}",
55 f.width, f.height, f.bpp, f.ss_h, f.ss_v
56 );
57 n += 1;
58 }
59 }
60 println!("{n} frames, {desc}");
61}Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Vp9Decoder
impl !Send for Vp9Decoder
impl !Sync for Vp9Decoder
impl !UnwindSafe for Vp9Decoder
impl Forget for Vp9Decoder
impl Freeze for Vp9Decoder
impl Move for Vp9Decoder
impl Unpin for Vp9Decoder
impl UnsafeUnpin for Vp9Decoder
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more