35 Replies Latest reply on Oct 16, 2013 2:18 AM by himanshu.gautam

    How to fill H264_picture_parameter_2 structure

    amd

      Hi all,

       

      I'm trying to implement an H264 decoder using opencl 1.2 and I'm currently studying the OVDecodeRender sample project.

       

      SideNote: I have been trying to compile the OVDecodeRender.zip sample, but it seems like it is based on SDK 2.7 and it

      failed with 2.8. Do you have any update of this sample? -I have manage to understand what I want from the sample, so this

      is not really urgent matter.

       

      I want to use the H264 decoder to decode an RTP stream in baseline profile. It appears that I need to decode myself all the SPS and PPS structure?

      Is it possible to avoid this? (I worked with several h264 decoder and all of them just need the SPS and PPS NAL untouched which is far

      easier....).

       

      I have started to parse SPS and PPS, however, I'm not able to understand some of the value of H264_picture_parameter_2

       

      What is the exact required values for "picture_parameter.level"?

          For example for level 4.1 -> picture_parameter.level = 41?

       

      Is pic_width_in_mbs_minus1 the exact value for "picture_parameter.width_in_mb"?

      Is  pic_heigtht_in_map_units_minus1 the exact value for "picture_parameter.height_in_mb"?

       

      I have no idea what should be in "picture_parameter_2.picture_structure"?

       

      I'm not sure at all how I should fill those last 3 values:

       

              picture_parameter_2.frame_num = 0; //?

              picture_parameter_2.intra_flag = 1; //?

              picture_parameter_2.reference = 1; //?

       

      If you have any hints about what should be in "slice_data_control" and how I should know

      the number of slice... I would also be greatfull.

       

      Tks to all

        • Re: How to fill H264_picture_parameter_2 structure
          himanshu.gautam

          SideNote: I have been trying to compile the OVDecodeRender.zip sample, but it seems like it is based on SDK 2.7 and it

          failed with 2.8. Do you have any update of this sample? -I have manage to understand what I want from the sample, so this

          is not really urgent matter.

           

          I want to use the H264 decoder to decode an RTP stream in baseline profile. It appears that I need to decode myself all the SPS and PPS structure?

          Is it possible to avoid this? (I worked with several h264 decoder and all of them just need the SPS and PPS NAL untouched which is far

          easier....).

           

          Hi amd,

          What errors are you getting in compiling the sample with SDK 2.8.?

           

          AFAIK, it is required to extract out the structures containing decoded information on a frame by frame basis, as shown in sample. Anyways I will ask someone more knowledgeable to help you

          1 of 1 people found this helpful
            • Re: How to fill H264_picture_parameter_2 structure
              amd

              Hi / Tks for your answer!

              What errors are you getting in compiling the sample with SDK 2.8.?

               

              First error was that the location of include

               

              #include <OVDecode/OVDecodeTypes.h>

              #include <OVDecode/OVDecode.h>

               

              while the file exist in app SDK 2.8 in:

               

              #include <OpenVideo/OVDecodeTypes.h>

              #include <OpenVideo/OVDecode.h>

               

              The second error was about usage of deprecated APIs.

              Using #define CL_USE_DEPRECATED_OPENCL_1_1_APIS solved that one.

               

              Then some link issue with checkVal, error, etc.. I have solved those ones // just removed the

              macro to not spend time on it.

               

              At least, then I have a binary compiled. I have no screen on my "asus HD 7750" so the app

              won't work as it look for a display connected.

               

              But it's not a big issue and not my real question!

               

              AFAIK, it is required to extract out the structures containing decoded information on a frame by frame basis, as shown in sample. Anyways I will ask someone more knowledgeable to help you

               

              Tks! I'll keep waiting for more!

               

              Aymeric

                • Re: How to fill H264_picture_parameter_2 structure
                  amd

                  Hi Again,

                   

                  I already did some progress and I'm able to run my application.

                   

                  I have OVDecodePicture returning true: so I guess, I'm getting closer. However, I still

                  haven't been able to display the correct NV12 image.... I have pixel movings and I can

                  see a form in the displayed/decoded image which is clearly ME... but it's not yet working.

                   

                  The image (my hand) is green and other part are grey.

                   

                  First, these are the parameters I have extracted from my SPS/PPS: hardcoded currently

                  for testing purpose:

                   

                         ovd_picture_parameter    picture_parameter;

                          H264_picture_parameter_2 picture_parameter_2;

                          ovd_slice_data_control   slice_data_control[1]; /* with slicenum=1 */

                          unsigned int num_event_in_wait_list=0;

                   

                   

                          memset(&picture_parameter, 0, sizeof(ovd_picture_parameter));

                          picture_parameter.codec_type = 1; //H264

                          picture_parameter.profile = 1;

                          picture_parameter.level = 40;

                   

                          //368x480

                          picture_parameter.width_in_mb = 22+1; // from sps pic_width_in_mbs_minus1   

                          picture_parameter.height_in_mb = 29+1; // from sps pic_heigtht_in_map_units_minus1

                          picture_parameter.decode_flag = 0;

                   

                   

                   

                          memset(&picture_parameter_2, 0, sizeof(H264_picture_parameter_2));

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

                          picture_parameter_2.sps_info.sps_flag.gaps_in_frame_num_value_allowed_flag = 0; // from sps

                          picture_parameter_2.sps_info.sps_flag.frame_mbs_only_flag = 1;

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

                          picture_parameter_2.sps_info.sps_flag.direct_8x8_inference_flag = 1; // from sps

                   

                   

                   

                   

                          picture_parameter_2.picture_structure = 3; //no idea if this is right?

                   

                   

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

                          picture_parameter_2.chroma_format = 1; //0 for baseline

                          picture_parameter_2.sps_info.sps_flag.residual_colour_transform_flag = 0; //0 for baseline.

                          picture_parameter_2.bit_depth_luma_minus8 = 0; //0 for baseline

                          picture_parameter_2.bit_depth_chroma_minus8 = 0; //0 for baseline

                   

                   

                          picture_parameter_2.log2_max_frame_num_minus4 = 0; // from sps

                          picture_parameter_2.pic_order_cnt_type = 2; // from sps

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

                          picture_parameter_2.num_ref_frames = 1; // from sps

                          picture_parameter_2.reserved_8bit = 0;

                   

                   

                   

                   

                          picture_parameter_2.pps_info.pps_flag.entropy_coding_mode_flag = 0; //from pps

                          picture_parameter_2.pps_info.pps_flag.pic_order_present_flag = 0; //from pps

                          picture_parameter_2.num_slice_groups_minus1 = 0; //from pps

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

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

                          picture_parameter_2.num_ref_idx_l0_active_minus1 = 0; //from pps

                          picture_parameter_2.num_ref_idx_l1_active_minus1 = 0; //from pps

                   

                   

                          picture_parameter_2.pps_info.pps_flag.weighted_pred_flag = 0; //from pps

                          picture_parameter_2.pps_info.pps_flag.weighted_bipred_idc = 0; //from pps

                          picture_parameter_2.pic_init_qp_minus26 = 0; //from pps

                          picture_parameter_2.pic_init_qs_minus26 = 0; //from pps

                          picture_parameter_2.chroma_qp_index_offset = 0; //from pps

                          picture_parameter_2.pps_info.pps_flag.deblocking_filter_control_present_flag = 1; //from pps

                          picture_parameter_2.pps_info.pps_flag.constrained_intra_pred_flag = 0; //from pps

                          picture_parameter_2.pps_info.pps_flag.redundant_pic_cnt_present_flag = 0; //from pps

                   

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

                          picture_parameter_2.pps_info.pps_flag.transform_8x8_mode_flag = 0;

                          picture_parameter_2.second_chroma_qp_index_offset = 0;

                          picture_parameter_2.reserved_16bit = 0;

                   

                   

                          picture_parameter_2.frame_num = 0; //?

                          picture_parameter_2.intra_flag = 1; //?

                          picture_parameter_2.reference = 1; //?

                   

                   

                          memset(&slice_data_control[0], 0, sizeof(ovd_slice_data_control));

                          slice_data_control[0].SliceBytesInBuffer = end-p;

                          slice_data_control[0].SliceBitsInBuffer = slice_data_control[0].SliceBytesInBuffer*8; //?

                          slice_data_control[0].SliceDataLocation = 0;

                   

                  Do I have to analyse each NAL (other than SPS/PPS) and extract some of the data? Or can

                  I just provide the other NAL as they are?

                   

                  Are those values correct:

                   

                  // in wireshark I see in sps pic_width_in_mbs_minus1    == 22

                          picture_parameter.width_in_mb = 22+1;

                  // in wireshark I see in sps pic_heigtht_in_map_units_minus1== 29

                          picture_parameter.height_in_mb = 29+1; // from sps

                   

                  Is there any value that should be changed for each NAL in those structure?

                   

                  Tks

                  Aymeric

              • Re: How to fill H264_picture_parameter_2 structure
                amd

                Hi All,

                 

                no answer yet - I'm doing -possible- progress myself so it might be usefull to post where I am.

                 

                1/ I'm still only able to view a broken frame where I clearly see part of the correct image (you can see my head, my hairs? I wish you could see better...)broken-video-openvideo.PNG

                2/ For intra_flag and reference, I think i found the values:

                For I-Frame:

                 

                picture_parameter_2.intra_flag = 1

                picture_parameter_2.reference =1

                 

                For P-Frame:

                 

                picture_parameter_2.intra_flag = 0

                picture_parameter_2.reference =1

                 

                3/ I'm not 100% sure of my other parameters, but both my ovd_picture_parameter and H264_picture_parameter_2 appears fine to me.

                 

                4/ After some testing, I understand that I'm receiving several I-slice or P-slice in separate RTP packets. I figured out that i should fill "ovd_slice_data_control" and this might be where I have some issue.

                 

                Here is the process, I use:

                 

                1/ each I-slice is combined into one buffer.

                2/ before first I-slice data, I append 00 00 00 01

                3/ the first octet of frst I-slice is removed (F-bit, nal_ref_idc and type of nal unit) I guess this is required in RTP only

                4/ before each I-slice data, I append 00 00 01

                 

                I do the same for P-slice

                 

                For each of the slice, I fill

                 

                slice_data_control[count_slice].SliceDataLocation = 0 // for first slice

                OR

                slice_data_control[count_slice].SliceDataLocation = slice_data_control[count_slice-1].SliceDataLocation+slice_data_control[count_slice-1].SliceBytesInBuffer;

                 

                slice_data_control[count_slice].SliceBytesInBuffer = slice_len;

                slice_data_control[count_slice].SliceBitsInBuffer = slice_data_control[*count_slice].SliceBytesInBuffer*8;

                 

                 

                I hope someone is listening and can help me to get this working. I must be very close...

                 

                Regards

                Aymeric

                  • Re: How to fill H264_picture_parameter_2 structure
                    himanshu.gautam

                    Hi Aymeric,

                    I am working on understanding these fields myself. I will post my learning in a few days.

                    • Re: How to fill H264_picture_parameter_2 structure
                      himanshu.gautam

                      Hi,

                      did you got any further?

                      Have you tried using some opensource libraries for parsing your video to SPS/PPS blocks? ffmpeg might help.

                      Still digging in, will keep you posted.

                        • Re: How to fill H264_picture_parameter_2 structure
                          amd

                          Hi,

                           

                          Tks for your answer.

                           

                          Parsing SPS/PPS doesn't seems to be the issue. I'm pretty sure I'm extracting the correct

                          information from SPS and PPS. It's still possible that i have made error in converting values

                          from SPS/PPS to the structures... There is absolutly no reference code on this I could find.

                           

                          I think my issue relates to formating the data and information to provide for ovd_slice_data_control.

                          I have tried every formating i could think of...


                          Regards

                          Aymeric

                            • Re: How to fill H264_picture_parameter_2 structure
                              himanshu.gautam

                              I am quite sure, you would have gone through this document: http://developer.amd.com/wordpress/media/2012/10/OpenVideo_Decode_API.PDF

                              But just adding for other reader's reference.

                               

                              FYI I have a piece of code, that converts a *.264 file into the bit files which are fed as input in the OVDecodeRender Sample. If you can ask some pointed questions about how this parsing is happening, i may try to browse through the code, and try answering your question. I am not allowed to share the parsing code here.

                                • Re: How to fill H264_picture_parameter_2 structure
                                  amd

                                  Hi Himanshu,

                                   

                                  Tks for the document: I already used it, but the explanation on slice is light...

                                   

                                  4.3 OVD_BITSTREAM_DATA and OVD_SLICE_DATA_CONTROL

                                   

                                  OVD_BITSTREAM_DATA contains blocks of compressed bitstream data (see Figure 3). The Decoder

                                  (host) stores the data blocks size/location information in OVD_SLICE_DATA_CONTROL. Every data

                                  block has its own control data structure. OVD_BITSTREAM_DATA must be 128 byte aligned.

                                   

                                  I was missing 128byte padding. So I have added it today at the end of my last slice. But it didn't helped.

                                   

                                  I'm pretty sure I have trouble with formating my OVD_BITSTREAM_DATA and values for OVD_SLICE_DATA_CONTROL .... else, it could still be an error with SPS/PPS... who knows...

                                   

                                  Questions:

                                  1/ How is the OVD_SLICE_DATA_CONTROL filled where there are multiple slice?

                                  2/ Do you have sample bit files for a BASELINE profile decoding?

                                   

                                  Regards

                                  Aymeric

                                  • Re: How to fill H264_picture_parameter_2 structure
                                    amd

                                    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

                                      • Re: How to fill H264_picture_parameter_2 structure
                                        himanshu.gautam

                                        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.

                                        1 of 1 people found this helpful
                                          • Re: How to fill H264_picture_parameter_2 structure
                                            amd

                                            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


                                              • Re: How to fill H264_picture_parameter_2 structure
                                                himanshu.gautam

                                                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.

                                                  • Re: How to fill H264_picture_parameter_2 structure
                                                    amd

                                                    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

                                                      • Re: How to fill H264_picture_parameter_2 structure
                                                        himanshu.gautam

                                                        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.

                                                          • Re: How to fill H264_picture_parameter_2 structure
                                                            amd

                                                            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

                                                              • Re: How to fill H264_picture_parameter_2 structure
                                                                himanshu.gautam

                                                                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;

                                                      • Re: How to fill H264_picture_parameter_2 structure
                                                        mrkenthesigh

                                                        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.

                                                          • Re: How to fill H264_picture_parameter_2 structure
                                                            himanshu.gautam

                                                            "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.

                                                              • Re: How to fill H264_picture_parameter_2 structure
                                                                amd

                                                                himanshu.gautam a écrit:

                                                                 

                                                                "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.

                                                                Just to add: I'm still not able to really test your bitstream because your OVDecodeRender is not compiling for the latest 2.8 sdk? It would help me to test the bitfiles that I would generate with my own app!

                                                                 

                                                                Tks

                                                                Aymeric

                                                                  • Re: How to fill H264_picture_parameter_2 structure
                                                                    himanshu.gautam

                                                                    I though You were able to run OVDecodeRender Sample long back. I will try to post a sample code that works with SDK 2.8 soon.

                                                                      • Re: How to fill H264_picture_parameter_2 structure
                                                                        amd

                                                                        I have modified the sample in order to read your bit files. But not to decode and render the files.

                                                                        Also, If I'm correct, your baseline sample only have one slice for each NAL and only one i-slice for first frame? And also only one slice in each bit file... Not enough close to my real life!!!

                                                                         

                                                                        I'm looking to receive your modified sample! It will help!

                                                                         

                                                                        Regards

                                                                        Aymeric

                                                                          • Re: How to fill H264_picture_parameter_2 structure
                                                                            himanshu.gautam

                                                                            PFA the changed files in OVDecodeRender sample to make it work with SDK 2.8. You need to make sure that you use old SDKUtil library and header though.

                                                                             

                                                                            amd wrote:

                                                                             

                                                                            I have modified the sample in order to read your bit files. But not to decode and render the files.

                                                                            Also, If I'm correct, your baseline sample only have one slice for each NAL and only one i-slice for first frame? And also only one slice in each bit file... Not enough close to my real life!!!

                                                                            If the baseline profile was not enough, probably you can point me to some yuv file, for which I can run the parser and sent you the results.

                                                                              • Re: How to fill H264_picture_parameter_2 structure
                                                                                amd

                                                                                Hi,

                                                                                 

                                                                                Tks for the update.

                                                                                 

                                                                                I originally had troubles to compile because another sdkutil include path was included in the OVDecodeRender vs2010 project...

                                                                                 

                                                                                I have finally compiled with your OVRender_fix, however, I'm still not able to run the project.

                                                                                 

                                                                                I have a windows 8 with 2 cards and 2 displays (one per card). OVDecodeRender shows:

                                                                                Platform 0 : NVIDIA Corporation

                                                                                Platform 1 : Advanced Micro Devices, Inc.

                                                                                 

                                                                                However, when testing I have 2 displays found being active, but both are failing

                                                                                at line: 468 of OVDecodeRender.cpp:

                                                                                 

                                                                                status = clGetGLContextInfoKHR(properties,

                                                                                                                      CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR,

                                                                                                                      0,

                                                                                                                      NULL,

                                                                                                                      &deviceSize);

                                                                                 

                                                                                For both display (one with a window being opened on nvidia screen and the other on a window being opened on amd screen) , the returned deviceSize is 0

                                                                                 

                                                                                Any hints?

                                                                                Aymeric

                                                                                 

                                                                                EDITING POST: I have managed to skip the "CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR" and replaced the code to search for "interopDevice" from

                                                                                 

                                                                                     status = clGetGLContextInfoKHR( properties,

                                                                                                                    CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR,

                                                                                                                    sizeof(cl_device_id),

                                                                                                                    &interopDevice,

                                                                                                                    NULL);

                                                                                 

                                                                                to:

                                                                                 

                                                                                     status = clGetGLContextInfoKHR( properties,

                                                                                                                    CL_DEVICES_FOR_GL_CONTEXT_KHR,

                                                                                                                    sizeof(cl_device_id),

                                                                                                                    &interopDevice,

                                                                                                                    NULL);

                                                                                 

                                                                                Now, I have a clDeviceID, but it is different compared to the one found by "OVDecodeGetDeviceInfo".

                                                                                 

                                                                                Later, the runRemovePitchKernel will fail there:

                                                                                 

                                                                                Error: Error: clEnqueueNDRangeKernel failed! (remove_pitch_kernel)

                                                                                Error code : CL_INVALID_WORK_GROUP_SIZE

                                                                                Location : OVDecodeRender.cpp:834

                                                                                 

                                                                                I guess the issue is coming from the initial error? It seems I cannot have CL_DEVICES_FOR_GL_CONTEXT_KHR returning a cl_device_id for my amd card?

                                                                                 

                                                                                tks again!

                                                                                  • Re: How to fill H264_picture_parameter_2 structure
                                                                                    amd

                                                                                    Today... After my test described above, I noticed there was a driver update for my "AMD Radeon HD 7700 Series"

                                                                                     

                                                                                    Catalyst version 13.4 was installed

                                                                                    Driver Packaging Version: 12.104-130328a-155980C-ATI was  installed

                                                                                     

                                                                                    And my non-IDR image... are now correctly rendered!!! At least from the initial test I've done.

                                                                                     

                                                                                    As far as I can tell, I had installed the advised 12.x catalyst version (installed in February I think)

                                                                                     

                                                                                    I hope the issue to be solved 100%...

                                                                                     

                                                                                    Aymeric

                                                                                  • Re: How to fill H264_picture_parameter_2 structure
                                                                                    lk_amd

                                                                                    Hi,
                                                                                    can you give some sample or explain on OVDecodePicture() deal with multi slices?

                                                                                     

                                                                                    My test have 4 silce in one frame , so I malloc 4 slice_data_control , set params, and send the begin address to OVDecodePicture,

                                                                                     

                                                                                    Is this the right way ?

                                                                                     

                                                                                    thanks

                                                                                      • Re: How to fill H264_picture_parameter_2 structure
                                                                                        amd

                                                                                        Hi,

                                                                                         

                                                                                        I'm the author of this thread, however, I still got some troubles to decode!

                                                                                         

                                                                                        This is what I'm doing to create and fill "ovd_slice_data_control" structure with nal_len

                                                                                        being my slice size:

                                                                                         

                                                                                        For all slices:

                                                                                         

                                                                                            if (*count_slice==0)

                                                                                              slice_data_control[*count_slice].SliceDataLocation = 0;

                                                                                            else

                                                                                              slice_data_control[*count_slice].SliceDataLocation = slice_data_control[(*count_slice)-1].SliceDataLocation+slice_data_control[(*count_slice)-1].SliceBytesInBuffer;

                                                                                            slice_data_control[*count_slice].SliceBytesInBuffer = nal_len;

                                                                                            slice_data_control[*count_slice].SliceBitsInBuffer = slice_data_control[*count_slice].SliceBytesInBuffer*8;

                                                                                            (*count_slice)++;

                                                                                         

                                                                                        All slices starts with :

                                                                                            *dst++=0;

                                                                                            *dst++=0;

                                                                                            *dst++=1;

                                                                                         

                                                                                        Then

                                                                                         

                                                                                                 int size_of_slice_structure = count_slice*sizeof(ovd_slice_data_control);

                                                                                         

                                                                                                OVresult res = OVDecodePicture(d->session,

                                                                                                  &d->picture_parameter,

                                                                                                  &d->picture_parameter_2,

                                                                                                  sizeof(H264_picture_parameter_2),

                                                                                                  &p,

                                                                                                  (unsigned int)(end-p),

                                                                                                  slice_data_control,

                                                                                                  size_of_slice_structure,

                                                                                                  d->nv12_surface,

                                                                                                  num_event_in_wait_list,

                                                                                                  NULL,

                                                                                                  &eventRunVideoProgram,

                                                                                                  0);

                                                                                         

                                                                                         

                                                                                        About my previous post: I said that I was able to have video by upgrading the driver: I was wrong: in fact, I'm able to decode some stream made with some encoders and not others and don't think the driver was faulty. More tests needed to find out...

                                                                                         

                                                                                        Regards

                                                                                        Aymeric

                                                                                          • Re: How to fill H264_picture_parameter_2 structure
                                                                                            lk_amd

                                                                                            Thanks Aymeric,

                                                                                            I did the same as you suggest, but I only get 1/4 picture on the top , the 3/4 below all green ( I convert the nv12_surface to YUV, checked  using yuv viewer )

                                                                                            I test a I frame frome a BD m2ts file,

                                                                                             

                                                                                            the slice_data_controls are :

                                                                                            0x0027FA20  08 24 05 00 00 00 00 00 81 a4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  .$......??......................

                                                                                            0x0027FA40  18 52 05 00 81 a4 00 00 43 aa 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  .R..??..C?......................

                                                                                            0x0027FA60  80 68 05 00 c4 4e 01 00 10 ad 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  €h..?N...?......................

                                                                                            0x0027FA80  08 20 05 00 d4 fb 01 00 01 a4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

                                                                                            code are:

                                                                                            slice_data_control[0].SliceDataLocation = 0;                   

                                                                                            slice_data_control[0].SliceBytesInBuffer = 42113;

                                                                                            slice_data_control[0].SliceBitsInBuffer = 42113 * 8;

                                                                                            slice_data_control[1].SliceDataLocation = 42113;                   

                                                                                            slice_data_control[1].SliceBytesInBuffer = 43587;

                                                                                            slice_data_control[1].SliceBitsInBuffer = 43587 * 8;

                                                                                            slice_data_control[2].SliceDataLocation = 85700;                   

                                                                                            slice_data_control[2].SliceBytesInBuffer = 44304;

                                                                                            slice_data_control[2].SliceBitsInBuffer = 44304 * 8;

                                                                                            slice_data_control[3].SliceDataLocation = 130004;                   

                                                                                            slice_data_control[3].SliceBytesInBuffer = 41985;

                                                                                            slice_data_control[3].SliceBitsInBuffer = 41985 * 8;

                                                                                            reserved part set 0

                                                                                             

                                                                                            then  bitstream_data 

                                                                                            // first I slice

                                                                                            0x085E0040  00 00 01 65 88 80 00 0b 00 00 06 af ef 26 72 f4 37 5e 91 90 ee 47 e4 c5 b7 48 68 f4 17 11 11 7c  ...e?€.....??&r?7^???G???Hh?...|

                                                                                            //  2nd I slice

                                                                                            0x085EA4C0  b0 00 00 01 65 00 3f c8 88 00 00 b0 00 00 6a ef 34 9b 9b 38 61 91 29 c4 75 aa 9f 54 da 5e c1 46  ?...e.???..?..j?4??8a?)?u??T?^?F

                                                                                            // 3 I slice

                                                                                            0x085F4F00  e6 79 ff fa 00 00 01 65 00 1f e2 22 00 00 2c 00 00 12 bf cb 50 cf f5 78 6e 95 d8 e4 e4 06 04 9c  ?y.?...e..?"..,...??P??xn????..?

                                                                                            // 4 I slice

                                                                                            0x085FFC10  e8 6d 21 50 00 00 01 65 00 0b f4 88 80 00 0b 00 00 04 af ed f1 99 88 1b e3 15 0c a6 54 41 4d e6  ?m!P...e..??€.....?????.?..?TAM?

                                                                                            // end align 128

                                                                                            0x0860A000  de 3a 47 df c8 e1 a0 65 97 bd 58 f2 b7 eb 1b aa 72 4d 3a 37 b8 00 00 00 00 00 00 00 00 00 00 00  ?:G????e??X???.?rM:7?...........

                                                                                             

                                                                                            original data size 171989 , so i make 172000 to do align,


                                                                                            Where is my mistake?

                                                                                            Please.

                                                                                        • Re: How to fill H264_picture_parameter_2 structure
                                                                                          lk_amd

                                                                                          Hi, Aymeric,

                                                                                               Thanks !   Bad news, But I will keep trying .   I will post here if make any progress.

                                                                                           

                                                                                          Hi, himanshu.gautamAny suggestions ?

                                                                                  • Re: How to fill H264_picture_parameter_2 structure
                                                                                    xushan

                                                                                    I use ffmpeg to parse the PPS and SPS,then fill picture parameter.Now I can decode baseline profile,but have problems with decoding high profile.Could you provide high profile bit files which can be decoded using the OVDecodeRender?Or could you use your internal h264 parser to convert my h264 file to bit files?

                                                                    • Re: How to fill H264_picture_parameter_2 structure
                                                                      lk_amd

                                                                      HI,  I change my test file to 1 silce per frame,

                                                                      then I P slice works fine,

                                                                      but B slice frame failed with noise yuv ?

                                                                      Any lucky to make one slice B frme work?

                                                                      Thanks