一、作业要求
1.输出第一帧第二个宏块行的第三个宏块mode
2.输出第二帧同样位置宏块的mode和mv
二、理论储备
1.宏块类型
// Available MB modes
typedef enum {
PSKIP = 0,
BSKIP_DIRECT = 0,
P16x16 = 1,
P16x8 = 2,
P8x16 = 3,
SMB8x8 = 4,
SMB8x4 = 5,
SMB4x8 = 6,
SMB4x4 = 7,
P8x8 = 8,
I4MB = 9,
I16MB = 10,
IBLOCK = 11,
SI4MB = 12,
I8MB = 13,
IPCM = 14,
MAXMODE = 15
} MBModeTypes;
2.帧内预测模式
4×4亮度块预测模式
// 4x4 intra prediction modes
typedef enum {
VERT_PRED = 0,
HOR_PRED = 1,
DC_PRED = 2,
DIAG_DOWN_LEFT_PRED = 3,
DIAG_DOWN_RIGHT_PRED = 4,
VERT_RIGHT_PRED = 5,
HOR_DOWN_PRED = 6,
VERT_LEFT_PRED = 7,
HOR_UP_PRED = 8
} I4x4PredModes;
16×16亮度块预测模式
// 16x16 intra prediction modes
typedef enum {
VERT_PRED_16 = 0,
HOR_PRED_16 = 1,
DC_PRED_16 = 2,
PLANE_16 = 3
} I16x16PredModes;
8×8亮度块预测模式
// 8x8 chroma intra prediction modes
typedef enum {
DC_PRED_8 = 0,
HOR_PRED_8 = 1,
VERT_PRED_8 = 2,
PLANE_8 = 3
} I8x8PredModes;
三、代码调试
1.命令行参数输入:
/d ./bin/decoder.cfg
2.设置打开trace文件:
设置define.h第25行启动trace:
#if defined _DEBUG
# define TRACE 1 //!< 0:Trace off 1:Trace on 2:detailed CABAC context information
#else
# define TRACE 0 //!< 0:Trace off 1:Trace on 2:detailed CABAC context information
#endif
3.注意修改RefFile路径
# Files
##########################################################################################
InputFile = "test.264" # H.264/AVC coded bitstream
OutputFile = "test_dec.yuv" # Output file, YUV/RGB
RefFile = "./bin/foreman_part_qcif.yuv" # Ref sequence (for SNR)
WriteUV = 1 # Write 4:2:0 chroma components for monochrome streams
FileFormat = 0 # NAL mode (0=Annex B, 1: RTP packets)
RefOffset = 0 # SNR computation offset
POCScale = 2 # Poc Scale (1 or 2)
##########################################################################################
4.添加代码
根据该段代码找出mode和mv
//! Macroblock
typedef struct macroblock_enc
{
struct slice *p_Slice; //!< pointer to the current slice
struct video_par *p_Vid; //!< pointer to VideoParameters
InputParameters *p_Inp;
int mbAddrX; //!< current MB address
short mb_type; //!< current MB mode type
short slice_nr; //!< current MB slice id
short mb_x; //!< current MB horizontal
short mb_y; //!< current MB vertical
short block_x; //!< current block horizontal
short block_y; //!< current block vertical
short pix_x; //!< current pixel horizontal
short pix_y; //!< current pixel vertical
short pix_c_x; //!< current pixel chroma horizontal
short pix_c_y; //!< current pixel chroma vertical
short opix_y; //!< current original picture pixel vertical
short opix_c_y; //!< current original picture pixel chroma vertical
short subblock_x; //!< current subblock horizontal
short subblock_y; //!< current subblock vertical
short list_offset;
Boolean prev_recode_mb;
int DeblockCall;
int mbAddrA, mbAddrB, mbAddrC, mbAddrD;
byte mbAvailA, mbAvailB, mbAvailC, mbAvailD;
short qp; //!< QP luma
short qpc[2]; //!< QP chroma
short qp_scaled[MAX_PLANE]; //!< QP scaled for all comps.
short qpsp;
int cbp;
short prev_qp;
short prev_dqp;
int prev_cbp;
int cr_cbp[3]; // 444. Should be added in an external structure
int c_nzCbCr[3];
short i16offset;
BitCounter bits;
short ar_mode; //!< mb type to store adaptive rounding parameters
// ***************************************************
short mvd[2][BLOCK_MULTIPLE][BLOCK_MULTIPLE][2]; //!< indices correspond to [list][block_y][block_x][x,y]
char c_ipred_mode; //!< chroma intra prediction mode
// ***************************************************
char i16mode;
Info8x8 b8x8[4];
//imgpel intra4x4_pred[16][17]; //!< 4x4 Intra prediction samples
imgpel **intra4x4_pred; //[3][17]; //!< 4x4 Intra prediction samples
imgpel **intra4x4_pred_buf[2]; //[3][17]; //!< 4x4 Intra prediction samples
imgpel **intra8x8_pred; //[3][25]; //!< 8x8 Intra prediction samples
imgpel **intra8x8_pred_buf[2]; //[3][25]; //!< 8x8 Intra prediction samples
imgpel **intra16x16_pred; //[3][33]; //!< 8x8 Intra prediction samples
imgpel **intra16x16_pred_buf[2]; //[3][33]; //!< 8x8 Intra prediction samples
char IntraChromaPredModeFlag;
byte mb_field;
byte is_field_mode;
byte luma_transform_size_8x8_flag;
byte temp_transform_size_8x8_flag;
byte NoMbPartLessThan8x8Flag;
byte valid_8x8;
byte valid_4x4;
byte write_mb;
byte is_intra_block;
char DFDisableIdc;
char DFAlphaC0Offset;
char DFBetaOffset;
int skip_flag;
char intra_pred_modes [MB_BLOCK_PARTITIONS];
char intra_pred_modes8x8[MB_BLOCK_PARTITIONS]; //!< four 8x8 blocks in a macroblock
...
添加代码:
if TRACE
// trace: write macroblock header
if (p_Enc->p_trace)
{
if (p_Vid->frame_no == 0 && currMB->mb_x == 2 && currMB->mb_y == 1)
{
printf("\n*********** Pic: %i (I/P) MB_x: %i MB_y: %i *********** \n", p_Vid->frame_no, currMB->mb_x, currMB->mb_y);
printf("MB type:%i\n", currMB->mb_type);
printf("MB mode:%i\n", currMB->c_ipred_mode);
printf("********************************************\n");
}
if (p_Vid->frame_no == 1 && currMB->mb_x == 2 && currMB->mb_y == 1)
{
printf("\n*********** Pic: %i (I/P) MB_x: %i MB_y: %i *********** \n", p_Vid->frame_no, currMB->mb_x, currMB->mb_y);
printf("MB type:%i\n", currMB->mb_type);
printf("MB mode:%i\n", currMB->c_ipred_mode);
printf("MB MV_x:%i\n", currMB->mvd[0][0][0][0]);
printf("MB MV_y:%i\n", currMB->mvd[0][0][0][1]);
printf("********************************************\n");
}
fprintf(p_Enc->p_trace, "\n*********** Pic: %i (I/P) MB: %i Slice: %i **********\n\n", p_Vid->frame_no, currMB->mbAddrX, currSlice->slice_nr);
}
#endif
输出结果: