Skip to content
Formats & Conversion

Planar vs. Packed: How YUV Pixels Are Laid Out in Memory

Two files can hold exactly the same picture and still be unreadable to each other. The difference is how the Y, U and V samples are ordered.

7 min read

Same picture, different order

A YUV frame contains three kinds of sample: luma (Y) and two chroma components (U and V). A pixel format defines not only how many of each there are, but the order in which they are written. Get the order wrong and the image still decodes — just into nonsense.

Planar formats

In a planar format such as I420, the file holds every Y sample for the frame, then every U sample, then every V sample. For a 4:2:0 frame of width W and height H:

  • Y plane: W × H bytes, starting at offset 0
  • U plane: (W/2) × (H/2) bytes, starting at W × H
  • V plane: (W/2) × (H/2) bytes, starting at W × H × 1.25

YV12 is identical except that V comes before U — a common source of pictures with swapped blue and red casts.

Semi-planar formats

NV12 keeps the full Y plane but stores chroma as a single interleaved plane: U, V, U, V… This suits many hardware decoders because both chroma values for a block are fetched together. NV21 interleaves them the other way round, V then U.

Packed formats

Packed formats interleave everything. In YUY2 (also called YUYV), each group of four bytes describes two horizontally adjacent pixels: Y0 U Y1 V. The two pixels share one U and one V value, which is what makes it 4:2:2. UYVY uses the order U Y0 V Y1.

Why it matters

Planar layouts make it easy to process luma alone — useful for analysis, scaling and many filters. Packed layouts map neatly onto older capture hardware and display pipelines. Converting between them is lossless as long as the sampling ratio stays the same; changing from 4:2:2 to 4:2:0 discards chroma and cannot be fully reversed.

A quick sanity check

If you are unsure of a file's layout, open it in a viewer and inspect the luma alone. A clean greyscale picture means your width, height and Y-plane assumptions are right; any remaining colour problems are in the chroma ordering.