A .yuv file has no header, so nothing in it says which layout it uses. These
are the layouts in common use, named by the FourCC codes used in Windows and by Linux’s
V4L2, and by FFmpeg’s pixel format names. In a planar layout each component is stored as a
separate block: all the Y samples, then one chroma plane, then the other. A file is the
frames one after another with nothing between them.
Three-plane layouts
| FourCC | V4L2 name | FFmpeg | Subsampling | Plane order | Chroma plane size |
|---|---|---|---|---|---|
I420, IYUV, YU12 | YUV420 | yuv420p | 4:2:0 | Y, Cb, Cr | W/2 × H/2 |
YV12 | YVU420 | 4:2:0 | Y, Cr, Cb | W/2 × H/2 | |
I422, 422P | YUV422P | yuv422p | 4:2:2 | Y, Cb, Cr | W/2 × H |
I444 | yuv444p | 4:4:4 | Y, Cb, Cr | W × H | |
411P | YUV411P | yuv411p | 4:1:1 | Y, Cb, Cr | W/4 × H |
YUV9 | YUV410 | yuv410p | 4:1:0 | Y, Cb, Cr | W/4 × H/4 |
YVU9 | YVU410 | 4:1:0 | Y, Cr, Cb | W/4 × H/4 |
Cb is the same as U, and Cr the same as V. Within a plane the samples run left to right, and the rows top to bottom. None of these layouts has padding when written to a file, even though the same names may have padding in memory.
Frame size
| Subsampling | Bytes per frame (8-bit) | Example: 1920 × 1080 |
|---|---|---|
| 4:2:0 | W × H × 3/2 | 3,110,400 |
| 4:2:2 | W × H × 2 | 4,147,200 |
| 4:4:4 | W × H × 3 | 6,220,800 |
| 4:1:1 | W × H × 3/2 | 3,110,400 |
| 4:1:0 | W × H × 9/8 | 2,332,800 |
The formulas hold when the width and height divide evenly by the chroma subsampling factors. When they do not, the chroma planes round up. FFmpeg uses (W + 1) / 2 for a half-width plane. Other software may round down, or may refuse odd sizes.
The number of frames is the file size divided by the frame size. If that does not give a whole number, the size or layout assumed is wrong.
Higher bit depths
Above 8 bits each sample is stored in two bytes. FFmpeg’s names show the depth and the
byte order: yuv420p10le is planar 4:2:0, 10 bits, little-endian, with the
value in the low bits of each 16-bit word, so a sample’s range is 0 to 1023. The
frame size in bytes is twice the 8-bit figure. The same pattern gives
yuv422p10le, yuv444p10le, 12-bit
yuv420p12le and so on. The big-endian forms end in be.
The P010 family puts the value in the high bits instead, so check which layout a file uses.
The IMC layouts
These are from Microsoft’s list of recommended rendering formats. They are 4:2:0 layouts defined by memory addresses and rarely appear as files.
| FourCC | Bits per pixel | Layout |
|---|---|---|
IMC1 | 16 | Y, then V, then U. The chroma planes have the same stride as Y, leaving unused space, and each starts on a 16-line boundary |
IMC3 | 16 | as IMC1, with U before V |
IMC2 | 12 | as IMC1, with V and U lines side by side in each full-stride chroma line, the U half starting at the half-stride point |
IMC4 | 12 | as IMC2, with U and V swapped |
Worked example
A 4 × 2 frame of I420 has eight Y samples, two Cb samples and two Cr
samples, 12 bytes in all:
Offset 0 Y00 Y01 Y02 Y03
Offset 4 Y10 Y11 Y12 Y13
Offset 8 Cb00 Cb01
Offset 10 Cr00 Cr01
Each chroma sample covers the two-by-two block of luma samples it belongs to.
YV12 has the same bytes with the Cr pair before the Cb pair.