H264参数结构

settingBtn

<div id="article_content" class="article_content clearfix csdn-tracking-statistics" data-pid="blog" data-mod="popu_307" data-dsm="post">
								            <link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-e2445db1a8.css">
						<div class="htmledit_views">
                <h1 style="border-width:0px 0px 0px 5px;border-left-style:solid;border-left-color:rgb(44,166,203);font-weight:inherit;font-style:inherit;font-family:inherit;font-size:32px;vertical-align:baseline;line-height:1.5;"><a name="t0"></a><a href="http://www.iosxxx.com/blog/2017-08-09-%E4%BB%8E%E9%9B%B6%E4%BA%86%E8%A7%A3H264%E7%BB%93%E6%9E%84.html" rel="nofollow" title="从零了解H264结构" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(44,166,203);" target="_blank">从零了解H264结构</a></h1><p class="article-time" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:.9em;vertical-align:baseline;text-align:center;">&nbsp;<br></p><div class="article-content" style="border:0px;font-family:'Helvetica Neue', Helvetica, 'Microsoft YaHei', 'WenQuanYi Micro Hei', Arial, sans-serif;vertical-align:baseline;color:rgb(65,63,63);background-color:rgb(250,250,250);">转自:http://www.iosxxx.com/blog/2017-08-09-%E4%BB%8E%E9%9B%B6%E4%BA%86%E8%A7%A3H264%E7%BB%93%E6%9E%84.html<br><h2 style="border-width:0px 0px 2px;border-bottom-style:solid;border-bottom-color:rgb(219,219,219);font-weight:inherit;font-style:inherit;font-family:inherit;font-size:28.8px;vertical-align:baseline;line-height:1.2em;color:rgb(51,51,51);"><a name="t1"></a><a href="http://www.iosxxx.com/blog/2017-08-09-%E4%BB%8E%E9%9B%B6%E4%BA%86%E8%A7%A3H264%E7%BB%93%E6%9E%84.html#%E5%89%8D%E8%A8%80" rel="nofollow" class="headerlink" title="前言" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:28.8px;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"></a>前言</h2><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;">建议先看一下<a href="http://www.iosxxx.com/" rel="nofollow" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(44,166,203);" target="_blank">FFmpeg3的iOS版的入门格式转换器(无编码)</a>,我们可以了解H264处于编解码层。为什么需要编码呢?比如当前屏幕是1280*720.一秒24张图片.那么我们一秒的视频数据是</p><table style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;border-spacing:0px;"><tbody style="font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:baseline;"><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:baseline;"><td class="gutter" style="border-style:none;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;line-height:1.3em;"><pre style="border:none;font-weight:inherit;font-style:inherit;font-family:Monaco, Menlo, Consolas, 'Courier New', monospace;font-size:.9em;vertical-align:baseline;background:rgb(238,238,238);color:rgb(153,153,153);line-height:1.5;text-align:right;"><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;">1</span><br></pre></td><td class="code" style="border-style:none;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;line-height:1.3em;"><pre style="border:none;font-weight:inherit;font-style:inherit;font-family:Monaco, Menlo, Consolas, 'Courier New', monospace;font-size:.9em;vertical-align:baseline;background:rgb(238,238,238);color:rgb(77,77,76);line-height:1.5;"><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;"><span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">1280</span>*<span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">720</span>(位像素)*<span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">24</span>(张) / <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">8</span>(<span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">1</span>字节<span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">8</span>位)(结果:B) / <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">1024</span>(结果:KB) / <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">1024</span> (结果:MB) =  <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">2.64</span>MB</span><br></pre></td></tr></tbody></table><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;">一秒的数据有2.64MB数据量。1分钟就会有100多MB。这对用户来说真心是灾难。所以现在我们需要一种压缩方式减小数据的大小.在更低 比特率(bps)的情况下依然提供清晰的视频。<br>H264: H264/AVC是广泛采用的一种编码方式。我们这边会带大家了解。从大到小排序依次是 序列,图像,片组,片,NALU,宏块,亚宏块,块,像素。</p><h2 style="border-width:0px 0px 2px;border-bottom-style:solid;border-bottom-color:rgb(219,219,219);font-weight:inherit;font-style:inherit;font-family:inherit;font-size:28.8px;vertical-align:baseline;line-height:1.2em;color:rgb(51,51,51);"><a name="t2"></a><a href="http://www.iosxxx.com/blog/2017-08-09-%E4%BB%8E%E9%9B%B6%E4%BA%86%E8%A7%A3H264%E7%BB%93%E6%9E%84.html#%E4%B8%80-%E5%8E%9F%E7%90%86" rel="nofollow" class="headerlink" title="一. 原理" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:28.8px;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"></a>一. 原理</h2><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;">H.264原始码流(裸流)是由一个接一个NALU组成,它的功能分为两层,VCL(视频编码层)和 NAL(网络提取层).</p><table style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;border-spacing:0px;"><tbody style="font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:baseline;"><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:baseline;"><td class="gutter" style="border-style:none;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;line-height:1.3em;"><pre style="border:none;font-weight:inherit;font-style:inherit;font-family:Monaco, Menlo, Consolas, 'Courier New', monospace;font-size:.9em;vertical-align:baseline;background:rgb(238,238,238);color:rgb(153,153,153);line-height:1.5;text-align:right;"><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;">1</span><br></pre></td><td class="code" style="border-style:none;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;line-height:1.3em;"><pre style="border:none;font-weight:inherit;font-style:inherit;font-family:Monaco, Menlo, Consolas, 'Courier New', monospace;font-size:.9em;vertical-align:baseline;background:rgb(238,238,238);color:rgb(77,77,76);line-height:1.5;"><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;">VCL(Video Coding Layer) + NAL(Network Abstraction Layer).</span><br></pre></td></tr></tbody></table><ol style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;list-style:none;"><li style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;">VCL:包括核心压缩引擎和块,宏块和片的语法级别定义,设计目标是尽可能地独立于网络进行高效的编码;</li><li style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;">NAL:负责将VCL产生的比特字符串适配到各种各样的网络和多元环境中,覆盖了所有片级以上的语法级别。</li></ol><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;">在VCL进行数据传输或存储之前,这些编码的VCL数据,被映射或封装进NAL单元。(NALU)。</p><table style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;border-spacing:0px;"><tbody style="font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:baseline;"><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:baseline;"><td class="gutter" style="border-style:none;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;line-height:1.3em;"><pre style="border:none;font-weight:inherit;font-style:inherit;font-family:Monaco, Menlo, Consolas, 'Courier New', monospace;font-size:.9em;vertical-align:baseline;background:rgb(238,238,238);color:rgb(153,153,153);line-height:1.5;text-align:right;"><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;">1</span><br></pre></td><td class="code" style="border-style:none;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;line-height:1.3em;"><pre style="border:none;font-weight:inherit;font-style:inherit;font-family:Monaco, Menlo, Consolas, 'Courier New', monospace;font-size:.9em;vertical-align:baseline;background:rgb(238,238,238);color:rgb(77,77,76);line-height:1.5;"><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;">一个NALU = 一组对应于视频编码的NALU头部信息 + 一个原始字节序列负荷(RBSP,Raw Byte Sequence Payload).</span><br></pre></td></tr></tbody></table><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;">如图所示,上图中的NALU的头 + RBSP 就相当于一个NALU(Nal Unit),每个单元都按独立的NALU传送。H.264的结构全部都是以NALU为主,理解了NALU,就理解了H.264的结构。<br>一个原始的H.264 NALU 单元常由 [StartCode] [NALU Header] [NALU Payload] 三部分组成,其中 Start Code 用于标示这是一个NALU 单元的开始,必须是”00 00 00 01” 或”00 00 01”</p><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;"><a href="http://www.iosxxx.com/images/h264base/05.png" rel="nofollow" title="" class="fancybox" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"><img src="http://www.iosxxx.com/images/h264base/05.png" alt="" style="border:none;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:middle;"></a></p><h4 style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:22.4px;vertical-align:baseline;color:rgb(51,51,51);"><a href="http://www.iosxxx.com/blog/2017-08-09-%E4%BB%8E%E9%9B%B6%E4%BA%86%E8%A7%A3H264%E7%BB%93%E6%9E%84.html#1-NAL-Header" rel="nofollow" class="headerlink" title="1. NAL Header" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:22.4px;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"></a>1. NAL Header</h4><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;">由三部分组成,forbidden_bit(1bit),nal_reference_bit(2bits)(优先级),nal_unit_type(5bits)(类型)。</p><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;"><a href="http://www.iosxxx.com/images/h264base/08.png" rel="nofollow" title="" class="fancybox" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"><img src="http://www.iosxxx.com/images/h264base/08.png" alt="" style="border:none;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:middle;"></a></p><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;">举例来说:</p><table style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;border-spacing:0px;"><tbody style="font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:baseline;"><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:baseline;"><td class="gutter" style="border-style:none;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;line-height:1.3em;"><pre style="border:none;font-weight:inherit;font-style:inherit;font-family:Monaco, Menlo, Consolas, 'Courier New', monospace;font-size:.9em;vertical-align:baseline;background:rgb(238,238,238);color:rgb(153,153,153);line-height:1.5;text-align:right;"><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;">1</span><br><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;">2</span><br><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;">3</span><br><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;">4</span><br></pre></td><td class="code" style="border-style:none;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;line-height:1.3em;"><pre style="border:none;font-weight:inherit;font-style:inherit;font-family:Monaco, Menlo, Consolas, 'Courier New', monospace;font-size:.9em;vertical-align:baseline;background:rgb(238,238,238);color:rgb(77,77,76);line-height:1.5;"><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;"><span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">00</span> <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">00</span> <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">00</span> <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">01</span> <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">06</span>:  SEI信息   </span><br><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;"><span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">00</span> <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">00</span> <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">00</span> <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">01</span> <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">67</span>:  <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">0x67</span>&amp;<span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">0x1f</span> = <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">0x07</span> :SPS</span><br><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;"><span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">00</span> <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">00</span> <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">00</span> <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">01</span> <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">68</span>:  <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">0x68</span>&amp;<span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">0x1f</span> = <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">0x08</span> :PPS</span><br><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;"><span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">00</span> <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">00</span> <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">00</span> <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">01</span> <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">65</span>:  <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">0x65</span>&amp;<span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">0x1f</span> = <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">0x05</span>: IDR Slice</span><br></pre></td></tr></tbody></table><h4 style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:22.4px;vertical-align:baseline;color:rgb(51,51,51);"><a href="http://www.iosxxx.com/blog/2017-08-09-%E4%BB%8E%E9%9B%B6%E4%BA%86%E8%A7%A3H264%E7%BB%93%E6%9E%84.html#2-RBSP" rel="nofollow" class="headerlink" title="2. RBSP" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:22.4px;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"></a>2. RBSP</h4><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;"><a href="http://www.iosxxx.com/images/h264base/09.png" rel="nofollow" title="" class="fancybox" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"><img src="http://www.iosxxx.com/images/h264base/09.png" alt="" style="border:none;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:middle;"></a><br>图 6.69 RBSP 序列举例</p><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;"><a href="http://www.iosxxx.com/images/h264base/10.png" rel="nofollow" title="" class="fancybox" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"><img src="http://www.iosxxx.com/images/h264base/10.png" alt="" style="border:none;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:middle;"></a><br>表 6.25 RBSP 描述.</p><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;"><span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">SODB与RBSP</span><br>SODB 数据比特串 -&gt; 是编码后的原始数据.<br>RBSP 原始字节序列载荷 -&gt; 在原始编码数据的后面添加了 结尾比特。一个 bit“1”若干比特“0”,以便字节对齐。<br><a href="http://www.iosxxx.com/images/h264base/12.png" rel="nofollow" title="" class="fancybox" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"><img src="http://www.iosxxx.com/images/h264base/12.png" alt="" style="border:none;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:middle;"></a></p><h2 style="border-width:0px 0px 2px;border-bottom-style:solid;border-bottom-color:rgb(219,219,219);font-weight:inherit;font-style:inherit;font-family:inherit;font-size:28.8px;vertical-align:baseline;line-height:1.2em;color:rgb(51,51,51);"><a name="t3"></a><a href="http://www.iosxxx.com/blog/2017-08-09-%E4%BB%8E%E9%9B%B6%E4%BA%86%E8%A7%A3H264%E7%BB%93%E6%9E%84.html#%E4%BA%8C-%E4%BB%8ENALU%E5%87%BA%E5%8F%91%E4%BA%86%E8%A7%A3H-264%E9%87%8C%E9%9D%A2%E7%9A%84%E4%B8%93%E4%B8%9A%E8%AF%8D%E8%AF%AD" rel="nofollow" class="headerlink" title="二. 从NALU出发了解H.264里面的专业词语" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:28.8px;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"></a>二. 从NALU出发了解H.264里面的专业词语</h2><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;"><a href="http://www.iosxxx.com/images/h264base/06.png" rel="nofollow" title="" class="fancybox" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"><img src="http://www.iosxxx.com/images/h264base/06.png" alt="" style="border:none;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:middle;"></a></p><table style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;border-spacing:0px;"><tbody style="font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:baseline;"><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:baseline;"><td class="gutter" style="border-style:none;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;line-height:1.3em;"><pre style="border:none;font-weight:inherit;font-style:inherit;font-family:Monaco, Menlo, Consolas, 'Courier New', monospace;font-size:.9em;vertical-align:baseline;background:rgb(238,238,238);color:rgb(153,153,153);line-height:1.5;text-align:right;"><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;">1</span><br><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;">2</span><br><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;">3</span><br></pre></td><td class="code" style="border-style:none;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;line-height:1.3em;"><pre style="border:none;font-weight:inherit;font-style:inherit;font-family:Monaco, Menlo, Consolas, 'Courier New', monospace;font-size:.9em;vertical-align:baseline;background:rgb(238,238,238);color:rgb(77,77,76);line-height:1.5;"><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;"><span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">1</span>帧 = n个片</span><br><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;"><span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">1</span>片 = n个宏块</span><br><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;"><span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">1</span>宏块 = <span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">16</span>x16yuv数据</span><br></pre></td></tr></tbody></table><h4 style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:22.4px;vertical-align:baseline;color:rgb(51,51,51);"><a href="http://www.iosxxx.com/blog/2017-08-09-%E4%BB%8E%E9%9B%B6%E4%BA%86%E8%A7%A3H264%E7%BB%93%E6%9E%84.html#1-Slice-%E7%89%87" rel="nofollow" class="headerlink" title="1. Slice(片)" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:22.4px;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"></a>1. Slice(片)</h4><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;">如图所示,NALU的主体中包含了Slice(片).</p><table style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;border-spacing:0px;"><tbody style="font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:baseline;"><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:baseline;"><td class="gutter" style="border-style:none;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;line-height:1.3em;"><pre style="border:none;font-weight:inherit;font-style:inherit;font-family:Monaco, Menlo, Consolas, 'Courier New', monospace;font-size:.9em;vertical-align:baseline;background:rgb(238,238,238);color:rgb(153,153,153);line-height:1.5;text-align:right;"><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;">1</span><br></pre></td><td class="code" style="border-style:none;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;line-height:1.3em;"><pre style="border:none;font-weight:inherit;font-style:inherit;font-family:Monaco, Menlo, Consolas, 'Courier New', monospace;font-size:.9em;vertical-align:baseline;background:rgb(238,238,238);color:rgb(77,77,76);line-height:1.5;"><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;">一个片 = Slice Header + Slice Data</span><br></pre></td></tr></tbody></table><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;">片是H.264提出的新概念,通过编码图片后切分通过高效的方式整合出来的概念。一张图片有一个或者多个片,而片由NALU装载并进行网络传输的。但是NALU不一定是切片,这是充分不必要条件,因为 NALU 还有可能装载着其他用作描述视频的信息.</p><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;"><span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">那么为什么要设置片呢?</span><br>设置片的目的是为了限制误码的扩散和传输,应使编码片相互间是独立的。某片的预测不能以其他片中的宏块为参考图像,这样某一片中的预测误差才不会传播到其他片中。</p><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;">可以看到上图中,每个图像中,若干宏块(Macroblock)被排列成片。一个视频图像可编程一个或更多个片,每片包含整数个宏块 (MB),每片至少包含一个宏块。<br><span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">片有一下五种类型:</span></p><table style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;border-spacing:0px;"><thead style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><th style="border-width:0px 0px 2px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">片</th><th style="border-width:0px 0px 2px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">意义</th></tr></thead><tbody style="font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">I 片</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">只包含I宏块</td></tr><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">P 片</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">包含P和I宏块</td></tr><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">B 片</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">包含B和I宏块</td></tr><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">SP 片</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">包含P 和/或 I宏块,用于不同码流之间的切换</td></tr><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">SI 片</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">一种特殊类型的编码宏块</td></tr></tbody></table><h4 style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:22.4px;vertical-align:baseline;color:rgb(51,51,51);"><a href="http://www.iosxxx.com/blog/2017-08-09-%E4%BB%8E%E9%9B%B6%E4%BA%86%E8%A7%A3H264%E7%BB%93%E6%9E%84.html#2-%E5%AE%8F%E5%9D%97-Macroblock" rel="nofollow" class="headerlink" title="2. 宏块(Macroblock)" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:22.4px;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"></a>2. 宏块(Macroblock)</h4><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;">刚才在片中提到了宏块.<span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">那么什么是宏块呢?</span><br>宏块是视频信息的主要承载者。一个编码图像通常划分为多个<span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">宏块</span>组成.包含着每一个像素的亮度和色度信息。视频解码最主要的工作则是提供高效的方式从码流中获得宏块中像素阵列。</p><table style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;border-spacing:0px;"><tbody style="font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:baseline;"><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:baseline;"><td class="gutter" style="border-style:none;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;line-height:1.3em;"><pre style="border:none;font-weight:inherit;font-style:inherit;font-family:Monaco, Menlo, Consolas, 'Courier New', monospace;font-size:.9em;vertical-align:baseline;background:rgb(238,238,238);color:rgb(153,153,153);line-height:1.5;text-align:right;"><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;">1</span><br></pre></td><td class="code" style="border-style:none;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;line-height:1.3em;"><pre style="border:none;font-weight:inherit;font-style:inherit;font-family:Monaco, Menlo, Consolas, 'Courier New', monospace;font-size:.9em;vertical-align:baseline;background:rgb(238,238,238);color:rgb(77,77,76);line-height:1.5;"><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;">一个宏块 = 一个<span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">16</span>*<span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">16</span>的亮度像素 + 一个<span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">8</span>×<span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">8</span>Cb + 一个<span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">8</span>×<span class="number" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;color:rgb(245,135,31);">8</span>Cr彩色像素块组成。(YCbCr 是属于 YUV 家族的一员,在YCbCr 中 Y 是指亮度分量,Cb 指蓝色色度分量,而 Cr 指红色色度分量)</span><br></pre></td></tr></tbody></table><table style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;border-spacing:0px;"><thead style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><th style="border-width:0px 0px 2px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">宏块分类</th><th style="border-width:0px 0px 2px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">意义</th></tr></thead><tbody style="font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">I 宏块</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">利用从<span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">当前片</span>中已解码的像素作为参考进行帧内预测</td></tr><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">P 宏块</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">利用前面已编码图像作为参考进行帧内预测,一个帧内编码的宏块可进一步作宏块的分割:即16×16.16×8.8×16.8×8亮度像素块。如果选了8×8的子宏块,则可再分成各种子宏块的分割,其尺寸为8×8,8×4,4×8,4×4</td></tr><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">B 宏块</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">利用双向的参考图像(当前和未来的已编码图像帧)进行帧内预测</td></tr></tbody></table><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;"><a href="http://www.iosxxx.com/images/h264base/01.png" rel="nofollow" title="" class="fancybox" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"><img src="http://www.iosxxx.com/images/h264base/01.png" alt="" style="border:none;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:middle;"></a></p><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;"><span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">图2.1句发元素的分层结构</span>,在 H.264 中,句法元素共被组织成 序列、图像、片、宏块、子宏块五个层次。<br>句法元素的分层结构有助于更有效地节省码流。例如,再一个图像中,经常会在各个片之间有相同的数据,如果每个片都同时携带这些数据,势必会造成码流的浪费。更为有效的做法是将该图像的公共信息抽取出来,形成图像一级的句法元素,而在片级只携带该片自身独有的句法元素。</p><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;"><a href="http://www.iosxxx.com/images/h264base/07.png" rel="nofollow" title="" class="fancybox" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"><img src="http://www.iosxxx.com/images/h264base/07.png" alt="" style="border:none;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:middle;"></a><br><span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">图2.2宏块的句法单元</span></p><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;"><a href="http://www.iosxxx.com/images/h264base/11.png" rel="nofollow" title="" class="fancybox" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"><img src="http://www.iosxxx.com/images/h264base/11.png" alt="" style="border:none;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:middle;"></a></p><table style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;border-spacing:0px;"><thead style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><th style="border-width:0px 0px 2px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">宏块分类</th><th style="border-width:0px 0px 2px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">意义</th></tr></thead><tbody style="font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">mb_type</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">确定该 MB 是帧内或帧间(P 或 B)编码模式,确定该 MB 分割的尺寸</td></tr><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">mb_pred</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">确定帧内预测模式(帧内宏块)确定表 0 或表 1 参考图 像,和每一宏块分割的差分编码的运动矢量(帧间宏块,除 8×8 宏块分割的帧内 MB)</td></tr><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">sub_mb_pred</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">(只对 8×8MB 分割的帧内 MB)确定每一子宏块的子宏 块分割,每一宏块分割的表 0 和/或表 1 的参考图象;每一 宏块子分割的差分编码运动矢量。</td></tr><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">coded_block_pattern</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">指出哪个 8×8 块(亮度和彩色)包 编码变换系数</td></tr><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">mb_qp_delta</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">量化参数的改变值</td></tr><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">residual</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">预测后对应于残差图象取样的编码变换系数</td></tr></tbody></table><h4 style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:22.4px;vertical-align:baseline;color:rgb(51,51,51);"><a href="http://www.iosxxx.com/blog/2017-08-09-%E4%BB%8E%E9%9B%B6%E4%BA%86%E8%A7%A3H264%E7%BB%93%E6%9E%84.html#3-%E5%9B%BE%E5%83%8F-%E5%9C%BA%E5%92%8C%E5%B8%A7" rel="nofollow" class="headerlink" title="3.图像,场和帧" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:22.4px;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"></a>3.图像,场和帧</h4><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;">图像是个集合概念,顶 场、底场、帧都可以称为图像。对于H.264 协议来说,我们平常所熟悉的那些称呼,例如: I 帧、P 帧、B帧等等,实际上都是我们把图像这个概念具体化和细小化了。我们 在 H.264里提到的“帧”通常就是指不分场的图像;</p><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;">视频的一场或一帧可用来产生一个<span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">编码图像</span>。一帧通常是一个完整的图像。当采集视频信号时,如果采用隔行扫描(奇.偶数行),则扫描下来的一帧图像就被分为了两个部分,这每一部分就被称为&nbsp;<span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">[场]</span>,根据次序氛围:&nbsp;<span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">[顶场]</span>&nbsp;和&nbsp;<span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">[底场]</span>。</p><table style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;border-spacing:0px;"><thead style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><th style="border-width:0px 0px 2px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">方式</th><th style="border-width:0px 0px 2px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">作用域</th></tr></thead><tbody style="font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">帧编码方式</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">活动量较小或者静止的图像宜采用</td></tr><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">场编码方式</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">活动量较大的运动图像</td></tr></tbody></table><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;"><a href="http://www.iosxxx.com/images/h264base/02.png" rel="nofollow" title="" class="fancybox" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"><img src="http://www.iosxxx.com/images/h264base/02.png" alt="" style="border:none;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:middle;"></a><br><span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">图2.3</span></p><h4 style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:22.4px;vertical-align:baseline;color:rgb(51,51,51);"><a href="http://www.iosxxx.com/blog/2017-08-09-%E4%BB%8E%E9%9B%B6%E4%BA%86%E8%A7%A3H264%E7%BB%93%E6%9E%84.html#4-I-P-B%E5%B8%A7%E4%B8%8Epts-dts" rel="nofollow" class="headerlink" title="4. I,P,B帧与pts/dts" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:22.4px;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"></a>4. I,P,B帧与pts/dts</h4><table style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;border-spacing:0px;"><thead style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><th style="border-width:0px 0px 2px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">帧的分类</th><th style="border-width:0px 0px 2px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">中文</th><th style="border-width:0px 0px 2px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">意义</th></tr></thead><tbody style="font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">I帧</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">帧内编码帧,又称intra picture</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">I 帧通常是每个 GOP(MPEG 所使用的一种视频压缩技术)的第一个帧,经过适度地压缩,做为随机访问的参考点,可以当成图象。I帧可以看成是一个图像经过压缩后的产物</td></tr><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">P帧</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">前向预测编码帧,又称predictive-frame</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">通过充分将低于图像序列中前面已编码帧的时间冗余信息来压缩传输数据量的编码图像,也叫预测帧</td></tr><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">B帧</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">双向预测帧,又称bi-directional interpolated prediction frame</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">既考虑与源图像序列前面已编码帧,也顾及源图像序列后面已编码帧之间的时间冗余信息来压缩传输数据量的编码图像,也叫双向预测帧</td></tr></tbody></table><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;"><span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">I P B帧的不同:</span><br>I frame:自身可以通过视频解压算法解压成一张单独的完整的图片。<br>P frame:需要参考其前面的一个I frame 或者B frame来生成一张完整的图片。<br>B frame:则要参考其前一个I或者P帧及其后面的一个P帧来生成一张完整的图片。</p><table style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;border-spacing:0px;"><thead style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><th style="border-width:0px 0px 2px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">名称</th><th style="border-width:0px 0px 2px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">意义</th></tr></thead><tbody style="font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">PTS(Presentation Time Stamp)</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">PTS主要用于度量解码后的视频帧什么时候被显示出来。</td></tr><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;"><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;line-height:1.3em;">DTS(Decode Time Stamp)</td><td style="border-top:0px;border-right:0px;border-left:0px;border-bottom-color:rgb(219,219,219);font-style:inherit;font-family:inherit;font-size:16px;vertical-align:middle;text-align:center;line-height:1.3em;">DTS主要是标识内存中的bit流再什么时候开始送入解码器中进行解码。</td></tr></tbody></table><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;"><a href="http://www.iosxxx.com/images/h264base/03.png" rel="nofollow" title="" class="fancybox" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"><img src="http://www.iosxxx.com/images/h264base/03.png" alt="" style="border:none;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:middle;"></a></p><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;">DTS与PTS的不同:<br>DTS主要用户视频的解码,在解码阶段使用。PTS主要用于视频的同步和输出,在display的时候使用。再没有B frame的时候输出顺序一样。</p><h4 style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:22.4px;vertical-align:baseline;color:rgb(51,51,51);"><a href="http://www.iosxxx.com/blog/2017-08-09-%E4%BB%8E%E9%9B%B6%E4%BA%86%E8%A7%A3H264%E7%BB%93%E6%9E%84.html#5-GOP" rel="nofollow" class="headerlink" title="5. GOP" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:22.4px;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"></a>5. GOP</h4><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;">GOP是画面组,一个GOP是一组连续的画面。<br>GOP一般有两个数字,如M=3,N=12.M制定I帧与P帧之间的距离,N指定两个I帧之间的距离。那么现在的GOP结构是</p><table style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;border-spacing:0px;"><tbody style="font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:baseline;"><tr style="border-top:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:baseline;"><td class="gutter" style="border-style:none;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;line-height:1.3em;"><pre style="border:none;font-weight:inherit;font-style:inherit;font-family:Monaco, Menlo, Consolas, 'Courier New', monospace;font-size:.9em;vertical-align:baseline;background:rgb(238,238,238);color:rgb(153,153,153);line-height:1.5;text-align:right;"><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;">1</span><br></pre></td><td class="code" style="border-style:none;font-style:inherit;font-family:inherit;font-size:14.4px;vertical-align:middle;line-height:1.3em;"><pre style="border:none;font-weight:inherit;font-style:inherit;font-family:Monaco, Menlo, Consolas, 'Courier New', monospace;font-size:.9em;vertical-align:baseline;background:rgb(238,238,238);color:rgb(77,77,76);line-height:1.5;"><span class="line" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:12.96px;vertical-align:baseline;">I BBP BBP BBP BB I</span><br></pre></td></tr></tbody></table><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;">增大图片组能有效的减少编码后的视频体积,但是也会降低视频质量,至于怎么取舍,得看需求了</p><h4 style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:22.4px;vertical-align:baseline;color:rgb(51,51,51);"><a href="http://www.iosxxx.com/blog/2017-08-09-%E4%BB%8E%E9%9B%B6%E4%BA%86%E8%A7%A3H264%E7%BB%93%E6%9E%84.html#6-IDR" rel="nofollow" class="headerlink" title="6. IDR" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:22.4px;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"></a>6. IDR</h4><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;"><span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">一个序列的第一个图像叫做 IDR 图像(立即刷新图像),IDR 图像都是 I 帧图像。</span><br>I和IDR帧都使用帧内预测。I帧不用参考任何帧,但是之后的P帧和B帧是有可能参考这个I帧之前的帧的。IDR就不允许这样。<br>比如这种情况:<br>IDR1 P4 B2 B3 P7 B5 B6 I10 B8 B9 P13 B11 B12 P16 B14 B15 这里的B8可以跨过I10去参考P7</p><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;"><span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">核心作用:</span><br>H.264 引入 IDR 图像是为了解码的重同步,当解码器解码到 IDR 图像时,立即将参考帧队列清空,将已解码的数据全部输出或抛弃,重新查找参数集,开始一个新的序列。这样,如果前一个序列出现重大错误,在这里可以获得重新同步的机会。IDR图像之后的图像永远不会使用IDR之前的图像的数据来解码。</p><h2 style="border-width:0px 0px 2px;border-bottom-style:solid;border-bottom-color:rgb(219,219,219);font-weight:inherit;font-style:inherit;font-family:inherit;font-size:28.8px;vertical-align:baseline;line-height:1.2em;color:rgb(51,51,51);"><a name="t4"></a><a href="http://www.iosxxx.com/blog/2017-08-09-%E4%BB%8E%E9%9B%B6%E4%BA%86%E8%A7%A3H264%E7%BB%93%E6%9E%84.html#%E4%B8%89-%E5%B8%A7%E5%86%85%E9%A2%84%E6%B5%8B%E5%92%8C%E5%B8%A7%E9%97%B4%E9%A2%84%E6%B5%8B" rel="nofollow" class="headerlink" title="三. 帧内预测和帧间预测" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:28.8px;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"></a>三. 帧内预测和帧间预测</h2><h4 style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:22.4px;vertical-align:baseline;color:rgb(51,51,51);"><a href="http://www.iosxxx.com/blog/2017-08-09-%E4%BB%8E%E9%9B%B6%E4%BA%86%E8%A7%A3H264%E7%BB%93%E6%9E%84.html#1-%E5%B8%A7%E5%86%85%E9%A2%84%E6%B5%8B%EF%BC%88%E4%B9%9F%E5%8F%AB%E5%B8%A7%E5%86%85%E5%8E%8B%E7%BC%A9%EF%BC%89" rel="nofollow" class="headerlink" title="1. 帧内预测(也叫帧内压缩)" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:22.4px;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"></a>1. 帧内预测(也叫帧内压缩)</h4><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;"><a href="http://www.iosxxx.com/images/h264base/13.png" rel="nofollow" title="" class="fancybox" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"><img src="http://www.iosxxx.com/images/h264base/13.png" alt="" style="border:none;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:middle;"></a></p><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;">我们可以通过第 1、2、3、4、5 块的编码来推测和计算第 6 块的编码,因此就不需要对第 6 块进行编码了,从而压缩了第 6 块,节省了空间</p><h4 style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:22.4px;vertical-align:baseline;color:rgb(51,51,51);"><a href="http://www.iosxxx.com/blog/2017-08-09-%E4%BB%8E%E9%9B%B6%E4%BA%86%E8%A7%A3H264%E7%BB%93%E6%9E%84.html#2-%E5%B8%A7%E9%97%B4%E9%A2%84%E6%B5%8B%EF%BC%88%E4%B9%9F%E5%8F%AB%E5%B8%A7%E9%97%B4%E5%8E%8B%E7%BC%A9%EF%BC%89" rel="nofollow" class="headerlink" title="2. 帧间预测(也叫帧间压缩)" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:22.4px;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"></a>2. 帧间预测(也叫帧间压缩)</h4><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;"><a href="http://www.iosxxx.com/images/h264base/14.png" rel="nofollow" title="" class="fancybox" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"><img src="http://www.iosxxx.com/images/h264base/14.png" alt="" style="border:none;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:middle;"></a>&nbsp;<a href="http://www.iosxxx.com/images/h264base/15.png" rel="nofollow" title="" class="fancybox" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"><img src="http://www.iosxxx.com/images/h264base/15.png" alt="" style="border:none;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:middle;"></a></p><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;">可以看到前后两帧的差异其实是很小的,这时候用帧间压缩就很有意义。<br>这里涉及到几个重要的概念:<span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">块匹配,残差,运动搜索(运动估计),运动补偿</span>.</p><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;">帧间压缩最常用的方式就是<span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">块匹配(Block Matching)</span>。找找看前面已经编码的几帧里面,和我当前这个块最类似的一个块,这样我不用编码当前块的内容了,只需要编码当前块和我找到的快的差异<span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">(残差)</span>即可。找最想的块的过程叫<span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">运动搜索(Motion Search)</span>,又叫<span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">运动估计</span>。用残差和原来的块就能推算出当前块的过程叫<span style="border:0px;font-style:inherit;font-family:inherit;vertical-align:baseline;">运动补偿(Motion Compensation)</span>.</p><h2 style="border-width:0px 0px 2px;border-bottom-style:solid;border-bottom-color:rgb(219,219,219);font-weight:inherit;font-style:inherit;font-family:inherit;font-size:28.8px;vertical-align:baseline;line-height:1.2em;color:rgb(51,51,51);"><a name="t5"></a><a href="http://www.iosxxx.com/blog/2017-08-09-%E4%BB%8E%E9%9B%B6%E4%BA%86%E8%A7%A3H264%E7%BB%93%E6%9E%84.html#%E5%9B%9B-%E5%BB%B6%E4%BC%B8" rel="nofollow" class="headerlink" title="四. 延伸" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:28.8px;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"></a>四. 延伸</h2><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;">最近我才知道FFmpeg也支持h264的硬编。具体还没有试验,接下来我会写demo来测试一下。直接用系统进行硬编的方式已经尝试过。接口还是蛮简单的。据说iOS11正式版会出H.265/HEVC硬编。目前Beta版暂不支持。如有支持,我会第一时间更新到博客,敬请期待!</p><h1 style="border-width:0px 0px 2px;border-bottom-style:solid;border-bottom-color:rgb(219,219,219);font-weight:inherit;font-style:inherit;font-family:inherit;font-size:28.8px;vertical-align:baseline;line-height:1.2em;color:rgb(51,51,51);"><a name="t6"></a><a href="http://www.iosxxx.com/blog/2017-08-09-%E4%BB%8E%E9%9B%B6%E4%BA%86%E8%A7%A3H264%E7%BB%93%E6%9E%84.html#%E5%8F%82%E8%80%83%E9%93%BE%E6%8E%A5" rel="nofollow" class="headerlink" title="参考链接:" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;font-size:28.8px;vertical-align:baseline;color:rgb(44,166,203);" target="_blank"></a>参考链接:</h1><p style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;line-height:1.5;">1.<a href="http://read.pudn.com/downloads147/ebook/635957/%E6%96%B0%E4%B8%80%E4%BB%A3%E8%A7%86%E9%A2%91%E5%8E%8B%E7%BC%A9%E7%BC%96%E7%A0%81%E6%A0%87%E5%87%86H.264.pdf" rel="nofollow" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(44,166,203);" target="_blank">新一代视频压缩编码标准H.264</a><br>2.<a href="http://simplecodesky.com/2016/11/15/%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BA%E7%90%86%E8%A7%A3%E8%A7%86%E9%A2%91%E7%BC%96%E7%A0%81H264%E7%BB%93%E6%9E%84/" rel="nofollow" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(44,166,203);" target="_blank">深入浅出理解视频编码H264结构</a><br>3.<a href="http://www.samirchen.com/video-concept/" rel="nofollow" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(44,166,203);" target="_blank">关于视频的一些概念</a><br>4.<a href="http://www.cnblogs.com/qingquan/archive/2011/07/27/2118967.html" rel="nofollow" style="border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(44,166,203);" target="_blank">I,P,B帧和PTS,DTS的关系</a></p></div>            </div>
                </div>

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值