yuv4mpeg(5)
β¨ YUV4MPEG2 β the video stream format bestie π
okay so welcome to yuv4mpeg(5), the manual page for YUV4MPEG2, the video stream format that all the pipe-based MJPEGtools use. pull up a chair, grab a strawberry π, we're gonna get into it.
πΈ DESCRIPTION πΈ
so like, a whole bunch of the MJPEGtools talk to each other through pipes and act as filters (or sources, or sinks, no judgment). the format of the video data flowing through those pipes is called "YUV4MPEG", or, to be precise about it, "YUV4MPEG2". (the format got extended and codified during v1.5.x of the tools, iykyk.)
the basic structure is literally just a stream header followed by an unlimited number of frames. and each frame is itself a header plus video data. the headers are vaguely human-readable ASCII, but the video data is straight up simple byte-size binary. no cap.
the MJPEGtools distribution ships a C library (libmjpegutils) that has functions for manipulating YUV4MPEG2 streams. we highly recommend you use this library instead of writing your own code if you possibly can. the header file yuv4mpeg.h describes all those functions. π«Ά
π Design Goals
- Easy to parse both via C or sh.
- Extensible; easy to add new parameters while maintaining backwards compatibility.
- Simple upgrade from original "YUV4MPEG" format.
π Drawbacks
- Frame headers do not have constant size, so streams are not seekable.
yes bestie that last one is a real one. no seeking. the frames are giving "mystery length" energy and that's just how it is.
π¦ GRAMMAR π¦
the precise description of the YUV4MPEG2 stream format is as follows:
STREAM consists of
- one STREAM-HEADER
- unlimited number of FRAMEs
STREAM-HEADER consists of
- magic string
"YUV4MPEG2" - unlimited number of TAGGED-FIELDs, each preceeded by a
' '(single space) separator - single
'\n'line terminator
FRAME consists of
- one FRAME-HEADER
- "length" octets of planar YCbCr 4:2:0 image data (If the stream is interlaced, then the two fields per frame are interleaved, with proper spatial ordering.)
FRAME-HEADER consists of
- magic string
"FRAME" - unlimited number of TAGGED-FIELDs, each preceeded by a
' '(single space) separator - single
'\n'line terminator
TAGGED-FIELD consists of
- single ASCII character tag
- VALUE (which does not contain whitespace)
VALUE consists of
- RATIO, or
- integer (base 10 ASCII representation), or
- single ascii character, or
- string (multiple ASCII characters)
RATIO consists of
- numerator (base 10 ASCII integer)
':'(a colon)- denominator (base 10 ASCII integer)
header tags fall into three categories: optional, required and has-default. optional tags are completely optional and may be omitted from a header. required tags must be present in a header. has-default tags have a default value which is implied if the tag is not present. and independent of these categories, some tags allow an "unknown" value and some do not. the way that's a whole taxonomy π
π the supported tags for the STREAM-HEADER
W[integer]β frame width in pixels, must be > 0 (required)H[integer]β frame height in pixels, must be > 0 (required)C[string]β chroma subsampling, image data format (has default)420jpegβ 4:2:0 with JPEG/MPEG-1 siting (default)420mpeg2β 4:2:0 with MPEG-2 siting420paldvβ 4:2:0 with PAL-DV siting411β 4:1:1, cosited422β 4:2:2, cosited444β 4:4:4 (no subsampling)444alphaβ 4:4:4 with an alpha channelmonoβ luma (Y') plane only
I[char]β interlacing specification: (has default)?β unknown (default)pβ progressive/nonetβ top-field-firstbβ bottom-field-firstmβ mixed-mode: refer to'I'tag in frame header
F[ratio]β frame-rate (has default of0:0== unknown)A[ratio]β sample aspect ratio (has default of0:0== unknown)X[string]β 'metadata' (optional; unparsed, but passed around)
π the currently supported tags for the FRAME-HEADER
I[string]β framing and sampling (required if-and-only-ifImis present in stream header). Value is a string of three characters"xyz"which have the following meanings:x: frame presentationtβ top-field-firstTβ top-field-first and repeatbβ bottom-field-firstBβ bottom-field-first and repeat1β single progressive frame2β double progressive frame (repeat)3β triple progressive frame (repeat)
y: frame temporal samplingpβ progressive (fields sampled at same time)iβ interlaced (fields sampled at different times)
z: frame chroma-subsamplingpβ progressive (subsampling over whole frame)iβ interlaced (each field subsampled independently)?β unknown (allowed only for non-4:2:0 subsampling)
X[string]β 'metadata' (optional; unparsed, but passed around)
ok important one bestie: a filter application must faithfully forward all"X"tags from input pipe to output pipe (unless it uses one of those tags, of course). the supplied library will do this automatically if the functionsy4m_copy_stream_info()andy4m_copy_frame_info()are used appropriately. don't be the filter that drops the metadata. that's not the vibe. π«
π§ NOTES ON IMAGE DATA π§
all image data is in the CCIR-601 Y'CbCr colorspace, presented plane-by-plane in row-major order. each sample within each plane is one octet (8-bits) in size. when all planes are present, they are transmitted in the order Y', Cb, Cr, potentially followed by an alpha/transparency mask plane (for the 444alpha chroma format). the alpha channel data is follows the same range as the Y' luma channel: full transparency is at 16 and full opacity is at 235. π
all Y' and alpha planes consist of (height X width) octets. the size of the chroma planes depends on the subsampling mode:
- 4:4:4 β (height X width) octets
- 4:2:2 β (height X width) / 2 octets
- 4:1:1 β (height X width) / 4 octets
- 4:2:0 β (height X width) / 4 octets
π NOTES ON FRAMING π
for more details about reading and writing yuv4mpeg files read the sources β there are many utility programs, some simple, some complex that can serve as guides. literally go look, it's giving textbook energy. π
π₯ SEE ALSO π₯
mjpegtools(1), yuv4mpeg.h
π AUTHOR π
This manual page Copyright 2004 Matthew J. Marjanovic.
and that's the whole page, bestie. this was written by the MJPEG Tools Team, dated 25 November 2002, from the MJPEG Tools Manual. slay, periodt. π β¨ππ¦πΈ
π¦ where this page comes from
- arch rolling: mjpegtools 2.2.1-4 Β· GPL-2.0-or-later
- fedora 43: mjpegtools 2.2.1-11.fc43 Β· GPL-2.0-or-later AND GPL-2.0-only AND GPL-1.0-or-later
- fedora 44: mjpegtools 2.2.1-12.fc44 Β· GPL-2.0-or-later AND GPL-2.0-only AND GPL-1.0-or-later
- nixos 26.05: mjpegtools 2.2.1
- nixpkgs unstable: mjpegtools 2.2.1
- opensuse-leap 16.0: mjpegtools 2.2.1-160000.2.2 Β· GPL-2.0-only
- opensuse-leap 16.0: mjpegtools 2.2.1-160000.2.2 Β· GPL-2.0-only
- opensuse-leap 16.0: mjpegtools 2.2.1-160000.2.2 Β· GPL-2.0-only
- opensuse-leap 16.0: mjpegtools 2.2.1-160000.2.2 Β· GPL-2.0-only
- ubuntu resolute: mjpegtools 1:2.2.1-3
- ubuntu stonking: mjpegtools 1:2.2.1-3
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms