Hi, everyone:<span lang="EN-US">&nbsp;</span>



<p class="MsoNormal" style="text-align: left;" align="left"><span lang="EN-US">I have some questions about vbv buffer update
in x264. The specification said that it is the data with the access units that
flow into the CPB. The data include not only the coded frame size but also all
the other NAL units flow into the CPB. <br></span></p>







<p class="MsoNormal" style="text-align: left;" align="left"><span lang="EN-US">Bellows are from h264 specification:</span><br><span style="font-size: 10pt; font-family: TimesNewRoman;" lang="EN-US">"The HRD
operates as follows. <span style="color: red;">Data associated with access units
that flow into the CPB according to a specified arrival schedule are delivered
by the HSS. </span>¡­¡­"</span><br><b><span style="font-size: 10pt; font-family: &quot;TimesNewRoman,Bold&quot;;" lang="EN-US">"access unit</span></b><span style="font-size: 10pt; font-family: TimesNewRoman;" lang="EN-US">
: A set of </span><i><span style="font-size: 10pt; font-family: &quot;TimesNewRoman,Italic&quot;;" lang="EN-US">NAL units </span></i><span style="font-size: 10pt; font-family: TimesNewRoman;" lang="EN-US">always containing exactly one 
</span><i><span style="font-size: 10pt; font-family: &quot;TimesNewRoman,Italic&quot;;" lang="EN-US">primary coded picture</span></i><span style="font-size: 10pt; font-family: TimesNewRoman;" lang="EN-US">. <span style="color: red;">
In addition to</span> the </span><i><span style="font-size: 10pt; font-family: &quot;TimesNewRoman,Italic&quot;;" lang="EN-US">primary
coded picture</span></i><span style="font-size: 10pt; font-family: TimesNewRoman;" lang="EN-US">, an
access unit may <span style="color: red;">also contain </span>one or more </span><i><span style="font-size: 10pt; font-family: &quot;TimesNewRoman,Italic&quot;;" lang="EN-US">redundant
coded pictures<span style="color: red;"> </span></span></i><span style="font-size: 10pt; font-family: TimesNewRoman; color: red;" lang="EN-US">or </span><span style="font-size: 10pt; font-family: TimesNewRoman;" lang="EN-US">
other </span><i><span style="font-size: 10pt; font-family: &quot;TimesNewRoman,Italic&quot;;" lang="EN-US">NAL units </span></i><span style="font-size: 10pt; font-family: TimesNewRoman;" lang="EN-US">not containing </span>
<i><span style="font-size: 10pt; font-family: &quot;TimesNewRoman,Italic&quot;;" lang="EN-US">slices </span></i><span style="font-size: 10pt; font-family: TimesNewRoman;" lang="EN-US">or </span><i><span style="font-size: 10pt; font-family: &quot;TimesNewRoman,Italic&quot;;" lang="EN-US">
slice data partitions </span></i><span style="font-size: 10pt; font-family: TimesNewRoman;" lang="EN-US">of a </span><i><span style="font-size: 10pt; font-family: &quot;TimesNewRoman,Italic&quot;;" lang="EN-US">coded picture
</span></i><span style="font-size: 10pt; font-family: TimesNewRoman;" lang="EN-US">. The decoding of an access unit always results
in a </span><i><span style="font-size: 10pt; font-family: &quot;TimesNewRoman,Italic&quot;;" lang="EN-US">decoded
picture</span></i><span style="font-size: 10pt; font-family: TimesNewRoman;" lang="EN-US">." <br></span></p>



<p class="MsoNormal"><span lang="EN-US">So I think the function "update_vbv" has
some bugs. The parameter "bits" should be equal to the total bits in the "h-&gt;out.nal[X264_NAL_MAX]".
Such as bellows:</span></p><p class="MsoNormal"><span lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>for(nNalLoop=0;
nNalLoop&lt;X264_NAL_MAX; nNalLoop++)</span></p>

<p class="MsoNormal"><span lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</span></p>

<p class="MsoNormal"><span lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>if(h-&gt;out.nal[nNalLoop].i_type
&gt; 0)</span></p>

<p class="MsoNormal" style="text-align: left;" align="left"><span lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>nRealBits
+= h-&gt;out.nal[nNalLoop].i_payload + 5;</span></p>

<p class="MsoNormal"><span lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</span></p>

<p class="MsoNormal"><span lang="EN-US"><span style="">&nbsp;&nbsp;&nbsp;
</span>rcc-&gt;buffer_fill += rcc-&gt;buffer_rate - nRealBits*8;</span></p>

<p class="MsoNormal" style="text-align: left;" align="left"><span lang="EN-US">The number 5 is that 4 bytes "start_code_prefix"
add 1 byte "nal_unit_start". i.e.<span style="">&nbsp; </span>"00 00 00 01 65".
</span></p>



<p class="MsoNormal"><span lang="EN-US">At the same time the "h-&gt;out.nal[nNalLoop].i_type"
should be set as zero at the begin of the function "x264_encoder_encode" to
avoid the influence of last frame. <br></span></p>



<p class="MsoNormal"><span lang="EN-US">I want to know my idea is right. Give me
some advice please. <br></span></p>

<p class="MsoNormal"><span lang="EN-US">Best wishes,</span></p><p class="MsoNormal"><span lang="EN-US"></span><span style="font-size: 10.5pt; font-family: &quot;Times New Roman&quot;;" lang="EN-US">Alexander tian</span></p>