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: u32Visible width.
height: u32Visible height.
ss_h: u8Horizontal chroma subsampling (log2).
ss_v: u8Vertical chroma subsampling (log2).
bpp: u8Bits per sample.
color_space: u8VP9 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: boolFull-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: usizeWidth in superblocks.
Implementations§
Source§impl Frame
impl Frame
Sourcepub fn to_decoded(&self) -> Result<DecodedFrame, String>
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.
Sourcepub fn cropped(&self, p: usize) -> (Vec<u16>, usize, usize)
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> 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