Skip to main content

Vp9Decoder

Struct Vp9Decoder 

Source
pub struct Vp9Decoder { /* private fields */ }
Available on crate feature decode only.
Expand description

The decoder.

Implementations§

Source§

impl Vp9Decoder

Source

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

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).

Source

pub fn accel_read(&mut self, frame: &Frame) -> Result<DecodedFrame, String>

The samples of frame, from the accelerator that decoded it.

Source

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§

Source§

impl Default for Vp9Decoder

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.