Skip to main content

Frame

Struct Frame 

Source
pub struct Frame {
    pub planes: [Plane; 3],
    pub width: u32,
    pub height: u32,
    pub ss_h: u8,
    pub ss_v: u8,
    pub bpp: u8,
    pub color_space: u8,
    pub full_range: bool,
    pub segmap: Vec<u8>,
    pub mv: Vec<MvRefPair>,
    pub sb_cols: usize,
}
Available on crate feature decode only.
Expand description

A decoded frame (a reference, or the output).

Fields§

§planes: [Plane; 3]

Superblock-aligned planes; the visible picture is width × height.

§width: u32

Visible width.

§height: u32

Visible height.

§ss_h: u8

Horizontal chroma subsampling (log2).

§ss_v: u8

Vertical chroma subsampling (log2).

§bpp: u8

Bits per sample.

§color_space: u8

VP9 color_space (0 unknown, 1 BT.601, 2 BT.709, 3 SMPTE-170, 4 SMPTE-240, 5 BT.2020, 6 reserved, 7 sRGB) and full range.

§full_range: bool

Full-range samples.

§segmap: Vec<u8>

Segment id per 8×8 block, row stride 8 * sb_cols.

§mv: Vec<MvRefPair>

Motion per 8×8 block, as later frames read it.

§sb_cols: usize

Width in superblocks.

Implementations§

Source§

impl Frame

Source

pub fn to_decoded(&self) -> Result<DecodedFrame, String>

As a DecodedFrame: planes cropped, VP9’s color_space as the matrix number ffmpeg reports (AVColorSpace; 0 for RGB, whose planes are G, B, R). 4:4:0 has no ChromaFormat and is refused.

Source

pub fn cropped(&self, p: usize) -> (Vec<u16>, usize, usize)

The visible luma/chroma planes, tightly packed.

Examples found in repository?
examples/vp9_yuv_dump.rs (line 44)
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}

Auto Trait Implementations§

§

impl Forget for Frame

§

impl Freeze for Frame

§

impl Move for Frame

§

impl RefUnwindSafe for Frame

§

impl Send for Frame

§

impl Sync for Frame

§

impl Unpin for Frame

§

impl UnsafeUnpin for Frame

§

impl UnwindSafe for Frame

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.