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
…
Links
Software
- FFmpeg and ffplay (Windows, macOS, Linux)
- mpv (Windows, macOS, Linux)
- x264, which takes Y4M as input (Windows, macOS, Linux)
- YUView, a viewer for raw video (Windows, macOS, Linux)
Developers
- libavformat, C, FFmpeg’s container library
Reference
- YUV4MPEG2, MultimediaWiki
- Xiph.org video test media, test sequences as Y4M files