<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Problem with H.264 encoder when using SLICE_CHECK_LIMIT in Intel® Integrated Performance Primitives</title>
    <link>https://community.intel.com/t5/Intel-Integrated-Performance/Problem-with-H-264-encoder-when-using-SLICE-CHECK-LIMIT/m-p/892009#M11623</link>
    <description>&lt;DIV style="margin: 0px; height: auto;"&gt;&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;I guess I solved my own problems ;)&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;There is indeed a bug in the state of CABAC in that mode.&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;When hitting the condition where the last macro block need to be rolled back, the Cabac stream need to be restored to where it was last save but the end_of_slice_flag should not be set right away(it will be set a little later shortly before exiting the compress_slice function).&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;Moreover, the state of the CABAC stream should not be saved again (we are going to terminate the stream right away).&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;Emmanuel&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Dec 2008 13:17:57 GMT</pubDate>
    <dc:creator>Emmanuel_W_</dc:creator>
    <dc:date>2008-12-05T13:17:57Z</dc:date>
    <item>
      <title>Problem with H.264 encoder when using SLICE_CHECK_LIMIT</title>
      <link>https://community.intel.com/t5/Intel-Integrated-Performance/Problem-with-H-264-encoder-when-using-SLICE-CHECK-LIMIT/m-p/892007#M11621</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Sorry I am reposting my finding because somehow I manage to delete my thread.&lt;/P&gt;
&lt;P&gt;I have found I believe two issues with the latest H.264 encoder (6.0) and specifying a maximum slice size (and using the preprocessor SLICE_CHECK_LIMIT).&lt;/P&gt;
&lt;P&gt;The first one is when rolling back the last macro block when the slice exceed the maximum allowed size. In that scenario two variables &lt;SPAN style="font-size: x-small;"&gt;m_iLastXmittedQP &lt;SPAN style="font-size: xx-small;"&gt;and &lt;SPAN style="font-size: x-small;"&gt;m_uSkipRun &lt;SPAN style="font-size: xx-small;"&gt;don't seem to be reset correctly. &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN style="font-size: xx-small;"&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN style="font-size: xx-small;"&gt;A proposed fix is as follow in umc_h_core_enc_templ.cpp.h line 900&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: x-small;"&gt;&lt;SPAN style="font-size: xx-small;"&gt;&lt;SPAN style="font-size: x-small;"&gt;
&lt;PRE&gt;[cpp]#ifdef SLICE_CHECK_LIMIT
        Ipp32s size = (H264BsBase_GetBsOffset(&amp;amp;pBitstream-&amp;gt;m_base) &amp;gt;&amp;gt; 3) + 3/*Start code*/ + 5;
        if (core_enc-&amp;gt;m_MaxSliceSize &amp;amp;&amp;amp; core_enc-&amp;gt;m_MaxSliceSize &amp;lt; (Ipp32u)size){
            //Increase slice_id
            for (Ipp32u mb = uMB; mb &amp;lt; uFirstMB + uNumMBs; mb++) core_enc-&amp;gt;m_pCurrentFrame-&amp;gt;m_mbinfo.mbs[mb].slice_id++;
            curr_slice-&amp;gt;m_MB_Counter--;
			curr_slice-&amp;gt;m_iLastXmittedQP = iLastQP;		// Restore the last xmitted QP
            curr_slice-&amp;gt;m_uSkipRun = uSaved_Skip_Run;	// Restore the last skipRun

            //Restore bitstream
            if (core_enc-&amp;gt;m_PicParamSet.entropy_coding_mode){
                H264ENC_MAKE_NAME(H264BsReal_RestoreCABACState)(pBitstream);
                H264ENC_MAKE_NAME(H264BsReal_EncodeFinalSingleBin_CABAC)(pBitstream, 1);
            }else{
                H264BsBase_SetState(&amp;amp;pBitstream-&amp;gt;m_base, pStartBits, uStartBitOffset);
                //Reset unused bits
                *pStartBits = *pStartBits &amp;amp; (0xff&amp;lt;&amp;lt;(8- uStartBitOffset));
            }
        }
