原理
H.264的协议中没有给出标准解码器,只给出了框架或码流的语法。H.264是一种基于块的混合编码技术,在以前的编码标准之上对预测、变换、量化、编码、进行了细节上的一些更新。H.264一些特点如下:
- 编码效率更高,表现形式更简洁
- 采用了分层技术,添加了NAL网络适配层,可以适应不同的网络应用环境
- 在空间域内进行帧内预测,提高精确度
- 运动估计和运动补偿更精细(多参考帧,多种宏块大小等方法)
- 整数变换,核心部分仅使用加法和移位操作实现
- 采用了去块效应滤波
- 熵编码技术有uvlc,cavlc,cabac
上述的特性虽然提高了容错率,但是缺点是计算复杂度较高
编解码器的框图如下,图来自老师的ppt
实验
解码
解码.264文件,生成对应yuv文件
对decoder.cfg里的参数进行修改,下图是举例的参数
对highway_qcif.264进行解码,需要修改的地方如下
# Files
##########################################################################################
InputFile = "highway_qcif.264" # H.264/AVC coded bitstream
OutputFile = "highway_qcif.yuv" # Output file, YUV/RGB
RefFile = "highway_qcif.yuv" # Ref sequence (for SNR)
结果如下
解码完毕
编码
本次编码实验需要进行不同参数情况下的对比,具体参数修改在encoder.cfg中
需要修改的参数如下,以highway_qcif为例
##########################################################################################
# Files
##########################################################################################
InputFile = "highway_qcif.yuv" # Input sequence
...
OutputFile = "highway_qcif_15_2_400.264" # Bitstream
下方是gop组相关参数的修改
IntraPeriod = 15 # Period of I-pictures (0=only first)
...
NumberBFrames = 2 # Number of B coded frames inserted (0=not used)```
...
PrimaryGOPLength = 15 # GOP length for redundant allocation (1-16)
# NumberReferenceFrames must be no less than PrimaryGOPLength when redundant slice enabled
下面是码流参数的修改
RateControlEnable = 1 # 0 Disable, 1 Enable
Bitrate = 400000 # Bitrate(bps)
此外,在编码过程中出现错误,发现还需要对下方参数进行修改
HierarchicalCoding = 2 # B hierarchical coding (0= off, 1= 2 layers, 2= 2 full hierarchy, 3 = explicit)
...
RCUpdateMode = 2 # Rate Control type. Modes supported :
# 0 = original JM rate control,
# 1 = rate control that is applied to all frames regardless of the slice type,
# 2 = original plus intelligent QP selection for I and B slices (including Hierarchical),
# 3 = original + hybrid quadratic rate control for I and B slice using bit rate statistics
另外,在进行全I帧编码时,需要将RCUpdateMode修改为1
其它参数情况下依照此修改即可
由于该视频较长,只对前60帧进行编码
下方表格用来对比不同参数下的图像质量以及psnr
gop\bitrate | 1000kbps | psnr | 800kbps | psnr | 400kbps | psnr |
---|---|---|---|---|---|---|
gop=15,2B帧 | ![]() | 55.54 | ![]() | 55.46 | ![]() | 52.66 |
gop=12,2B帧 | ![]() | 55.58 | ![]() | 55.57 | ![]() | 52.26 |
gop=9,2B帧 | ![]() | 55.43 | ![]() | 55.36 | ![]() | 52.06 |
gop=4,1B帧 | ![]() | 55.98 | ![]() | 55.98 | ![]() | 52.05 |
gop=12,0B帧 | ![]() | 55.93 | ![]() | 55.87 | ![]() | 53.76 |
gop=1,全I帧 | ![]() | 52.59 | ![]() | 51.43 | ![]() | 47.15 |
运动矢量
以gop=4,1B帧为例
帧数 | 矢量 |
---|---|
第1帧(I) | ![]() |
第2帧(B) | ![]() |
第3帧(P) | ![]() |
不难看出,I帧并没有进行帧间预测,故没有运动矢量,而B帧中有两种颜色的运动矢量,分别为前向预测和后向预测,P帧中只有红色的矢量,即后向预测的矢量。
另对miss.qcif进行了编码,运动矢量如下,I帧由于没有矢量没有进行对比
帧数 | 运动矢量 | 宏块分割 |
---|---|---|
第2帧(B) | ![]() | ![]() |
第3帧(P) | ![]() | ![]() |
可以看出,miss图像中运动矢量更为明显,便于观察,由于miss的甩头动作,面部的运动矢量是水平的,而在手,电话以及头发处的运动矢量明显的预示着动作的走向
其他信息
宏块信息可在MB Info处查看,可查看当前帧类型,宏块类型,量化参数,比特数等
此外像素信息也可查看
此外,summary中可以查到编码方式等信息,highway视频中所有的编码方式均为CABAC