Expand description
YUV4MPEG2 (.y4m) raw-video container.
A .y4m file is the simplest possible video container: a single
ASCII header line followed by a sequence of FRAME\n-prefixed raw
planar YUV pictures. There is no index, no random-access support,
and no in-stream codec tag — every payload is rawvideo.
§Wire format
YUV4MPEG2 W<w> H<h> F<num>:<den> Ip A<n>:<d> C<colorspace> [X<k>=<v>...]\n
FRAME [X<k>=<v>...]\n
<Y plane><U plane><V plane>
FRAME ...\n
...- The header begins with the literal
YUV4MPEG2magic (10 bytes, trailing space included). - Each parameter is a single ASCII letter followed by a value, with
space-separated tokens and a
\nterminator. W(width) andH(height) are required.F<num>:<den>is the frame rate.Iis the interlace mode:pprogressive (default),ttop first,bbottom first,mmixed.A<num>:<den>is the pixel aspect ratio.C<colorspace>selects chroma subsampling and bit depth. Common values:420jpeg,420mpeg2,420paldv,420,422,444,mono, with optionalp10/p12/p14/p16suffix for higher bit depths.X<key>=<val>extension tokens are preserved verbatim in the demuxer’smetadata()output and ignored by the muxer (per-frame extensions are simply dropped on decode and never emitted on encode).
§Plane sizes
For an 8-bit stream:
| colorspace | Y bytes | U bytes | V bytes |
|---|---|---|---|
420* | w*h | (w/2)*(h/2) | (w/2)*(h/2) |
422 | w*h | (w/2)*h | (w/2)*h |
444 | w*h | w*h | w*h |
mono | w*h | 0 | 0 |
p10/p12/p14/p16 doubles every byte count (16-bit
little-endian samples, per the ffmpeg convention).
§Codec id
Frames are emitted as packets carrying the rawvideo codec id.
Pixel format and dimensions are exposed via the stream’s
CodecParameters.