#endif[/cpp]&lt;/PRE&gt;
&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The second issue leads to random crashes and a poorer encode quality. &lt;BR /&gt;Even though when specifying a maximum size for a slice the number of slice is set to 1, the slice_id parameter is incremented for the MBs as slices are beeing generated.&lt;/P&gt;
&lt;P&gt;Line 904 of umc_h264_gen_enc_tmpl.cpp.h&lt;/P&gt;
&lt;PRE&gt;[cpp]for (Ipp32u mb = uMB; mb &amp;lt; uFirstMB + uNumMBs; mb++) core_enc-&amp;gt;m_pCurrentFrame-&amp;gt;m_mbinfo.mbs[mb].slice_id++;[/cpp]&lt;/PRE&gt;
&lt;P&gt;
&lt;/P&gt;&lt;P&gt;Unfortunaltely, at least 2 spots in the code uses the slice_id to index into tables that have been allocated with num_slices elements.&lt;/P&gt;
&lt;P&gt;Line 654 of umc_h264_deblocking_tmpl.cpp.h&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;PRE&gt;[cpp]H264SliceType *curr_slice = &amp;amp;core_enc-&amp;gt;m_Slices[core_enc-&amp;gt;m_pCurrentFrame-&amp;gt;m_mbinfo.mbs[MBAddr].slice_id];[/cpp]&lt;/PRE&gt;
&lt;P&gt;Line 451 of umc_h264_enc_cpb_tmpl.h (called from many many places with slice_id as the first parameter)&lt;/P&gt;
&lt;PRE&gt;[cpp]inline
EncoderRefPicListStructType* H264ENC_MAKE_NAME(H264EncoderFrame_GetRefPicList)(
    H264EncoderFrameType* state,
    Ipp32s SliceNum,
    Ipp32s List)
{
    EncoderRefPicListStructType *pList;

    if (List == LIST_0)
        pList = &amp;amp;state-&amp;gt;m_pRefPicList[SliceNum].m_RefPicListL0;
    else
        pList = &amp;amp;state-&amp;gt;m_pRefPicList[SliceNum].m_RefPicListL1;

    return pList;

}[/cpp]&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;If I set the slice_id or SliceNum in those two spots to be 0 when in that particular mode, the encoding quality seems to be fine and I do not crash anymore but I am not sure this is the right way to fix the issue.&lt;/P&gt;
&lt;P&gt;Emmanuel&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Dec 2008 19:49:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Integrated-Performance/Problem-with-H-264-encoder-when-using-SLICE-CHECK-LIMIT/m-p/892007#M11621</guid>
      <dc:creator>Emmanuel_W_</dc:creator>
      <dc:date>2008-12-01T19:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with H.264 encoder when using SLICE_CHECK_LIMIT</title>
      <link>https://community.intel.com/t5/Intel-Integrated-Performance/Problem-with-H-264-encoder-when-using-SLICE-CHECK-LIMIT/m-p/892008#M11622</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
&lt;P&gt;There is also a problem when using CABAC and SLICE_CHECK_LIMIT at the same time, the state of the CABAC stream doesn't seem to be setup properly after generating a new slice causing a corrupted stream.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Dec 2008 12:19:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Integrated-Performance/Problem-with-H-264-encoder-when-using-SLICE-CHECK-LIMIT/m-p/892008#M11622</guid>
      <dc:creator>Emmanuel_W_</dc:creator>
      <dc:date>2008-12-05T12:19:38Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with H.264 encoder when using SLICE_CHECK_LIMIT</title>
      <link>https://community.intel.com/t5/Intel-Integrated-Performance/Problem-with-H-264-encoder-when-using-SLICE-CHECK-LIMIT/m-p/892009#M11623</link>
      <description>&lt;DIV style="margin: 0px; height: auto;"&gt;&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;I guess I solved my own problems ;)&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;There is indeed a bug in the state of CABAC in that mode.&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;When hitting the condition where the last macro block need to be rolled back, the Cabac stream need to be restored to where it was last save but the end_of_slice_flag should not be set right away(it will be set a little later shortly before exiting the compress_slice function).&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;Moreover, the state of the CABAC stream should not be saved again (we are going to terminate the stream right away).&lt;/DIV&gt;
&lt;DIV style="margin:0px;"&gt;Emmanuel&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Dec 2008 13:17:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Integrated-Performance/Problem-with-H-264-encoder-when-using-SLICE-CHECK-LIMIT/m-p/892009#M11623</guid>
      <dc:creator>Emmanuel_W_</dc:creator>
      <dc:date>2008-12-05T13:17:57Z</dc:date>
    </item>
  </channel>
</rss>

