The file records only numbers. How they map to colours depends on the sample range, the colour matrix and the chroma siting, none of which the file states. This page gives the usual meanings, as set out in Microsoft’s guide to 8-bit YUV formats.
Sample ranges
Most video uses limited range, also called studio or TV range:
| Component | Black or minimum | White or maximum | Neutral |
|---|---|---|---|
| Y, 8-bit | 16 | 235 | |
| Cb and Cr, 8-bit | 16 | 240 | 128 |
| Y, M-bit | 16 × 2M−8 | 235 × 2M−8 | |
| Cb and Cr, M-bit | 16 × 2M−8 | 240 × 2M−8 | 128 × 2M−8 |
Values outside these ranges can appear. JPEG-derived video uses full range instead, where Y runs from 0 to 255 and neutral chroma is 128.
Colour matrix
Y is a weighted sum of the red, green and blue signals, and U and V are scaled differences. Two sets of weights are in common use:
| Standard | Kr | Kb | Used for |
|---|---|---|---|
| BT.601 | 0.299 | 0.114 | standard-definition video |
| BT.709 | 0.2126 | 0.0722 | high-definition video |
Given R, G and B in the range 0 to 1:
L = Kr·R + Kb·B + (1 − Kr − Kb)·G
Y = 219·L + 16
U = 112·(B − L) / (1 − Kb) + 128
V = 112·(R − L) / (1 − Kr) + 128
These are for 8-bit limited range. For M bits, multiply by 2M−8.
Converting 8-bit BT.601 YUV to RGB
C = Y − 16
D = U − 128
E = V − 128
R = clip(round(1.164383·C + 1.596027·E))
G = clip(round(1.164383·C − 0.391762·D − 0.812968·E))
B = clip(round(1.164383·C + 2.017232·D))
Here clip limits the result to 0 to 255.
Chroma siting
In 4:2:0 and 4:2:2 video there are fewer chroma samples than pixels, and the formats differ in where those samples are centred:
| Name | Position relative to luma | Used by |
|---|---|---|
| Left | horizontally on a luma column, vertically half-way between lines | MPEG-2, H.264 default for 4:2:0 |
| Centre | half-way between luma samples in both directions | MPEG-1, JPEG, H.263 |
| Top-left | on a luma sample in both directions | BT.601, SMPTE 274M and 296M, DV 4:1:1, MPEG-2 4:2:2 |
Microsoft’s guidance is that 4:2:0 should be read with MPEG-2 siting unless known otherwise.
Finding the parameters of a file
Because the file holds no header, the settings are usually carried by convention, often
in the file name, as in clip_1920x1080_25fps_420p.yuv. Test-sequence
collections publish them with the files. A reader has to be told at least the width, the
height and the layout. Frame rate affects only playback speed and is not needed to
decode the frames.