转:Close gop与Open Gop

GOP和Reference

  在视频编码序列中,主要有三种编码帧:I帧、P帧、B帧,如下图3.1所示。

  ● I帧即Intra-coded picture(帧内编码图像帧),不参考其他图像帧,只利用本帧的信息进行编码
● P帧即Predictive-coded Picture(预测编码图像帧),利用之前的I帧或P帧,采用运动预测的方式进行帧间预测编码
● B帧即Bidirectionally predicted picture(双向预测编码图像帧),提供最高的压缩比,它既需要之前的图
像帧(I帧或P帧),也需要后来的图像帧(P帧),采用运动预测的方式进行帧间双向预测编码

  在视频编码序列中,GOP即Group of picture(图像组),指两个I帧之间的距离,Reference(参考周期)指两个P帧之间的距离(如下图3.1)。一个I帧所占用的字节数大于一个P帧,一个P帧所占用的字节数大于一个B帧(如下图3.1所示)。

  图3.1 I、P、B帧示意图

  所以在码率不变的前提下,GOP值越大,P、B帧的数量会越多,平均每个I、P、B帧所占用的字节数就越多,也就更容易获取较好的图像质量;Reference越大,B帧的数量越多,同理也更容易获得较好的图像质量。

  需要说明的是,通过提高GOP值来提高图像质量是有限度的,在遇到场景切换的情况时,H.264编码器会自动强制插入一个I帧,此时实际的GOP值被缩短了。另一方面,在一个GOP中,P、B帧是由I帧预测得到的,当I帧的图像质量比较差时,会影响到一个GOP中后续P、B帧的图像质量,直到下一个GOP开始才有可能得以恢复,所以GOP值也不宜设置过大。

同时,由于P、B帧的复杂度大于I帧,所以过多的P、B帧会影响编码效率,使编码效率降低。另外,过长的GOP还会影响Seek操作的响应速度,由于P、B帧是由前面的I或P帧预测得到的,所以Seek操作需要直接定位,解码某一个P或B帧时,需要先解码得到本GOP内的I帧及之前的N个预测帧才可以,GOP值越长,需要解码的预测帧就越多,seek响应的时间也越长。

 

x264最近的更新加入了两个关于keyframe的参数,–open-gop和–keyint infinite。
所谓open-gop,就是指允许类似IBBPBBIBB的frame结构,它的作用在于提高低keyint设置时的压缩率。
–keyint infinite的作用和open-gop正好相反,它为了最大化的利用压缩率存在的。开启infinite的open-gop后,除非scene-cut自动判定需要加入keyframe,一般情况下都不会加入keyframe。

众所周知,过于频繁的keyframe存在会降低压缩率,而一定频率的keyframe又能保证GOP间的B和P帧拥有良好的预测精度。同时keyframe的存在又保证了编码视频的可seek能力这在某些应用场合又是非常关键的。所以keyframe的选择是一个因人而异,因应用场合不同而变化的参数。

由于open-gop开启/keyint infinite与open-gop关闭/keyint infinite结果一模一样,所以不在列出了。这也可以理解,因为两者对keyframe的控制作用是完全相反的。

从上面的结果不难看出,开启open-gop保持现有keyint的设定,或者完全无视open-gop直 接上极端的无穷keyint interval,都能对最终编码视频的质量有所提升(opengop的提升很有限)。至于两者选何者好就要根据实际编码视频的质量,以及可播放性来确定 了,如果是极端ep的终极质量追求者,看片子几乎不seek,那就选择keyint infinite吧。


MPEG的格式支持open GOP或者close GOP格式。Close GOP是指帧间的预测都是在GOP中进行的。而使用open GOP,后一个GOP会参考前一个GOP的信息。使用这种方式就大大降低了码率。

from: http://www.videohelp.com

GOP: Group Of Pictures

A Group Of Pictures (GOP) consists of all the pictures that follow a GOP header before another GOP header.


The GOP layer allows random access because the first picture after the GOP header is an Intra picture that means that it doesn't need any reference to any other picture.


The GOP layer is optional, i.e. it's not mandatory to put any GOP header in the bitstream. In the header there is also the timecode of the first picture of the GOP to be displayed.

The decoding process, as the GOP header is immediately followed by an Intra picture, can begin at that point of the bitstream. Anyway it's possible that some B pictures, following such I_picture in the bitstream, have references coming from the previous GOP and can't be correctly decoded. In this case the GOP is called an Open GOP because some references from the previous GOP exist; if a random access to such a GOP is performed, some B_pictures shouldn't be displayed .
A GOP is called a Closed GOP when either there are no B_pictures immediately following the first I_picture or such B_pictures haven't any references coming from the previous GOP (in this case a GOP header flag must be set).

the GOP length is the period (often expressed in frames) by which an Intra frame occursIt must be noticed that such a value cannot be found in the bitstream and it is unnecessary to the decoding process. Furthermore it isn't specified any fixed period for the Intra frame. As the presence of the Intra frames is quite important for many applications, it is the encoder that has to provide them, while the decoder has only to work with all the valid bitstreams.

例子:

  • 非封闭GOP: I1 P2 B3 B4 P5 B6 B7 

       I8  B9  B10 P11 B11 B12 P13 B14 B15

       I16 B16 B17 P18 B19 B20 P21 B22 B23

       第一个GOP length为9-2帧,从第二个GOP开始为9帧

  • 封闭GOP:

               I1  P2  B3  B4  P5  B6  B7   

               I8  P9  B10 B11 P12 B13 B14

               I15 P16 B17 B18 P19 B20 B21

       GOP length = 9-2;

posted @ 2011-09-19 16:00  Mr.Rico  阅读(3412)  评论(0编辑  收藏  举报