Introduction
Y4M, or YUV4MPEG2, is a simple file of uncompressed video frames with a short text header. It came from the mjpegtools project and is now the usual way to feed raw video into encoders such as x264, x265, libvpx and libaom, and to share test sequences.
Unlike a raw YUV file, a Y4M file records its own frame size, frame rate and pixel format, so no settings need to be given when it is opened.
Structure
The file starts with a header line in plain text: the word YUV4MPEG2, then
parameters separated by spaces, each a letter and a value, ending with a newline.
W and H give the width and height, F the frame
rate as a ratio, I the interlacing, A the pixel aspect ratio
and C the colour space, such as 420jpeg,
420mpeg2 or 444. X adds a comment.
Each frame is the word FRAME, optional parameters and a newline, followed
by the raw planes: all the Y samples, then the U samples, then the V samples.
YUV4MPEG2 W1920 H1080 F25:1 Ip A1:1 C420jpeg
FRAME
(1920 × 1080 Y bytes, then 960 × 540 U bytes, then 960 × 540 V bytes)
FRAME
…
Reference
- Stream header – every tag and value, with the extensions FFmpeg adds
- Frames – the FRAME line, its tags and the plane layout for each colour space
Not described
Known, not yet covered
- Reference: the header
yuv4mpeg.hof mjpegtools, the original implementation, was not read; the pages use theyuv4mpeg(5)manual and FFmpeg’s reader and writer. - Viewer: there is no Y4M viewer plugin yet; the explorer shows the file as bytes.
Unknown
- Reference: how odd picture sizes round in the chroma planes is not defined by the manual; only FFmpeg’s behaviour is described.
Links
Software
- FFmpeg and ffplay – command-line tools that play, write and convert Y4M (Windows, macOS, Linux)
- mpv – free, minimal media player (Windows, macOS, Linux)
- x264 – free H.264 encoder that takes Y4M as input (Windows, macOS, Linux)
- YUView – free viewer for raw and uncompressed video (Windows, macOS, Linux)
Developers
- libavformat – FFmpeg’s container library, which reads and writes Y4M (C)
Reference
- yuv4mpeg(5) – the MJPEG Tools manual page that defines the format
- YUV4MPEG2 – MultimediaWiki’s description of the header and frame layout
- Xiph.org video test media – widely used test sequences, as Y4M files