Skip to main content

Module y4m

Module y4m 

Source
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 YUV4MPEG2 magic (10 bytes, trailing space included).
  • Each parameter is a single ASCII letter followed by a value, with space-separated tokens and a \n terminator.
  • W (width) and H (height) are required.
  • F<num>:<den> is the frame rate.
  • I is the interlace mode: p progressive (default), t top first, b bottom first, m mixed.
  • 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 optional p10/p12/p14/p16 suffix for higher bit depths.
  • X<key>=<val> extension tokens are preserved verbatim in the demuxer’s metadata() 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:

colorspaceY bytesU bytesV bytes
420*w*h(w/2)*(h/2)(w/2)*(h/2)
422w*h(w/2)*h(w/2)*h
444w*hw*hw*h
monow*h00

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.

Functions§

register