YUV

本文详细介绍了YUV像素格式在视频应用中的使用,包括VLC媒体播放器中常见的YUV格式,如YUV4:2:0、YUV4:2:2和YUV4:4:4,以及它们的子类别,如I420、J420、YV12、I422、J422、I444等。同时,文章还解释了平面格式、打包格式和半平面格式的区别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

https://wiki.videolan.org/YUV/

YUV

See also: Huffyuv and Creative YUV

Wikipedia has information on this entry:

YUV

YUV is a class of pixel formats used in video applications, including VLC media player.

YUV is actually the name of the color space that is common to all "YUV" pixel formats. Contrary to RGB formats (Red-Green-Blue), YUV colors are represented with one "luminance" component called Y (equivalent to grey scale) and two "chrominance" components, called U (blue projection) and V (red projection) respectively, hence the name.

YUV can also be referred to as YCbCr, although the terms mean slightly different things,[note 1] they tend to be confused and used interchangeably (including in VLC-related venues).

This page explains the most useful YUV pixel formats in the context of VLC media player. Unless otherwise stated, values for each component are stored in one octet (8 bits).

Contents

 [hide

Planar formats

Planar (or sometimes "triplanar") formats use separate matrices for each of the 3 color components. In other words, there is one table of luminance pixel values, and two separate tables for the chrominance components. This segregated representation in memory of pixels is more convenient for video coding.

YUV 4:2:0 (I420/J420/YV12)

I420

It has the luma "luminance" plane Y first, then the U chroma plane and last the V chroma plane.

The two chroma planes (blue and red projections) are sub-sampled in both the horizontal and vertical dimensions by a factor of 2. That is to say, for a 2×2 square of pixels, there are 4 Y samples but only 1 U sample and 1 V sample.

This format requires 4×8+8+8=48 bits per 4 pixels, so its depth is 12 bits per pixel.

I420 is by far the most common format in VLC. Most video decoders output raw pictures in I420 format.

A graphical illustration: Each letter represents one bit.

  • For a single I420 pixel: YYYYYYYY UU VV
  • For a 50-pixel I420 frame: YYYYYYYY×50 UU×50 VV×50 (or Y×8×50 U×2×50 V×2×50 for short)
  • For an n-pixel I420 frame: Y×8×n U×2×n V×2×n

J420

J420 is exactly like I420, but with a full range ("digital", 0-255) luma (Y) component instead of limited range ("analog", 16-240). The chroma planes are exactly the same as in I420.

YV12

YV12 is exactly like I420, but the order of the U and V planes is reversed. In the name, "YV" refers to the plane order: Y, then V (then U). "12" refers to the pixel depth: 12-bits per pixel as for I420.

YUV 4:2:2 (I422/J422)

I422

Like I420, I422 has one luma plane Y and 2 chroma planes UV.

However, in I422, chroma planes (blue and red projections) are sub-sampled only in the horizontal dimension, still by a factor of 2. Thus, there is the same amount of lines in chroma planes as in the luma plane.

For a 2×2 group of pixels, there are 4 Y samples and 2 U and 2 V samples each. The depth is 4×8+2×8+2×8=64 bits per 4 pixels, so 16 bits per pixel.

Some video codecs support I422 (optionally) for higher quality video encoding.

J422

J422 is exactly like I422, but with a full range ("digital", 0-255) luma (Y) component instead of limited range ("analog", 16-240). The chroma planes are exactly the same as in I422.

YUV 4:4:4

I444

As I420 and I422, I444 has one luma plane Y and 2 chroma planes U and V. Chroma planes are not sub-sampled: there are 3 octet values for each pixels. The depth is thus 24 bits per pixel (as with RGB24 or RGB32).

A few video codecs support I444 optionally.

Packed formats

In packed formats, you usually have only one plane, with all the luma and chroma data interleaved. This is similar to RGB pixel formats, only using a different color space.

Packed formats are very popular inside webcams. In hardware, using separate planes is inefficient: several memory accesses are needed for each pixel. Packed formats are easier and thus cheaper to use.

On the other hand, packet formats cannot normally deal with vertical sub-sampling. Otherwise scan lines would have different sizes. So generally, packed formats are horizontally subsampled, especially by a factor of 2 (i.e., YUV 4:2:2).

UYVY

Known as UYVYY422 or UYNV.

In UYVY, the chroma samples are sub-sampled by a factor of 2.

In UYVY, the succession for 2 pixels, starts by U then one luma if the first pixel, then V and then another luma for the second pixel.

YUY2

Known as YUY2YUYVV422 or YUNV.

In YUY2, the chroma samples are sub-sampled by a factor of 2.

In YUY2, the succession for 2 pixels, starts by one luma for the first pixel, then U, then another luma for the second pixel and then V again.

Conversion between YUY2 and UYVY is achieved by swapping bytes pairwise.

YVYU

YVYU is just like YUY2, but with U and V order reversed.

VYUV

TBD.

Semi-planar

Semi planar formats have two planes instead of three, one plane for luminance, and one plane for both chrominance components. They are also sometimes referred to as biplanar formats also.

NV12/NV21

NV12

Related to I420, NV12 has one luma "luminance" plane Y and one plane with U and V values interleaved.

In NV12, chroma planes (blue and red) are subsampled in both the horizontal and vertical dimensions by a factor of 2.

For a 2×2 group of pixels, you have 4 Y samples and 1 U and 1 V sample.

It can be helpful to think of NV12 as I420 with the U and V planes interleaved.

Here is a graphical representation of NV12. Each letter represents one bit:

  • For 1 NV12 pixel: YYYYYYYY UVUV
  • For a 2-pixel NV12 frame: YYYYYYYYYYYYYYYY UVUVUVUV
  • For a 50-pixel NV12 frame: Y×8×50 (UV)×2×50
  • For a n-pixel NV12 frame: Y×8×n (UV)×2×n

NV21

NV21 is like NV12, but with U and V order reversed: it starts with V.

Other NV formats

Following the same pattern as NV12/NV21, there are NV16/NV61 (4:2:2 sub-sampling) and NV24/NV42 (4:4:4 sampling) formats. They are mostly used in some funky cheap camera circuitry and not supported in VLC (as of VLC version 2.0).

Notes

Further reading

03-25
### YUV格式介绍 YUV是一种色彩空间表示法,主要用于视频编码、图像处理以及电视广播等领域。它通过将亮度(Luma, Y)和色度(Chroma, U/V)分离的方式,有效地减少了数据冗余并提升了压缩效率[^1]。 #### 数据结构与表现形式 YUV格式可以根据其内部的数据排列方式分为两种主要类别:**打包格式**和**平面格式**。 - **打包格式**是指Y、U、V分量按特定顺序交错存储在一个连续的内存块中,这种格式通常便于硬件访问和实时处理。 - **平面格式**则是将Y、U、V分别存放在独立的内存区域中,这种方式更适合软件操作和后期编辑[^2]。 #### 应用领域 1. **视频编码与压缩** YUV因其高效的压缩特性和良好的视觉质量,在现代视频编码标准中占据重要地位。无论是流媒体服务还是物理介质(如DVD、蓝光),都广泛采用基于YUV的颜色模型进行数据存储和传输。 2. **电视广播** 在传统模拟电视信号传输过程中,PAL和NTSC等制式均依赖于YUV体系来传递彩色画面信息。这不仅简化了信号调制流程,也增强了抗干扰能力。 3. **图像处理与计算机视觉** 利益于YUV独特的亮度/色度分解机制,该格式被频繁应用于诸如颜色匹配、对象识别及运动跟踪之类的高级算法开发当中。特别是针对人类皮肤色调检测的任务,利用YUV能取得更精确的结果。 4. **学习与研究工具支持** 针对希望深入理解或实际运用YUV格式的研究人员和技术爱好者们,存在一些公共资源可供下载使用。例如某开源项目就提供了标准化尺寸(1920×1080)下的样本文件集合及其配套可视化程序,极大地方便了相关人员的学习实践工作[^4]。 ```python import numpy as np from PIL import Image def yuv_to_rgb(yuv_image_path, width=1920, height=1080): """ 将YUV格式图片转换成RGB模式显示 参数: yuv_image_path (str): 输入YUV文件路径. width (int): 图像宽度,默认为1920像素. height (int): 图像高度,默认为1080像素. 返回: RGB图像实例. """ with open(yuv_image_path, 'rb') as f: raw_data = np.frombuffer(f.read(), dtype=np.uint8) # 假设输入的是NV12格式(YUV 4:2:0),调整数组形状 y_plane_size = width * height uv_plane_size = int(width / 2) * int(height / 2) y_channel = raw_data[:y_plane_size].reshape((height, width)) u_channel = raw_data[y_plane_size:y_plane_size + uv_plane_size].reshape((int(height / 2), int(width / 2))) v_channel = raw_data[y_plane_size + uv_plane_size:].reshape((int(height / 2), int(width / 2))) rgb_array = cv2.cvtColor(np.stack([y_channel,u_channel,v_channel], axis=-1),cv2.COLOR_YUV2BGR_NV12) return Image.fromarray(rgb_array,"RGB") if __name__ == "__main__": img = yuv_to_rgb('example.yuv') img.show() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值