关于视频YUV
这里有一篇摘自MSDN的文章。介绍了YUV视频数据格式。
About YUV Video
Digital video is often encoded in a YUV format. This article explains the general concepts of YUV video, along with some terminology, without going deeply into the mathematics of YUV video processing.
If you have worked with computer graphics, you are probably familiar with RGB color. An RGB color is encoded using three values: red, green, and blue. These values correspond directly to portions of the visible spectrum. The three RGB values form a mathematical
coordinate system, called a color space. The red component defines one axis of this coordinate system, blue defines the second, and green defines the third, as shown in the following illustration. Any valid RGB color falls somewhere within this color
space. For example, pure magenta is 100% blue, 100% red, and 0% green.
Although RGB is a common way to represent colors, other coordinate systems are possible. The term YUV refers to a family of color spaces, all of which encode brightness information separately from color information. Like RGB, YUV uses three values
to represent any color. These values are termed Y', U, and V. (In fact, this use of the term "YUV" is technically inaccurate. In computer video, the term YUV almost always refers to one particular color space named Y'CbCr, discussed later. However, YUV is
often used as a general term for any color space that works along the same principles as Y'CbCr.)
The Y' component, also called luma, represents the brightness value of the color. The prime symbol (') is used to differentiate luma from a closely related value, luminance, which is designated Y. Luminance is derived from linear RGB
values, whereas luma is derived from non-linear (gamma-corrected) RGB values. Luminance is a closer measure of true brightness but luma is more practical to use for technical reasons. The prime symbol is frequently omitted, but YUV color spaces always
use luma, not luminance.
Luma is derived from an RGB color by taking a weighted average of the red, green, and blue components. For standard-definition television, the following formula is used:
Y' = 0.299R + 0.587G + 0.114B
This formula reflects the fact that the human eye is more sensitive to certain wavelengths of light than others, which affects the perceived brightness of a color. Blue light appears dimmest, green appears brightest, and red is somewhere in between. This formula
also reflects the physical characteristics of the phosphors used in early televisions. A newer formula, taking into account modern television technology, is used for high-definition television:
Y' = 0.2125R + 0.7154G + 0.0721B
The luma equation for standard-definition television is defined in a specification named ITU-R BT.601. For high-definition television, the relevant specification is ITU-R BT.709.
The U and V components, also called chroma values or color difference values, are derived by subtracting the Y value from the red and blue components of the original RGB color:
U = B - Y'
V = R - Y'
Together, these values contain enough information to recover the original RGB value.
Benefits
of YUV
Analog television uses YUV partly for historical reasons. Analog color television signals were designed to be backward compatible with black-and-white televisions. The color television signal carries the chroma information (U and V) superimposed onto the luma
signal. Black-and-white televisions ignore the chroma and display the combined signal as a grayscale image. (The signal is designed so that the chroma does not significantly interfere with the luma signal.) Color televisions can extract the chroma and convert
the signal back to RGB.
YUV has another advantage that is more relevant today. The human eye is less sensitive to changes in hue than changes in brightness. As a result, an image can have less chroma information than luma information without sacrificing the perceived quality of the
image. For example, it is common to sample the chroma values at half the horizontal resolution of the luma samples. In other words, for every two luma samples in a row of pixels, there is one U sample and one V sample. Assuming that 8 bits are used to encode
each value, a total of 4 bytes are needed for every two pixels (two Y', one U, and one V), for an average of 16 bits per pixel, or 30% less than the equivalent 24-bit RGB encoding.
YUV is not inherently any more compact than RGB. Unless the chroma is downsampled, a YUV pixel is the same size as an RGB pixel. Also, the conversion from RGB to YUV is not lossy. If there is no downsampling, a YUV pixel can be converted back to RGB with no
loss of information. Downsampling makes a YUV image smaller and also loses some of the color information. If performed correctly, however, the loss is not perceptually significant.
YUV
in Computer Video
The formulas listed previously for YUV are not the exact conversions used in digital video. Digital video generally uses a form of YUV called Y'CbCr. Essentially, Y'CbCr works by scaling the YUV components to the following ranges:
Component | Range |
---|---|
Y' | 16–235 |
Cb/Cr | 16–240, with 128 representing zero |
These ranges assume 8 bits of precision for the Y'CbCr components. Here is the exact derivation of Y'CbCr, using the BT.601 definition of luma:
- Start with RGB values in the range [0...1]. In other words, pure black is 0 and pure white is 1. Importantly, these are non-linear (gamma corrected) RGB values.
- Calculate the luma. For BT.601, Y' = 0.299R + 0.587G + 0.114B, as described earlier.
- Calculate the intermediate chroma difference values (B - Y') and (R - Y'). These values have a range of +/- 0.886 for (B - Y'), and +/- 0.701 for (R - Y').
Scale the chroma difference values as follows:
Pb = (0.5 / (1 - 0.114)) × (B - Y')
Pr = (0.5 / (1 - 0.299)) × (R - Y')
These scaling factors are designed to give both values the same numerical range, +/- 0.5. Together, they define a YUV color space named Y'PbPr. This color space is used in analog component video.
Scale the Y'PbPr values to get the final Y'CbCr values:
Y' = 16 + 219 × Y'
Cb = 128 + 224 × Pb
Cr = 128 + 224 × Pr
These last scaling factors produce the range of values listed in the previous table. Of course, you can convert RGB directly to Y'CbCr without storing the intermediate results. The steps are listed separately here to show how Y'CbCr derives from the original
YUV equations given at the beginning of this article.
The following table shows RGB and YCbCr values for various colors, again using the BT.601 definition of luma.
Color | R | G | B | Y' | Cb | Cr |
---|---|---|---|---|---|---|
Black | 0 | 0 | 0 | 16 | 128 | 128 |
Red | 255 | 0 | 0 | 81 | 90 | 240 |
Green | 0 | 255 | 0 | 145 | 54 | 34 |
Blue | 0 | 0 | 255 | 41 | 240 | 110 |
Cyan | 0 | 255 | 255 | 170 | 166 | 16 |
Magenta | 255 | 0 | 255 | 106 | 202 | 222 |
Yellow | 255 | 255 | 0 | 210 | 16 | 146 |
White | 255 | 255 | 255 | 235 | 128 | 128 |
As this table shows, Cb and Cr do not correspond to intuitive ideas about color. For example, pure white and pure black both contain neutral levels of Cb and Cr (128). The highest and lowest values for Cb are blue and yellow, respectively. For Cr, the highest
and lowest values are red and cyan.
For
More Information
- Recommended
8-Bit YUV Formats for Video Rendering - Keith Jack. Video Demystified, Fifth Edition. Newnes, 2007.
- Charles A. Poynton. A Technical Introduction to Digital Video. Wiley, 1996.
Related topics
http://msdn.microsoft.com/en-us/library/windows/desktop/bb530104(v=vs.85).aspx
关于视频YUV的更多相关文章
- 音视频处理基础知识扫盲:数字视频YUV像素表示法以及视频帧和编解码概念介绍
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt+moviepy音视频剪辑实战 专栏:PyQt入门学习 老猿Python博文目录 老猿学5G博文目录 一. ...
- 使用ffmpeg将BMP图片编码为x264视频文件,将H264视频保存为BMP图片,yuv视频文件保存为图片的代码
ffmpeg开源库,实现将bmp格式的图片编码成x264文件,并将编码好的H264文件解码保存为BMP文件. 实现将视频文件yuv格式保存的图片格式的測试,图像格式png,jpg, gif等等測试均O ...
- 最简单的基于FFMPEG的视频编码器(YUV编码为H.264)
本文介绍一个最简单的基于FFMPEG的视频编码器.该编码器实现了YUV420P的像素数据编码为H.264的压缩编码数据.编码器代码十分简单,可是每一行代码都非常重要,适合好好研究一下.弄清楚了本代码也 ...
- 最简单的基于FFmpeg的视频编码器-更新版(YUV编码为HEVC(H.265))
===================================================== 最简单的基于FFmpeg的视频编码器文章列表: 最简单的基于FFMPEG的视频编码器(YUV ...
- 利用FFmpeg玩转Android视频录制与压缩(二)<转>
转载出处:http://blog.csdn.net/mabeijianxi/article/details/72983362 预热 时光荏苒,光阴如梭,离上一次吹牛逼已经过去了两三个月,身边很多人的女 ...
- 【视频开发】Nvidia硬解码总结
Nvidia硬解码总结 1.前言 本文的主要目的是对近期进行的nvidia硬件解码工作的记录和总结.至于为什么研究nvidia硬件解码的具体内容,其实主要是为了在项目中能够利用nvidia的硬件解码和 ...
- moviepy音视频剪辑:颜色相关变换函数blackwhite、colorx、fadein/out、gamma_corr、invert_colors、lum_contrast、mask_color介绍
☞ ░ 前往老猿Python博文目录 ░ 一.引言 在<moviepy音视频剪辑:moviepy中的剪辑基类Clip详解>介绍了剪辑基类的fl.fl_time.fx方法,在<movi ...
- moviepy音视频剪辑:lum_contrast什么时候使用以及图像处理什么时候需要调整亮度与对比度
☞ ░ 前往老猿Python博文目录 ░ 一.亮度.对比度的概念 图像的亮度(luminosity )也即对明度的度量(参考<音视频处理基础知识扫盲:数字视频YUV像素表示法以及视频帧和编解码概 ...
- Python+moviepy音视频剪辑:视频帧数据的本质、Clip的fl方法进行变换处理的原理以及滚屏案例
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt+moviepy音视频剪辑实战 专栏:PyQt入门学习 老猿Python博文目录 老猿学5G博文目录 一. ...
随机推荐
- Understanding Cache Access
URL Loading System提供了综合的disk 和 in-memory 策略的请求缓存.使用缓存有利于减少程序对网络的依赖,并且能提高程序的体验. Using the Cache for a ...
- HDU 5293 Annoying problem 树形dp dfs序 树状数组 lca
Annoying problem 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5293 Description Coco has a tree, w ...
- Codeforces Round #301 (Div. 2) C. Ice Cave BFS
C. Ice Cave Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/problem/C ...
- svn服务器搭建及使用 二
上一篇介绍了VisualSVN Server和TortoiseSVN的下载,安装,汉化.这篇介绍一下如何使用VisualSVN Server建立版本库,以及TortoiseSVN的使用. 首先打开Vi ...
- webstrom内置压缩工具YUI-compressor详解
压缩工具层次不穷,各有优点,选择适合的压缩工具为将来做项目开发使用是一件很重要的事情!!在这介绍YUI-compressor 英文官网:http://yui.github.io/yuicompress ...
- [Js插件]使用JqueryUI的弹出框做一个“炫”的登录页面
引言 查看项目代码的时候,发现项目中用到JqueryUi的弹出框,可拖拽,可设置模式对话框,就想着使用它弄一个登录页面. 弹出框 在Jquery Ui官网可定制下载弹出框,下载和弹出框下载相关的js文 ...
- SqlServer收缩数据库语句
ALTER DATABASE [Spacebuilder] SET RECOVERY SIMPLEDBCC SHRINKDATABASE([Spacebuilder], 0)ALTER DATABAS ...
- 企业应用:浅谈 “数据权限” 和 查询 API 设计
背景 多数企业应用都需要对数据权限进行控制,如:某个用户只能看到某个范围的数据(数据行).某个用户只能看到某几列数据(数据列).本文以数据行级别的权限控制为范例,谈谈如何设计权限模型和查询 API. ...
- iOS:CoreData数据库的使用二(创建多个数据库表,表之间有对应关系)
CoreData数据库框架是一个封装性好,功能强大数据库,它底层使用的还是sqlite数据库,不过苹果公司在其基础上,为其封装新和安全性的维护上做了大量的处理,例如对一些事物做了详细的操作,如读脏数据 ...
- GSM模块_STM32实现GPRS与服务器数据传输经验总结
硬件环境 MCU:STM32F103RET6 (调试器:J-Link) GSM模块:Ai-Thinker_A6 (安信可)(还需要配一个串口打印工具,当初选这个模块纯粹是因为价格是最便宜的) ---- ...