A Y4M file starts with one line of ASCII text, and the
frames follow it. The format is defined by the
yuv4mpeg(5) manual page of the MJPEG Tools project.
Syntax
The line is the magic string YUV4MPEG2, then any number of tagged fields,
each with one space before it, then one newline byte (0A). A tagged field
is one ASCII tag character followed at once by its value, which contains no whitespace.
A value is a ratio (numerator:denominator), a base-10 integer, a single
character or a string, depending on the tag.
FFmpeg’s reader accepts a header of at most 128 bytes.
Colour spaces
The values in the manual page:
| Value | Subsampling | Meaning |
|---|---|---|
420jpeg | 4:2:0 | chroma sited as in JPEG and MPEG-1. The default |
420mpeg2 | 4:2:0 | chroma sited as in MPEG-2 |
420paldv | 4:2:0 | chroma sited as in PAL DV |
411 | 4:1:1 | chroma cosited with luma |
422 | 4:2:2 | chroma cosited with luma |
444 | 4:4:4 | no subsampling |
444alpha | 4:4:4 | no subsampling, plus an alpha plane |
mono | none | the luma plane only |
FFmpeg also writes these, which it calls non-standard and writes only with
-strict -1. Samples above 8 bits take two bytes:
| Value | Meaning |
|---|---|
mono9, mono10, mono12, mono16 | luma only, at that depth |
420p9, 422p9, 444p9 | planar, 9 bits |
420p10, 422p10, 444p10 | planar, 10 bits |
420p12, 422p12, 444p12 | planar, 12 bits |
420p14, 422p14, 444p14 | planar, 14 bits |
420p16, 422p16, 444p16 | planar, 16 bits |
The header does not say which colour matrix was used. The manual page describes the samples as CCIR-601 Y′CbCr.
Interlacing
| Value | Meaning |
|---|---|
? | unknown. The default |
p | progressive |
t | top field first |
b | bottom field first |
m | mixed: each frame header gives the framing |
FFmpeg’s reader refuses m as unsupported.
Common frame rates and aspect ratios
| Value | Meaning |
|---|---|
F25:1 | 25 frames per second (PAL and SECAM) |
F30000:1001 | 29.97 frames per second (NTSC) |
F24000:1001 | 23.976 frames per second (film transferred to NTSC) |
A1:1 | square pixels |
Worked example
YUV4MPEG2 W1920 H1080 F30000:1001 It A1:1 C420mpeg2 XCOLORRANGE=LIMITED
1920 × 1080 at 29.97 frames a second, interlaced top field first, square pixels, 4:2:0 with MPEG-2 chroma siting and limited range. A newline ends the line, and the first frame header starts on the next byte.