1. 将MP4格式文件转成264文件
MP4to264
2. 将264文件进行解码得到YUV文件
修改decoder.cfg文件中的输入文件和输出文件。
InputFile = "mov.264" # H.264/AVC coded bitstream
OutputFile = "mov.yuv" # Output file, YUV/RGB
3. 实验结果
MP4和yuv截取的帧并不是同一帧。命令行代码为ldecod.exe -d decoder.cfg
mov.mp4 | mov.yuv | trailer.mp4 | trailer.yuv |
---|---|---|---|
![]() |
![]() |
![]() |
以上文中生成的mov.yuv作为实验材料。命令行代码为lencod.exe -d encoder.cfg
修改配置文件修改encoder.cfg。
...
##########################################################################################
# Files
##########################################################################################
InputFile = "mov.yuv" # Input sequence
InputHeaderLength = 0 # If the inputfile has a header, state it's length in byte here
StartFrame = 0 # Start frame for encoding. (0-N)
FramesToBeEncoded = 30 # Number of frames to be coded
...
SourceWidth = 320 # Source frame width
SourceHeight = 176 # Source frame height
SourceResize = 0 # Resize source size for output
OutputWidth = 320 # Output frame width
OutputHeight = 176 # Output frame height
...
ReconFile = "mov_test1_rec.yuv" # Reconstruction YUV file
OutputFile = "mov_test1.264" # Bitstream
##########################################################################################
# Encoder Control
##########################################################################################
...
IntraPeriod = 15 # Period of I-pictures (0=only first)
...
##########################################################################################
# B Slices
##########################################################################################
NumberBFrames = 2 # Number of B coded frames inserted (0=not
disable, N <= NumberReferenceFrames)
...
HierarchicalCoding = 0 # B hierarchical coding (0= off, 1= 2 layers, 2= 2 full hierarchy, 3 = explicit)
...
修改配置文件修改encoder.cfg。
...
##########################################################################################
# Files
##########################################################################################
InputFile = "mov.yuv" # Input sequence
InputHeaderLength = 0 # If the inputfile has a header, state it's length in byte here
StartFrame = 0 # Start frame for encoding. (0-N)
FramesToBeEncoded = 30 # Number of frames to be coded
...
SourceWidth = 320 # Source frame width
SourceHeight = 176 # Source frame height
SourceResize = 0 # Resize source size for output
OutputWidth = 320 # Output frame width
OutputHeight = 176 # Output frame height
...
ReconFile = "mov_test2_rec.yuv" # Reconstruction YUV file
OutputFile = "mov_test2.264" # Bitstream
##########################################################################################
# Encoder Control
##########################################################################################
...
IntraPeriod = 1 # Period of I-pictures (0=only first)
...
##########################################################################################
# B Slices
##########################################################################################
NumberBFrames = 0 # Number of B coded frames inserted (0=not
disable, N <= NumberReferenceFrames)
...
HierarchicalCoding = 0 # B hierarchical coding (0= off, 1= 2 layers, 2= 2 full hierarchy, 3 = explicit)
...
除了上面修改过的地方,还得在配置文件中新修改两处encoder.cfg。
...
##########################################################################################
# Files
##########################################################################################
InputFile = "mov.yuv" # Input sequence
InputHeaderLength = 0 # If the inputfile has a header, state it's length in byte here
StartFrame = 0 # Start frame for encoding. (0-N)
FramesToBeEncoded = 30 # Number of frames to be coded
...
SourceWidth = 320 # Source frame width
SourceHeight = 176 # Source frame height
SourceResize = 0 # Resize source size for output
OutputWidth = 320 # Output frame width
OutputHeight = 176 # Output frame height
...
ReconFile = "mov_test3_rec.yuv" # Reconstruction YUV file
OutputFile = "mov_test3.264" # Bitstream
##########################################################################################
# Encoder Control
##########################################################################################
...
IntraPeriod = 15 # Period of I-pictures (0=only first)
...
##########################################################################################
# B Slices
##########################################################################################
NumberBFrames = 2 # Number of B coded frames inserted (0=not
disable, N <= NumberReferenceFrames)
...
########################################################################################
#Rate control
########################################################################################
RateControlEnable = 1 # 0 Disable, 1 Enable
Bitrate = 1000000 # Bitrate(bps)
...
以上文中的mov_test1.264为例。
选取的是第一帧,按照分析来看,第一帧一定是帧内编码帧(I帧),在分析软件中分析时也确实如此。其Slice Type为I Slice。
同时,从图中,我们也可以看到,宏块的类型MB Type为I_16X16_2_1_1和I_4X4。两个宏块都是I类型的宏块。
同时,由于是I帧的原因,运动矢量并不存在。从上图中发现也确实如此。
由分析软件可知,Slice Type为P Slice,即该帧为前向预测帧(P帧),所以运动矢量应该是只有前向预测所得的运动矢量,从图中可以看出也确实如此,只有前向预测的绿色运动矢量。
由分析软件可知,Slice_Type为B Slice,即该帧为双向预测帧(B帧),所以运动矢量应该有两种,一种是前向预测所得,一种是后向预测所得,从图中可以看出也确实如此,拥有红色和绿色两种不同的运动矢量。
以上文中的mov_test3.264为例。
由于是I帧的原因,运动矢量并不存在。从上图中发现也确实如此。
和上一小节中【GOP=15,2B】的码流不同,该码流的第4帧也是I帧编码,这和编码时所选取的参数是一致的,编码时让该码流为全I帧编码。
同时,由于是I帧的原因,运动矢量并不存在。
全I帧编码和【GOP=15,2B】比较,B帧属于极端的没有。
由分析可知,B帧越多的话,相对来说,运动矢量会越多。
同时,由所学知识和在播放器中码流的表现来看,在前后两帧画面相差大的情况下,运动矢量也会相应增多。
所用的yuv文件是上文中生成的mov.yuv。我们所使用的编码方式分别为如下几种:
该帧的实际码率为1028.23kbit/s,其Y-PSNR为40.763dB。
该帧的实际码率为927.68kbit/s,其Y-PSNR为39.546dB。
该帧的实际码率为676.02kbit/s,其Y-PSNR为38.171dB。
该帧的实际码率为1066.14kbit/s,其Y-PSNR为43.280dB。
该帧的实际码率为1004.25kbit/s,其Y-PSNR为43.126dB。
该帧的实际码率为997.76kbit/s,其Y-PSNR为35.867dB。
该帧的实际码率为920.62kbit/s,其Y-PSNR为40.553dB。
该帧的实际码率为397.98kbit/s,其Y-PSNR为37.775dB。
该帧的实际码率为846.92kbit/s,其Y-PSNR为39.368dB。
该帧的实际码率为424.61kbit/s,其Y-PSNR为37.356dB。
该帧的实际码率为676.02kbit/s,其Y-PSNR为38.171dB。
该帧的实际码率为427.82kbit/s,其Y-PSNR为36.941dB。
该帧的实际码率为840.67kbit/s,其Y-PSNR为42.529dB。
该帧的实际码率为400.62kbit/s,其Y-PSNR为39.093dB。
该帧的实际码率为803.48kbit/s,其Y-PSNR为41.975dB。
该帧的实际码率为398.04kbit/s,其Y-PSNR为37.986dB。
该帧的实际码率为803.46kbit/s,其Y-PSNR为34.871dB。
该帧的实际码率为400.90kbit/s,其Y-PSNR为32.408dB。
GOP=9,2B
1000kb/s | 800kb/s | 400kb/s |
---|---|---|
![]() |
![]() |
![]() |
可以发现,用播放器查看时的264视频质量无甚区别。
2B,1000kb/s
15 | 12 | 9 |
---|---|---|
![]() |
![]() |
![]() |
可以发现,用播放器查看时的264视频质量无甚区别。
GOP=12,1000kb/s
2B | 1B | 无B |
---|---|---|
![]() |
![]() |
![]() |
可以发现,用播放器查看时的264视频质量无甚区别。
将前文中得到的实际码率和Y-PSNR整理到一个表格中,得到如下图所示的表格。
根据上述表格中的数据作图,如下图所示:
H.264相比于之前讲过的MPEG-2来说,注重实用,采用更成熟的技术,要求更高的编码效率和简洁的表现形式。
与此同时,在混合编码器的基本框架下,H.264对MPEG-2中的主要关键模块都进行了重大改进。
但是,H.264标准的预测、变换、量化、熵编码等基本模块和MPEG-2并没有太大的区别,变化主要体现在功能模块的具体细节上。
H.264的主要特点: