cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

amd4
Journeyman III

Re: How to fill H264_picture_parameter_2 structure

I have made a network capture which contains 8 RTP packets:

1/ 1 RTP containing SPS packet

2/ 1 RTP containing PPS packet

3/ 1 RTP containing SEI packet

4/ 2 RTP packets containing 2 slice for an IDR Picture

5/ 3 RTP packets containing 3 slice for an non-IDR Picture

http://sip.antisip.com/h264-rtp-to-decode.pcapng

You can see the RTP packets by selecting a packet and do "decode as" -> choose RTP.

Then, in wireshark, "edit" "preference", choose "protocols" -> choose "H264" and put "117"

in "H264 Dynamic Payload types".

Then, you can see my SPS, PPS, SEI, etc...

This is the hard coded extracted values from SPS and PPS: are they correct?

          d->picture_parameter.codec_type = 1; //H264

          d->picture_parameter.profile = 1;

          d->picture_parameter.level = 0x12;

          d->picture_parameter.width_in_mb = 14+1; // from sps pic_width_in_mbs_minus1   

          d->picture_parameter.height_in_mb = 19+1; // from sps pic_heigtht_in_map_units_minus1

          d->picture_parameter.decode_flag = 0;

          d->picture_parameter_2.sps_info.sps_flag.delta_pic_always_zero_flag = 0; //from sps (because pic_order_cnt_type == 2)

          d->picture_parameter_2.sps_info.sps_flag.gaps_in_frame_num_value_allowed_flag = 0; // from sps

          d->picture_parameter_2.sps_info.sps_flag.frame_mbs_only_flag = 1;

          d->picture_parameter_2.sps_info.sps_flag.mb_adaptive_frame_field_flag = 0; // from sps (because frame_mbs_only_flag==1)

          d->picture_parameter_2.sps_info.sps_flag.direct_8x8_inference_flag = 1; // from sps

          d->picture_parameter_2.picture_structure = 2; //no idea if this is right?

          //ALL 0 (and not present) if profile_idc=66

          d->picture_parameter_2.chroma_format = 1; //1 for 420

          d->picture_parameter_2.sps_info.sps_flag.residual_colour_transform_flag = 0; //0 for baseline.

          d->picture_parameter_2.bit_depth_luma_minus8 = 0; //0 for baseline

          d->picture_parameter_2.bit_depth_chroma_minus8 = 0; //0 for baseline

          d->picture_parameter_2.log2_max_frame_num_minus4 = 0; // from sps

          d->picture_parameter_2.pic_order_cnt_type = 2; // from sps

          d->picture_parameter_2.log2_max_pic_order_cnt_lsb_minus4 = 0; // from sps, because pic_order_cnt_type == 2

          d->picture_parameter_2.num_ref_frames = 1; // from sps

          d->picture_parameter_2.reserved_8bit = 0;

          d->picture_parameter_2.pps_info.pps_flag.entropy_coding_mode_flag = 0; //from pps

          d->picture_parameter_2.pps_info.pps_flag.pic_order_present_flag = 0; //from pps

          d->picture_parameter_2.num_slice_groups_minus1 = 0; //from pps

          d->picture_parameter_2.slice_group_map_type = 0; //from pps (because num_slice_groups_minus1==0)

          d->picture_parameter_2.slice_group_change_rate_minus1 = 0; //from pps (because num_slice_groups_minus1==0)

          d->picture_parameter_2.num_ref_idx_l0_active_minus1 = 0; //from pps

          d->picture_parameter_2.num_ref_idx_l1_active_minus1 = 0; //from pps

          d->picture_parameter_2.pps_info.pps_flag.weighted_pred_flag = 0; //from pps

          d->picture_parameter_2.pps_info.pps_flag.weighted_bipred_idc = 0; //from pps

          d->picture_parameter_2.pic_init_qp_minus26 = 0; //from pps

          d->picture_parameter_2.pic_init_qs_minus26 = 0; //from pps

          d->picture_parameter_2.chroma_qp_index_offset = 0; //from pps

          d->picture_parameter_2.pps_info.pps_flag.deblocking_filter_control_present_flag = 1; //from pps

          d->picture_parameter_2.pps_info.pps_flag.constrained_intra_pred_flag = 0; //from pps

          d->picture_parameter_2.pps_info.pps_flag.redundant_pic_cnt_present_flag = 0; //from pps

          //from pps (if stop bit wasn't set)

          d->picture_parameter_2.pps_info.pps_flag.transform_8x8_mode_flag = 0;

          d->picture_parameter_2.second_chroma_qp_index_offset = 0;

          d->picture_parameter_2.reserved_16bit = 0;

This is additionnaly incremented for each new OVDecodePicture call:

d->picture_parameter_2.frame_num++;

I'll be very happy if you can verify my SPS/PPS and if you can provide the "bit files" for this stream.

The image should be my "hand"...

Tks,

Aymeric

0 Likes
himanshu_gautam
Grandmaster

Re: How to fill H264_picture_parameter_2 structure

hi amd,

Here is some data, that may be useful to you.

I have taken a raw yuv file akiyo_qcif.yuv from http://trace.eas.asu.edu/yuv/ (176 X 144).

I encoded it using quality.config file. After changing profile=66, pictureHeight=144, pictureWidth=176, encNumMBsPerSlice=99. The output is akiyo.264

You can confirm akiyo.264 using elecard stream analyzer. http://www.elecard.com/en/download/products.html

Now I ran the internal H264 parser on this akiyo.264 file and generated the bitstream files ( bitstream, datacontrol, pictureparameter1, pictureparameter2 for 300 frames).

I will attach a modified snippet of the parser code, to fill ovd_slice_control_data, in some time. Hope you will be able to find your way after this. Please let us know your progress.

amd4
Journeyman III

Re: How to fill H264_picture_parameter_2 structure

Hi Himanshu,

Tks a lot for the files: it did really helped me to figure out a mistake in my H264_picture_parameter_2

structure! ie: missing 0x10 to be filled in picture_parameter_2.scaling_lists_4x4 and picture_parameter_2.scaling_lists_8x8.

Now, I have IDR fully working.

Unfortunatly, non-IDR frame doesn't work well: the more I move, the more image becomes

bad. static part of images are still correct.

Do you have any idea where I should look for? Which parameter, being wrong, may introduce such error?

Tks for your valuable help.

Regards

Aymeric


0 Likes
himanshu_gautam
Grandmaster

Re: How to fill H264_picture_parameter_2 structure

It looks like you are able to decode I frame properly, but some parameter is missing in terms of P frames/ B frames.

Firstly you can try to create all I frame video and pass it through our H264 decoder. Then try with IPPPPPPIPP frames.

If all I frames work and IPPPI does not work, this means reference frame management is not correct. You need to check how you are feeding the reference frames to the decoder and also in SPS number of reference frames are set properly.

0 Likes
amd4
Journeyman III

Re: How to fill H264_picture_parameter_2 structure

Hi

In my network capture, I can see "num_ref_frames is 1" and in my code, I set:

picture_parameter_2.num_ref_frames = 1;

I have no understanding about "picture_parameter_2.frame_num":

In your baseline profile picture_parameter_2.frame_num is incremented by one for either the I-frame or the P-frame. So what is the reason for that parameter? What should it be? I tried setting it to 0 and never increment it: there is no difference in my images.

The documentation says it's "The field is used as an identifier for pictures." But where that value should come from?

And what about "reference" and "intra_flag": again, whatever value I provide, I have the same images: IDR correct, and non-IDR not working as expected.

A tiny bit should still be wrong in my code...

Tks a lot!

Regards

Aymeric

0 Likes
himanshu_gautam
Grandmaster

Re: How to fill H264_picture_parameter_2 structure

amd wrote:

Hi

In my network capture, I can see "num_ref_frames is 1" and in my code, I set:

picture_parameter_2.num_ref_frames = 1;

I have no understanding about "picture_parameter_2.frame_num":

This is the fram_num parameter which in slice header of the H.264 standard. There are few rules to set it.

In your baseline profile picture_parameter_2.frame_num is incremented by one for either the I-frame or the P-frame. So what is the reason for that parameter? What should it be? I tried setting it to 0 and never increment it:

The documentation says it's "The field is used as an identifier for pictures." But where that value should come from?

Rule 1. For now you can increment it by one for every frame.

Set this log2_max_frame_num_minus4 to any value between 0 to 12 (Refer OpenVideo API documentation attached above)

for ex: if this 0 then frame_num can take values from 0 to 15.

frame_num = (frame_num + 1) % (1 << (log2_max_frame_num_minus4 + 4))

Rule 2. if the current frame is an IDR then make frame_num to 0.

This value needs to be generated as per H.264 spec. For baseline profile you follow the above 2 rules. If you have H.264 standard then search for frame_num under slice_header semantics

there is no difference in my images.

can you confirm all your encoded frames were IDR?

And what about "reference" and "intra_flag": again, whatever value I provide, I have the same images: IDR correct, and non-IDR not working as expected.

reference flag: set it to 1.

-- intra_flag: set to 1 for I or IDR frames. Set it to 0 for P frames.

Share all the test vectors that get generated with the corresponding picture_parameter_1 and picture_parameter_2 structure. You can probably share a similar attachment as I had done before.

0 Likes
mrkenthesigh
Journeyman III

Re: How to fill H264_picture_parameter_2 structure

hi himanshu.gautam,

May I ask that what is the "internal H264 parser" you mentioned?

It seems that the files in "OVDecodeDataH264" folder are generated by the parser.

But there are no such things in "OVDecodeRender" sample.

Will you provide the parser (code/docs)?

Or we developers have to figure it out on our own.

0 Likes
himanshu_gautam
Grandmaster

Re: How to fill H264_picture_parameter_2 structure

"internal H264 parser" is a AMD propriatary Code, which I am not allowed to share. This code is used to generate the bitfiles which are fed as input to the OVDecodeRender Sample. There should probably be some opensource / free applications for this purpose, but I am not aware of them.

0 Likes
amd4
Journeyman III

Re: How to fill H264_picture_parameter_2 structure

Hi,

Tks again for your answer and details. It's again helpfull and it helps to go closer...

Rule 1. For now you can increment it by one for every frame.

Set this log2_max_frame_num_minus4 to any value between 0 to 12 (Refer OpenVideo API documentation attached above)

for ex: if this 0 then frame_num can take values from 0 to 15.

frame_num = (frame_num + 1) % (1 << (log2_max_frame_num_minus4 + 4))

Rule 2. if the current frame is an IDR then make frame_num to 0.

This value needs to be generated as per H.264 spec. For baseline profile you follow the above 2 rules. If you have H.264 standard then search for frame_num under slice_header semantics

I'm still not understanding.

What I'm doing now: (my log2_max_frame_num_minus4 is 0)

1/ I'm setting frame_num=0 for each IDR. Should I do the same for non-IDR I-slice?

2/ I'm incrementing by 1 for other non-IDR P-slice

results: frame_num is growing above 15???? Because I have more than 15 non-IDR P-slice

between each IDR? If this is not allowed, then I guess I'm wrong. What should I do?

Share all the test vectors that get generated with the corresponding picture_parameter_1 and picture_parameter_2 structure. You can probably share a similar attachment as I had done before.

Well... I would prefer to provide an RTP network capture: would you be able then to build the bit files?

Tks.

Aymeric

0 Likes
himanshu_gautam
Grandmaster

Re: How to fill H264_picture_parameter_2 structure

What I'm doing now: (my log2_max_frame_num_minus4 is 0)

1/ I'm setting frame_num=0 for each IDR. Should I do the same for non-IDR I-slice?

2/ I'm incrementing by 1 for other non-IDR P-slice

results: frame_num is growing above 15???? Because I have more than 15 non-IDR P-slice

between each IDR? If this is not allowed, then I guess I'm wrong. What should I do?

If (IDR)

frame_num = 0;

else

frame_num = (frame_num + 1) % (1 << (log2_max_frame_num_minus4 + 4));

In your case log2_max_frame_num_minus4 =0, then this will be

If (IDR)

frame_num = 0;

else

frame_num = (frame_num + 1) % 16;

0 Likes