yuv

tape
import yuv from "yuv";

let pic: yuv.Picture = yuv.Picture { y: f.y; cb: f.cb; cr: f.cr; y_stride: f.y_stride;
                                     c_stride: f.c_stride; nv12: false; x: f.crop.x;
                                     y0: f.crop.y; width: f.crop.width; height: f.crop.height; };
let colour: yuv.Colour = yuv.Colour { matrix: f.colour.matrix; full_range: f.colour.full_range;
                                      chroma_loc: f.colour.chroma_loc; };
yuv.convert(&pic, colour, &surface, 0, 0, surface.width, surface.height) or { return 1; };

yuv turns a decoded video frame (8-bit 4:2:0: I420’s three planes, or NV12’s luma and interleaved chroma) into the pixels of a gfx.Surface. convert draws the frame’s visible area into a rectangle of the surface, scaled to fit (bilinear), clipped to the surface.

Colour is the stream’s description as the H.264 VUI codes it (what h264.Frame.colour holds): the matrix (BT.601, BT.709, BT.2020, …; unspecified means BT.601 below 720 lines and BT.709 from 720), limited or full range, and where the chroma samples sit. The result is within one level of the exact conversion. A picture whose planes are too small for its size is BadPicture.

Last modified: