{"id":49,"date":"2007-11-15T17:18:51","date_gmt":"2007-11-16T01:18:51","guid":{"rendered":"http:\/\/multimedia.cx\/eggs\/yuv-and-rgb\/"},"modified":"2007-11-15T22:54:17","modified_gmt":"2007-11-16T06:54:17","slug":"yuv-and-rgb","status":"publish","type":"post","link":"https:\/\/multimedia.cx\/eggs\/yuv-and-rgb\/","title":{"rendered":"Video Coding Concepts: YUV and RGB Colorspaces And Pixel Formats"},"content":{"rendered":"<p>If you have any experience in programming computer graphics, you probably know all about red\/green\/blue (RGB) video modes and pixel formats. Guess what? It is all useless now that you are working on video codec technology!<\/p>\n<p>No, that&#8217;s not entirely true. Some video codecs operate on RGB video natively. A majority of modern codecs use some kind of YUV colorspace. We will get to that. Since many programmers are familiar with RGB pixel formats, let&#8217;s use that as a starting point.<\/p>\n<p><strong>RGB Colors<\/strong><\/p>\n<p>To review, computers generally display RGB pixels. These pixels have red (R), green (G), and blue (B) components to them. Here are the various combinations of R, G, and B components at their minimum (0) and maximum (255\/0xFF) values:<\/p>\n<table border=\"1\" cellpadding=\"2\">\n<tr>\n<th>R<\/th>\n<th>G<\/th>\n<th>B<\/th>\n<th>color<\/th>\n<th>notes:<\/th>\n<\/tr>\n<tr>\n<td>0x00<\/td>\n<td>0x00<\/td>\n<td>0x00<\/td>\n<td width=\"256\" height=\"32\" bgcolor=\"#000000\"><\/td>\n<td><em>absence of R, G, and B = full black<\/em><\/td>\n<\/tr>\n<tr>\n<td>0x00<\/td>\n<td>0x00<\/td>\n<td>0xFF<\/td>\n<td width=\"256\" height=\"32\" bgcolor=\"#0000ff\"><\/td>\n<td><em>full blue<\/em><\/td>\n<\/tr>\n<tr>\n<td>0x00<\/td>\n<td>0xFF<\/td>\n<td>0x00<\/td>\n<td width=\"256\" height=\"32\" bgcolor=\"#00ff00\"><\/td>\n<td><em>full green<\/em><\/td>\n<\/tr>\n<tr>\n<td>0x00<\/td>\n<td>0xFF<\/td>\n<td>0xFF<\/td>\n<td width=\"256\" height=\"32\" bgcolor=\"#00ffff\"><\/td>\n<\/tr>\n<tr>\n<td>0xFF<\/td>\n<td>0x00<\/td>\n<td>0x00<\/td>\n<td width=\"256\" height=\"32\" bgcolor=\"#ff0000\"><\/td>\n<td><em>full red<\/em><\/td>\n<\/tr>\n<tr>\n<td>0xFF<\/td>\n<td>0x00<\/td>\n<td>0xFF<\/td>\n<td width=\"256\" height=\"32\" bgcolor=\"#ff00ff\"><\/td>\n<\/tr>\n<tr>\n<td>0xFF<\/td>\n<td>0xFF<\/td>\n<td>0x00<\/td>\n<td width=\"256\" height=\"32\" bgcolor=\"#ffff00\"><\/td>\n<\/tr>\n<tr>\n<td>0xFF<\/td>\n<td>0xFF<\/td>\n<td>0xFF<\/td>\n<td width=\"256\" height=\"32\" bgcolor=\"#ffffff\"><\/td>\n<td><em>full R, G, and B combine to make full white<\/em><\/td>\n<\/tr>\n<\/table>\n<p><strong>YUV Colors<\/strong><br \/>\nIf you are used to dealing with RGB colors, YUV will seem a bit unintuitive at first. What does YUV stand for? Nothing you would guess. It turns out Y stands for intensity. U stands for blue and V stands for red. U is also denoted as C<sub>b<\/sub> and V is also denoted as C<sub>r<\/sub>. So YUV is sometimes written as YC<sub>b<\/sub>C<sub>r<\/sub>. <\/p>\n<p>Here are the various combinations of Y, U, and V components at their minimum (0) and maximum (255\/0xFF) values:<\/p>\n<table border=\"1\" cellpadding=\"2\">\n<tr>\n<th>Y<\/th>\n<th>U\/<br \/>C<sub>b<\/sub><\/th>\n<th>V\/<br \/>C<sub>r<\/sub><\/th>\n<th>color<\/th>\n<th>notes<\/th>\n<\/tr>\n<tr>\n<td>0x00<\/td>\n<td>0x00<\/td>\n<td>0x00<\/td>\n<td><img decoding=\"async\" src=\"\/eggs\/images\/yuv-00-00-00.png\" alt=\"\" \/><\/td>\n<\/tr>\n<tr>\n<td>0x00<\/td>\n<td>0x00<\/td>\n<td>0xFF<\/td>\n<td><img decoding=\"async\" src=\"\/eggs\/images\/yuv-00-00-ff.png\" alt=\"\" \/><\/td>\n<\/tr>\n<tr>\n<td>0x00<\/td>\n<td>0xFF<\/td>\n<td>0x00<\/td>\n<td><img decoding=\"async\" src=\"\/eggs\/images\/yuv-00-ff-00.png\" alt=\"\" \/><\/td>\n<\/tr>\n<tr>\n<td>0x00<\/td>\n<td>0xFF<\/td>\n<td>0xFF<\/td>\n<td><img decoding=\"async\" src=\"\/eggs\/images\/yuv-00-ff-ff.png\" alt=\"\" \/><\/td>\n<\/tr>\n<tr>\n<td>0xFF<\/td>\n<td>0x00<\/td>\n<td>0x00<\/td>\n<td><img decoding=\"async\" src=\"\/eggs\/images\/yuv-ff-00-00.png\" alt=\"\" \/><\/td>\n<td><em>full green<\/em><\/td>\n<\/tr>\n<tr>\n<td>0xFF<\/td>\n<td>0x00<\/td>\n<td>0xFF<\/td>\n<td><img decoding=\"async\" src=\"\/eggs\/images\/yuv-ff-00-ff.png\" alt=\"\" \/><\/td>\n<\/tr>\n<tr>\n<td>0xFF<\/td>\n<td>0xFF<\/td>\n<td>0x00<\/td>\n<td><img decoding=\"async\" src=\"\/eggs\/images\/yuv-ff-ff-00.png\" alt=\"\" \/><\/td>\n<\/tr>\n<tr>\n<td>0xFF<\/td>\n<td>0xFF<\/td>\n<td>0xFF<\/td>\n<td><img decoding=\"async\" src=\"\/eggs\/images\/yuv-ff-ff-ff.png\" alt=\"\" \/><\/td>\n<\/tr>\n<tr>\n<td>0x00<\/td>\n<td>0x80<\/td>\n<td>0x80<\/td>\n<td><img decoding=\"async\" src=\"\/eggs\/images\/yuv-00-80-80.png\" alt=\"\" \/><\/td>\n<td><em>full black<\/em><\/td>\n<\/tr>\n<tr>\n<td>0x80<\/td>\n<td>0x80<\/td>\n<td>0x80<\/td>\n<td><img decoding=\"async\" src=\"\/eggs\/images\/yuv-80-80-80.png\" alt=\"\" \/><\/td>\n<\/tr>\n<tr>\n<td>0xFF<\/td>\n<td>0x80<\/td>\n<td>0x80<\/td>\n<td><img decoding=\"async\" src=\"\/eggs\/images\/yuv-ff-80-80.png\" alt=\"\" \/><\/td>\n<td><em>full white<\/em><\/td>\n<\/tr>\n<\/table>\n<p>So, all minimum and all maximum components do not generate intuitive (read: similar to RGB) results. In fact, all 0s in the YUV colorspace result in a dull green rather than black. That last point is useful to understand when a video is displaying a lot of green block errors&#8211; that probably means that the decoder is skipping blocks of data completely and leaving the underlying YUV data as all 0.<\/p>\n<p><strong>Further Reading:<\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/wiki.multimedia.cx\/index.php?title=YCbCr\">YC<sub>b<\/sub>C<sub>r<\/sub><\/a> at the MultimediaWiki<\/li>\n<li><a href=\"http:\/\/wiki.multimedia.cx\/index.php?title=Category:YCbCr_Formats\">YC<sub>b<\/sub>C<sub>r<\/sub> Formats <\/a> category page at the MultimediaWiki<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Understanding all of those different pixel formats&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,16],"tags":[],"class_list":["post-49","post","type-post","status-publish","format-standard","hentry","category-codec-technology","category-video-codecs"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/49","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/comments?post=49"}],"version-history":[{"count":0,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/49\/revisions"}],"wp:attachment":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/media?parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/categories?post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/tags?post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}