YUV4MPEG2: Difference between revisions

From MultimediaWiki
Jump to navigation Jump to search
(Let's get ya to use the HTML code tag first)
(→‎Data format: bit better, right?)
Line 5: Line 5:


== Data format ==
== Data format ==
=== File header ===
A Y4M file begins with a plaintext, quasi-freeform header. The first 10 bytes are a file signature of <code>YUV4MPEG2 </code> (last character is a space, ASCII 0x20).  Following the signature is any number of parameters preceeded by a space (ASCII 0x20). The parameters that should definitely be present are width, height, and frame rate:
A Y4M file begins with a plaintext, quasi-freeform header. The first 10 bytes are a file signature of <code>YUV4MPEG2 </code> (last character is a space, ASCII 0x20).  Following the signature is any number of parameters preceeded by a space (ASCII 0x20). The parameters that should definitely be present are width, height, and frame rate:
* frame width: <code>W</code> followed by a plaintext integer; example: <code>W720</code>
* frame width: <code>W</code> followed by a plaintext integer; example: <code>W720</code>
Line 16: Line 18:


The following parameters are optional:
The following parameters are optional:
; {{#tag:code|I}} (interlacing)
; {{#tag:code|I}}, interlacing
 
: <code>Ip</code> = Progressive
* interlacing: <code>I</code> followed by a single letter to indicate interlacing mode:
: <code>It</code> = Top field first
** <code>Ip</code> = Progressive
: <code>Ib</code> = Bottom field first
** <code>It</code> = Top field first
: <code>Im</code> = Mixed modes (detailed in FRAME headers)
** <code>Ib</code> = Bottom field first
; <code>A</code>, pixel aspect ratio
** <code>Im</code> = Mixed modes (detailed in FRAME headers)
: Note that this is not the ratio of the picture as a whole, just the pixels. Any integer ratio is acceptable. Examples:
* Parameter <code>A</code>: Pixel aspect ratioNote that this is not the ratio of the picture as a whole, just the pixels. Examples:  
:* <code>A0:0</code> = unknown
** <code>A0:0</code> = unknown
:* <code>A1:1</code> = square pixels
** <code>A1:1</code> = square pixels
:* <code>A4:3</code> = NTSC-SVCD (480x480 stretched to 4:3 screen)
** <code>A4:3</code> = NTSC-SVCD (480x480 stretched to 4:3 screen)
:* <code>A4:5</code> = NTSC-DVD narrow-screen (720x480 compressed to a 4:3 display)
** <code>A4:5</code> = NTSC-DVD narrow-screen (720x480 compressed to a 4:3 display)
:* <code>A32:27</code> = NTSC-DVD wide-screen (720x480 stretched to a 16:9 display)
** <code>A32:27</code> = NTSC-DVD wide-screen (720x480 stretched to a 16:9 display)
; <code>C</code>, Colour space
* Parameter <code>C</code>: Colour space
: Called "colorspace", actually defines pixel format and color model.
** <code>C420jpeg</code> = 4:2:0 with biaxially-displaced chroma planes
:* <code>C420jpeg</code> = 4:2:0 with biaxially-displaced chroma planes
** <code>C420paldv</code> = 4:2:0 with vertically-displaced chroma planes
:* <code>C420paldv</code> = 4:2:0 with vertically-displaced chroma planes
** <code>C420</code> = 4:2:0 with coincident chroma planes
:* <code>C420</code> = 4:2:0 with coincident chroma planes
** <code>C422</code> = 4:2:2
:* <code>C422</code> = 4:2:2
** <code>C444</code> = 4:4:4
:* <code>C444</code> = 4:4:4
** <code>Cmono</code> = YCbCr plane only
:* <code>Cmono</code> = YCbCr plane only
* Parameter <code>X</code>: Comment or extension. Ignored, but passed, by a YUV4MPEG2 processor.
:For a much more exhaustive list, check out documentation for [https://docs.rs/y4m/0.8.0/y4m/enum.Colorspace.html y4m::Colorspace]. Yes, there are higher bit-depth options. If you tell ffmpeg to be less strict, there are even wackier possibilities.
** FFMPEG defines, among others, the following extensions:
:If you have trouble figuring out the difference between C420jpeg and C420paldv, this might help: https://chromium.googlesource.com/webm/libvpx/+/refs/heads/main/y4minput.c
*** <code>XCOLORRANGE</code> providing information on the color space
; <code>X</code>, Comment or extension.
**** <code>XCOLORRANGE=FULL</code> JPEG / Full swing / ITU T.871 range
: Ignored, but preserved and passed down, by a YUV4MPEG2 processor.
**** <code>XCOLORRANGE=LIMITED</code> MPEG / Studio swing / TV range
: FFMPEG defines, among others, the following extensions:
 
:*<code>XCOLORRANGE</code>, defines the color range.
If you have trouble figuring out the difference between C420jpeg and C420paldv, this might help: https://chromium.googlesource.com/webm/libvpx/+/refs/heads/main/y4minput.c
:**<code>XCOLORRANGE=FULL</code> JPEG / Full swing / ITU T.871 range
:**<code>XCOLORRANGE=LIMITED</code> MPEG / Studio swing / TV range
:*<code>XYSCSS</code>, indicates non-standard pixel formats not quite described by <code>C</code>


=== Frame data ===
Following the header is any number of frames coded in YCbCr format in Y-Cb-Cr plane order. Each frame begins with the 5 bytes <code>FRAME</code> followed by zero or more parameters each preceded by 0x20, ending with 0x0A.  This is then followed by the raw bytes from each plane.
Following the header is any number of frames coded in YCbCr format in Y-Cb-Cr plane order. Each frame begins with the 5 bytes <code>FRAME</code> followed by zero or more parameters each preceded by 0x20, ending with 0x0A.  This is then followed by the raw bytes from each plane.



Revision as of 03:23, 21 November 2023

YUV4MPEG2 is a simple file format designed to hold uncompressed frames of YCbCr video formatted as YCbCr 4:2:0, YCbCr 4:2:2 or YCbCr 4:4:4 data for the purpose of encoding, likely to MPEG-2. The part "YUV" in its name just derives from the fact that the color space YCbCr (used for color encoding in digital media) is often falsely mixed up with the color space YUV (used in analog PAL based applications, including analog TV and video tapes). Since the original MPEG-2 specification supports more than one type of color matrix (BT.601, BT.709, ...), there is no way to know, without extensions in this format, the color matrix used for conversion to YCbCr from RGB.

Data format

File header

A Y4M file begins with a plaintext, quasi-freeform header. The first 10 bytes are a file signature of YUV4MPEG2 (last character is a space, ASCII 0x20). Following the signature is any number of parameters preceeded by a space (ASCII 0x20). The parameters that should definitely be present are width, height, and frame rate:

  • frame width: W followed by a plaintext integer; example: W720
  • frame height: H followed by a plaintext integer; example: H480
  • frame rate: F followed by the number of frames per second, expressed as a fraction in the form numerator:denominator. Examples:
    • F30:1 = 30 FPS
    • F25:1 = 25 FPS (PAL/SECAM standard)
    • F24:1 = 24 FPS (Film)
    • F30000:1001 = 29.97 FPS (NTSC standard)
    • F24000:1001 = 23.976 FPS (Film transferred to NTSC)

The following parameters are optional:

I, interlacing
Ip = Progressive
It = Top field first
Ib = Bottom field first
Im = Mixed modes (detailed in FRAME headers)
A, pixel aspect ratio
Note that this is not the ratio of the picture as a whole, just the pixels. Any integer ratio is acceptable. Examples:
  • A0:0 = unknown
  • A1:1 = square pixels
  • A4:3 = NTSC-SVCD (480x480 stretched to 4:3 screen)
  • A4:5 = NTSC-DVD narrow-screen (720x480 compressed to a 4:3 display)
  • A32:27 = NTSC-DVD wide-screen (720x480 stretched to a 16:9 display)
C, Colour space
Called "colorspace", actually defines pixel format and color model.
  • C420jpeg = 4:2:0 with biaxially-displaced chroma planes
  • C420paldv = 4:2:0 with vertically-displaced chroma planes
  • C420 = 4:2:0 with coincident chroma planes
  • C422 = 4:2:2
  • C444 = 4:4:4
  • Cmono = YCbCr plane only
For a much more exhaustive list, check out documentation for y4m::Colorspace. Yes, there are higher bit-depth options. If you tell ffmpeg to be less strict, there are even wackier possibilities.
If you have trouble figuring out the difference between C420jpeg and C420paldv, this might help: https://chromium.googlesource.com/webm/libvpx/+/refs/heads/main/y4minput.c
X, Comment or extension.
Ignored, but preserved and passed down, by a YUV4MPEG2 processor.
FFMPEG defines, among others, the following extensions:
  • XCOLORRANGE, defines the color range.
    • XCOLORRANGE=FULL JPEG / Full swing / ITU T.871 range
    • XCOLORRANGE=LIMITED MPEG / Studio swing / TV range
  • XYSCSS, indicates non-standard pixel formats not quite described by C

Frame data

Following the header is any number of frames coded in YCbCr format in Y-Cb-Cr plane order. Each frame begins with the 5 bytes FRAME followed by zero or more parameters each preceded by 0x20, ending with 0x0A. This is then followed by the raw bytes from each plane.

The length of each frame (excluding its header) can be computed as:

  • frame length = width * height * 3 / 2 (4:2:0)
  • frame length = width * height * 2 (4:2:2)
  • frame length = width * height * 3 (4:4:4)