实验内容
- 熟悉H.264参考编码器JM software编码参数(本文采用JM18.6);
- 输出foreman_qcif序列第0、1帧指定宏块如下信息:
- 编码模式(mode);
- 运动矢量(MV);
- 量化参数(QP);
H264参考编码器参数设置
JM编码器的参数通过cfg文件设置,运行编码器时调用配置文件的命令(以Windows平台的vs项目为例)为:
-d [配置文件路径]
示例:
配置文件encoder.cfg的关键参数为:
InputFile = "foreman_part_qcif.yuv" # Input sequence
# 输入序列,为420采样的YUV文件
StartFrame = 0 # Start frame for encoding. (0-N)
# 起始帧号
FramesToBeEncoded = 3 # Number of frames to be coded
# 编码的帧数
FrameRate = 30.0 # Frame Rate per second (0.1-100.0)
SourceWidth = 176 # Source frame width
SourceHeight = 144 # Source frame height
# 输入图像尺寸
SourceResize = 0 # Resize source size for output
OutputWidth = 176 # Output frame width
OutputHeight = 144 # Output frame height
# 输出图像尺寸
TraceFile = "trace_enc.txt" # Trace file
ReconFile = "test_rec.yuv" # Recontruction YUV file
OutputFile = "test.264" # Bitstream
StatsFile = "stats.dat" # Coding statistics file
IntraPeriod = 0 # Period of I-pictures (0=only first)
# Intra帧周期(I帧,不表示一个GOP结束)
IDRPeriod = 0 # Period of IDR pictures (0=only first)
# Intra IDR帧周期(I帧,表示一个GOP结束)
# 该选项确定了一个GOP的长度
EnableIDRGOP = 1 # Support for IDR closed GOPs (0: disabled, 1: enabled)
# 使用对IDR封闭的GOP
QPISlice = 28 # Quant. param for I Slices (0-51)
QPPSlice = 28 # Quant. param for P Slices (0-51)
# 在不启用码率控制时,该选项指定
# I帧与P帧的QP
NumberBFrames = 1 # Number of B coded frames inserted (0=not used)
# B帧数,与IntraPeriod、IDRPeriod共同确定GOP结构
QPBSlice = 30 # Quant. param for B slices (0-51)
# B帧的QP
RateControlEnable = 0 # 0 Disable, 1 Enable
# 禁用码率控制
编码模式与运动预测信息输出
Trace文件分析
JM编码器自带trace功能,启用trace即可生成trace文件输出编码过程中的关键参数。启用条件如下:
- 在cfg配置文件中TraceFile指定输出的文件名;
- 在defines.h文件中将TRACE的宏定义为1;
#if defined _DEBUG # define TRACE 1 #else # define TRACE 0 #endif
运行程序对3帧的实验序列foreman_part_qcif.yuv进行编码,查看Trace文件获得第2行第3个宏块的mode、MV、QP等信息:
对于第一帧I帧
通过计算可知该宏块编号为13,在Trace文件中找到如下内容:
*********** Pic: 0 (I/P) MB: 13 Slice: 0 **********
@4456 mb_type (I_SLICE) ( 2, 1) = 9 ( 0)
@4456 Intra 4x4 mode = 7 (context: 0) ( 7)
@4458 Intra 4x4 mode = 7 (context: 1) ( 7)
@4460 Intra 4x4 mode = predicted (context: 2) ( -1)
@4461 Intra 4x4 mode = predicted (context: 3) ( -1)
@4463 Intra 4x4 mode = 5 (context: 4) ( 5)
@4467 Intra 4x4 mode = 7 (context: 5) ( 7)
@4468 Intra 4x4 mode = 7 (context: 6) ( 7)
@4470 Intra 4x4 mode = predicted (context: 7) ( -1)
@4471 Intra 4x4 mode = 2 (context: 8) ( 2)
@4478 Intra 4x4 mode = 7 (context: 9) ( 7)
@4480 Intra 4x4 mode = predicted (context: 10) ( -1)
@4481 Intra 4x4 mode = predicted (context: 11) ( -1)
@4482 Intra 4x4 mode = predicted (context: 12) ( -1)
@4483 Intra 4x4 mode = predicted (context: 13) ( -1)
@4484 Intra 4x4 mode = predicted (context: 14) ( -1)
@4485 Intra 4x4 mode = 6 (context: 15) ( 6)
@4490 intra_chroma_pred_mode ( 0)
@4490 CBP ( 2, 1) = 23 ( 23)
@4497 Delta QP ( 2, 1) = 0 ( 0)
@4497 Luma4x4 sng( 0) level = -1 run = 0 ( -1)
@4497 Luma4x4 sng( 1) level = 1 run = 1