CU-tree
x265中CU-tree的主要思想同x264的MB-tree一样,无较大改动。其目的是通过预估当前块在帧间预测中被未来帧所参考的信息多少,来调整当前块的QP值。如果当前块贡献给后续帧的信息越多,则其重要性越高,应当提高该区域的编码质量,减少QP,反之,则增大该区域的QP。(有点感知压缩的意思)
计算流程如下:(加入后缀cur及ref以区分当前块及其参考块)
- 获取当前块的intra_cost_curintra\_cost\_curintra_cost_cur ,inter_cost_curinter\_cost\_curinter_cost_cur,以及propagate_cost_curpropagate\_cost\_curpropagate_cost_cur(叠加 参考了当前块的未来帧 而得到)来计算当前块给其参考块带来的遗传代价即propagate_cost_refpropagate\_cost\_refpropagate_cost_ref
- 计算继承率propagate_fraction_cur=1−inter_cost_curintra_cost_curpropagate\_fraction\_cur=1- \frac{inter\_cost\_cur}{intra\_cost\_cur}propagate_fraction_cur=1−intra_cost_curinter_cost_cur。假设当前块inter_cost_curinter\_cost\_curinter_cost_cur只有intra_cost_curintra\_cost\_curintra_cost_cur的80%,说明帧间预测节省了20% 的编码消耗,则当前块的信息有20%来自于其参考帧,propagate_fraction_cur=0.2propagate\_fraction\_cur=0.2propagate_fraction_cur=0.2。
- 当前块传递其给参考块的总传递代价量propagate_amount_ref=(intra_cost_cur∗invQScales+propagate_cost_cur)∗propagate_fraction_curpropagate\_amount\_ref=(intra\_cost\_cur*invQScales+propagate\_cost\_cur)*propagate\_fraction\_curpropagate_amount_ref=(intra_cost_cur∗invQScales+propagate_cost_cur)∗propagate_fraction_cur
- 当前单元在邻近帧中的匹配块可能覆盖4个块,按照当前块实际参考像素面积估算代价传递权重 weight1,weight2,weight3,weight4weight1,weight2,weight3,weight4weight1,weight2,weight3,weight4。将上面计算的propagate_amount_refpropagate\_amount\_refpropagate_amount_ref按照权重比例分配给这四个参考块。如:propagate_cost_ref1=propagate_amount_ref∗weight1propagate\_cost\_ref1=propagate\_amount\_ref*weight1propagate_cost_ref1=propagate_amount_ref∗weight1 。
若当前帧为b帧,在第一步我们获得了当前块的propagate_cost_curpropagate\_cost\_curpropagate_cost_cur,便可根据此公式cuTreeQPOffset=−cuTreeStrength∗log2(1+propagate_cost_curintra_cost_cur)cuTreeQPOffset=-cuTreeStrength*log2( 1+\frac{propagate\_cost\_cur}{intra\_cost\_cur})cuTreeQPOffset=−cuTreeStrength∗log2(1+intra_cost_curpropagate_cost_cur)计算CU-tree算法为当前块计算的QPOffsetQPOffsetQPOffset。其中cuTreeStrengthcuTreeStrengthcuTreeStrength为cuTree的强度,最大为2.
需要注意的点:
- 在cuTree算法执行之前,会对当前图像进行1/2下采样,即将256x256的图像下采样至128x128再进行intra_cost,inter_costintra\_cost,inter\_costintra_cost,inter_cost等的计算。
- x265中仍以16x16的块为单位( 也就是下采样后8x8的块)计算cuTreeQPOffsetcuTreeQPOffsetcuTreeQPOffset,32x32的块cuTreeQPOffsetcuTreeQPOffsetcuTreeQPOffset是其4个16x16块offset的平均。