一、将.264文件转换为YUV文件
#define DECOUTPUT_TEST 0
#define PRINT_OUTPUT_POC 0
#define BITSTREAM_FILENAME "miao.264"
#define DECRECON_FILENAME "miao.yuv"
#define ENCRECON_FILENAME "test_rec.yuv"
#define FCFR_DEBUG_FILENAME "fcfr_dec_rpu_stats.txt"
#define DECOUTPUT_VIEW0_FILENAME "H264_Decoder_Output_View0.yuv"
#define DECOUTPUT_VIEW1_FILENAME "H264_Decoder_Output_View1.yuv"
二、将视频序列编码为.264文件
1.固定码率,以不同的GOP长度及形状编码
因为一个GOP组只拥有一个I帧,所以I帧之间的间隔就可以看作GOP组的长度。所以可以通过设置IntraPeriod 的值确定GOP组的长度。
修改下列参数:
InputFile = "miao.yuv" # Input sequence
FramesToBeEncoded = 30 # Number of frames to be coded
SourceWidth = 960 # Source frame width
SourceHeight = 464 # Source frame height
OutputWidth = 960 # Output frame width
OutputHeight = 464 # Output frame height
ReconFile = "miao_rec_400.yuv" # Reconstruction YUV file
OutputFile = "miao_400.264" # Bitstream
IntraPeriod = 10 # Period of I-pictures (0=only first)
IDRPeriod = 0 # Period of IDR pictures (0=only first)
NumberBFrames = 0 # Number of B coded frames inserted (0=not used)
RateControlEnable = 0 # 0 Disable, 1 Enable
获得上述不同GOP长度及编码形状编码后的.264文件
GOP=15,2B帧:
GOP=12,2B帧:
2.相同GOP长度,不同码率
InputFile = "miao.yuv" # Input sequence
FramesToBeEncoded = 30 # Number of frames to be coded
SourceWidth = 960 # Source frame width
SourceHeight = 464 # Source frame height
OutputWidth = 960 # Output frame width
OutputHeight = 464 # Output frame height
ReconFile = "miao_rec_400.yuv" # Reconstruction YUV file
OutputFile = "miao_400.264" # Bitstream
IntraPeriod = 10 # Period of I-pictures (0=only first)
IDRPeriod = 0 # Period of IDR pictures (0=only first)
NumberBFrames = 0 # Number of B coded frames inserted (0=not used)
RateControlEnable = 1 # 0 Disable, 1 Enable
Bitrate = 400000 # Bitrate(bps)
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
1000kb/s,GOP=10,无B帧
800kb/s,GOP=10,无B帧
400kb/s,GOP=10,无B帧
三、用码流分析软件检查所生成的码流中各种编码模式和运动矢量等信息
该帧为视频码流最后一帧,帧内类型为P帧。
紫色代表I宏块,绿色代表P宏块。由于不同宏块所在的图像细节不同,采用的宏块大小也不同,可以看出在平坦区域
该图表示运动矢量,因为该帧为P帧,所以只有前向预测。
四、用播放器观看生成码流的质量
1000kb/s:
800kb/s:
400kb/s:
由于比特率相差不大,视频清晰程度差不多,但仔细对比1000kb/s与400kb/s的视频图像,可以看出1000kb/s的视频图像较为清晰。
生成率失真曲线
横坐标为不同的比特率,纵坐标为Y分量的PSNR
通过上图可以看出,GOP15-无B质量最高,GOP15-2B与GOP15-1B相差不大,GOP15-2B质量高于GOP9-2B。因此,一个GOP组内B帧越少质量越好,GOP长度越长质量越好。