Introduction
A .yuv file holds uncompressed video frames one after another, with no
header at all. Each pixel is stored as a brightness value (Y, or luma) and two colour
difference values (U and V, or chroma), usually with the colour at lower resolution
than the brightness. Codec developers and researchers use these files as the input and
output of encoders and decoders.
Because nothing in the file says how it is laid out, the width, height, frame rate and pixel format must be given separately, often in the file name. Opening the file with the wrong settings gives a scrambled picture.
Structure
The most common layout is 8-bit planar 4:2:0, also called I420 or
yuv420p. Each frame is the full Y plane, one byte per pixel, then the U
plane and the V plane, each half the width and half the height. A frame therefore takes
width × height × 1.5 bytes when both are even, and the number of frames is the file
size divided by that.
Other layouts exist: NV12 stores U and V interleaved in a single plane, 4:2:2 and 4:4:4 keep more colour detail, and 10-bit formats use two bytes per sample.
0Y plane of frame 0, one byte per pixelw × h…U plane of frame 0w/2 × h/2…V plane of frame 0w/2 × h/2…the planes of the next framerepeated
Reference
- Planar layouts – I420, YV12, the other three-plane layouts and high bit depths
- Semi-planar layouts – NV12 and its relatives, and P010
- Packed layouts – YUY2, UYVY, AYUV and the byte order of each
- Sample values – sample ranges, colour matrices and chroma siting
Not described
Known, not yet covered
- Reference: the layouts of P016 and of the tiled and multi-buffer Video4Linux formats are not on the pages (the tiled ones are memory layouts rather than file layouts).
- Reference: the byte order of Microsoft’s AYUV, which Microsoft shows only as a diagram.
- Viewer: there is no YUV viewer plugin; a raw file has no header, so the size and layout would have to be given.
Unknown
- Reference: no specification of the file itself exists: .yuv is only raw frames in one of the layouts above.
Links
Software
- YUView – free viewer for raw video, where the size and pixel format are set by hand (Windows, macOS, Linux)
- FFmpeg and ffplay – command-line tools that read raw YUV with
-f rawvideoand the size and pixel format given (Windows, macOS, Linux) - mpv – free media player that plays raw YUV with its raw video options set (Windows, macOS, Linux)
Developers
- libswscale – FFmpeg’s library for converting between pixel formats (C)
Reference
- Recommended 8-bit YUV formats – Microsoft’s guide to the layouts, the ranges and conversion to RGB
- Planar YUV formats – the Linux V4L2 descriptions of the planar and semi-planar layouts
- Packed YUV formats – the Linux V4L2 descriptions of the packed layouts