分享

h.264解码中的一些变量的说明 - 'kite一路顺风"的个人空间 - 博客中国人 - ...

 dongmeng 2010-05-13

h.264解码中的一些变量的说明

上一篇 / 下一篇  2010-04-22 15:06:27

载自以下

http://blog.sina.com.cn/s/blog_4185dfc70100g6yn.html    

http://users.ecel./~zhifeng/personal/study/Project_Notes.htm#JM14.0:

-------------------------encoder-----------------------------------------

encoder architecture

encoding:
main()-->encode_one_frame()-->frame_picture()--code_a_picture(frame)-->encode_one_slice()-->start_macroblock()/encode_one_macroblock()
void (*encode_one_macroblock) (Macroblock *currMB)==>void encode_one_macroblock_high (Macroblock *currMB);
compute_mode_RD_cost(mode, currMB, enc_mb, &min_rdcost, &min_dcost, &min_rate, i16mode, bslice, &inter_skip);

packetization:
main()-->encode_one_frame()-->writeout_picture()-->writeUnit()

save decoded picture buffer (DPB):
main()-->encode_one_frame()-->store_picture_in_dpb(enc_frame_picture[0])-->insert_picture_in_dpb(dpb.fs[dpb.used_size],p)
in dump_dpb(), we may set DUMP_DPB = 1 to get debug information!

write test_rec.yuv:
main()-->flush_dpb()-->output_one_frame_from_dpb()-->write_stored_frame(dpb.fs[pos], p_dec)-->write_picture(fs->frame, p_out, FRAME)-->write_out_picture(p, p_out)
-->img2buf (p->imgY, buf, p->size_x, p->size_y, symbol_size_in_bytes, crop_left, crop_right, crop_top, crop_bottom)
-->write(p_out, buf, (p->size_y-crop_bottom-crop_top)*(p->size_x-crop_right-crop_left)*symbol_size_in_bytes)
 

在JM14.0中有两个结构体比较重要:ImageParametersStorablePicture

在global.h中定义: ImageParameters用于保存程序运算过程的图像参数

1)imgpel mpr [MAX_PLANE][16][16]; 用于保存预测的像素值

2)int m7 [MAX_PLANE][16][16]; 用于保存residue data的处理过程临时数据(注释写的有问题“the diff pixel values between the original macroblock/block and its prediction”)

3)int ****cofAC; / int ***cofDC; 用于保存经过transform和quantization以后的宏块系数

4)Slice *currentSlice;

DataPartition *partArr;

Bitstream *bitstream;

byte *streamBuffer; 用于保存最终的编码结果,输出到test.264

 

在mbuffer.h中定义:StorablePicture用于保存图像处理的结果

imgpel ** imgY; / imgpel *** imgUV; 用于保存重构图像的像素值,输出到test_rec.yuv

imgpel ** p_curr_img; ??

short **** mv; 用于保存motion vector的值

 

这两个结构体各定义了一个全局变量用来保存图像的处理结果:

在lencod.c中定义:ImageParameters images, *img = &images;

在image.c中定义:StorablePicture *enc_picture;(其实还定义了StorablePicture **enc_frame_picture;但是enc_frame_picture[i]取决于rd_pass变量对i有不同的取值,在实验中只用到enc_frame_picture[0])

 

在zhifeng.c和zhifeng.h两个文件中用到img->mpr,enc_picture->imgY/enc_picture->imgUV和enc_picture->mv来得到所有像素的motion vector和residue data。

---------------------------------------------------

me_fullfast.c中的FastFullPelBlockMotionSearch()函数中:
mcost = block_sad[pos_00[list][ref]] + MV_COST_SMP (lambda_factor, 0, 0, pred_mv[0], pred_mv[1]);
是在根据RDOptimization做rate distortion optimazatin。虽然这里RateControlEnable=0,但是对于每p帧中任一宏块都有7中预测模式,理论上用4×4的block得到的distortion最小,但是rate最大,这条语句就是做两者的balance。
RateControlEnable的设置是对整个video sequence做的。


用-d "*.cfg"不用-f "*.cfg"!!!(-f好像是组合参数,lencod -f "encoder_baseline.cfg"对于没有修改的JM中的lencod运行出错)

可以用Bit_Buffer来计算每一帧的大小,但是好像不能计算slice的大小。
image.c:Bit_Buffer[total_frame_buffer] = (int) (stats->bit_ctr - stats->bit_ctr_n);


original图像:

/ buf = malloc (xs*ys * symbol_size_in_bytes)
image.c-->ReadOneFrame()-->
\ read(p_in, buf, bytes_y)
 

但是buf的值在ReadOneFrame()最后被释放:free (buf);
通过imgY_org_frm保存的是16位,高8位为0x00:
buf2img(imgY_org_frm_JV[0], buf, xs, ys, symbol_size_in_bytes);
buf2img(imgUV_org_frm[0], buf, xs_cr, ys_cr, symbol_size_in_bytes);
buf2img(imgUV_org_frm[1], buf, xs_cr, ys_cr, symbol_size_in_bytes);


重要参数:
stats->bit_ctr_parametersets_n:SPS和PPS的位数
start_sequence()-->stats->bit_ctr_parametersets_n = len;
encode_one_frame()-->stats->bit_ctr_parametersets_n=0;

stats->bit_ctr_n: 当前处理的帧之前的所有位数
encode_one_frame()-->stats->bit_ctr_n = stats->bit_ctr;

stats->bit_ctr: 在ReportFirstframe()中清零!
ReportFirstframe()-->stats->bit_ctr = 0;

ok:
output:
.cfg
ReportFrameStats = 0 # (0:Disable Frame. Statistics 1: Enable)
DisplayEncParams = 0 # (0:Disable Display of Encoder Params 1: Enable)
Verbose = 1 # level of display verboseness (0:short, 1:normal, 2:detailed)

in dump_dpb(), we may set DUMP_DPB = 1 to get debug information!

全局变量:
frame_pic
defined in global.h: Picture **frame_pic;
*img:
defined in lencod.c: ImageParameters images, *img = &images;
referenced in global.h: extern ImageParameters *img;


difference between JM13 and JM14:
there is no LoopFilterDisable in JM14, but deblocking filter!

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多