<div dir="ltr"><div><div><div>Hi,<br><br></div>Yes its constant bit-rate control, that work better that existing for me. I realize it's inside avcenc.c . <span lang="en"><span>I have not</span> <span>delved into driver sources, so</span></span><span lang="en"><span> may be worth</span> <span>to do something</span> <span>like</span> <span>that in driver.<br>
<br></span></span></div><span lang="en"><span>Best Regards,<br></span></span></div><span lang="en"><span>Warp.</span></span></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Aug 21, 2014 at 4:48 AM, Zhao, Yakui <span dir="ltr"><<a href="mailto:yakui.zhao@intel.com" target="_blank">yakui.zhao@intel.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Wed, 2014-08-20 at 16:38 +0400, Alexey wrote:<br>
> Hi all,<br>
><br>
><br>
<br>
Hi, Alexey<br>
<br>
What is the purpose of your patch? I guees that it is for the<br>
Bit-rate control?<br>
<br>
If it is for constant bit-rate control, I don't think that it is<br>
necessary to put it in the avcenc test-case as the constant bit-rate<br>
control is done in low-level driver. Maybe it looks more reasonable that<br>
it is put into the driver.<br>
<br>
Thanks.<br>
<span class="HOEnZb"><font color="#888888"> Yakui<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
> I decided that problem with small modify avcenc.c . After each encoded<br>
> frame i do :<br>
><br>
> enc->needsize = ( enc->frame_bit_rate * 1024 ) / 8;<br>
> if ( *outlen ) {<br>
> float o = (float)( (float)*outlen) / ( (float)enc->needsize /<br>
> (float)enc->fps );<br>
> if ( o > 1.0f ) {<br>
> enc->slice_qp_delta_next += 2;<br>
> } else if ( o < 0.9f ){<br>
> enc->slice_qp_delta_next--;<br>
> }<br>
> if ( enc->slice_qp_delta_next < -33 ) enc->slice_qp_delta_next =<br>
> -33;<br>
> if ( enc->slice_qp_delta_next > 17 ) enc->slice_qp_delta_next =<br>
> 17;<br>
> }<br>
><br>
><br>
> *outlen its size of current encoded frame.<br>
><br>
><br>
><br>
> And in void avcenc_update_slice_parameter(struct h264_vaapi_enc *enc,<br>
> int slice_type) i set slice_param->slice_qp_delta =<br>
> enc->slice_qp_delta;<br>
><br>
><br>
> Initial qp value enc->qp_value = 33;<br>
><br>
><br>
><br>
> Best Regards,<br>
><br>
> Warp.<br>
><br>
><br>
><br>
> On Tue, Aug 19, 2014 at 7:09 PM, Chris Healy <<a href="mailto:cphealy@gmail.com">cphealy@gmail.com</a>><br>
> wrote:<br>
> Hi Zhao,<br>
><br>
><br>
> Thanks for pointing out the QP adjustment logic. I made the<br>
> (bad) assumption previously that it would be in gen7_mfc.c.<br>
><br>
> I will file a bug and make a YUV stream available in the<br>
> coming days.<br>
><br>
> Thanks,<br>
><br>
><br>
> Chris<br>
><br>
><br>
><br>
> On Mon, Aug 18, 2014 at 6:03 PM, Zhao, Yakui<br>
> <<a href="mailto:yakui.zhao@intel.com">yakui.zhao@intel.com</a>> wrote:<br>
> On Mon, 2014-08-18 at 11:19 -0600, Chris Healy wrote:<br>
> > Well after taking a look at the behaviour again this<br>
> morning, (it was<br>
> > real late for me last night), it does seem that this<br>
> change did not<br>
> > solve the issue. I'm still seeing the same<br>
> inconsistent frame rate.<br>
> ><br>
> > The encoder still seems to be trying to average<br>
> things over a 20<br>
> > second window.<br>
> ><br>
> ><br>
> > Where is the code that implements the per frame<br>
> adjustment of the QP?<br>
> > avcenc.c seems to just be responsible for setting up<br>
> some encoder<br>
> > preferences but does not do any dynamic QP<br>
> adjustment. Also, how can<br>
> > I enable some debugging to see what the QP is set to<br>
> for each frame?<br>
> ><br>
> ><br>
><br>
><br>
> Hi, Chris<br>
><br>
> The QP adjustment is implemented in the function<br>
> of<br>
> intel_mfc_brc_postpack in gen6_mfc_common.c. (Sorry<br>
> that there is no<br>
> debug option to control whether the QP is printed for<br>
> every frame. You<br>
> can print the corresponding QP).<br>
><br>
> Will you please help to create one bug in<br>
> <a href="https://bugs.freedesktop.org/" target="_blank">https://bugs.freedesktop.org/</a> and then attach your<br>
> original YUV stream?<br>
> Then we can look at the issue.<br>
><br>
> Thanks.<br>
> Yakui<br>
> ><br>
> ><br>
> > On Mon, Aug 18, 2014 at 6:27 AM, Gwenole Beauchesne<br>
> > <<a href="mailto:gb.devel@gmail.com">gb.devel@gmail.com</a>> wrote:<br>
> > Hi Chris,<br>
> ><br>
> > 2014-08-18 11:55 GMT+02:00 Chris Healy<br>
> <<a href="mailto:cphealy@gmail.com">cphealy@gmail.com</a>>:<br>
> > > Hi Zhao,<br>
> > ><br>
> > > I just tested the new values you gave me.<br>
> This is a night<br>
> > and day<br>
> > > improvement in bitrate consistency. Based<br>
> on the small<br>
> > amount of testing I<br>
> > > have done, this seems to completely<br>
> address the problem!<br>
> > ><br>
> > > I have to understand why moving from 15<br>
> and 900 to 1 and 60<br>
> > makes the<br>
> > > bitrate so consistent. Both pairs of<br>
> values are the same so<br>
> > given the<br>
> > > following comment: /* Tc =<br>
> num_units_in_tick / time_sacle<br>
> > */ I have the<br>
> > > same Tc in both cases.<br>
> ><br>
> ><br>
> > This should make zero difference. If it<br>
> does, there should<br>
> > some arith<br>
> > error around, that needs to be investigated.<br>
> 900/15 or 60/1<br>
> > still<br>
> > yield 30 fps.<br>
> ><br>
> > Note: a tick is the minimum time slice that<br>
> can be represented<br>
> > in the<br>
> > coded data. Typically, a field. time_scale<br>
> is the frequency.<br>
> ><br>
> > > How is this changing things for the better<br>
> AND, what is the<br>
> > tradeoff in<br>
> > > using these values. (There must be some<br>
> downside otherwise<br>
> > these values<br>
> > > would have always been 1 and 2 * fps.)<br>
> > ><br>
> > > Regards,<br>
> > ><br>
> > > Chris<br>
> > ><br>
> > > (PS - Thank you!)<br>
> > ><br>
> > ><br>
> > > On Mon, Aug 18, 2014 at 1:36 AM, Chris<br>
> Healy<br>
> > <<a href="mailto:cphealy@gmail.com">cphealy@gmail.com</a>> wrote:<br>
> > >><br>
> > >> Hi Zhao,<br>
> > >><br>
> > >> I've done testing with both 30 and 24 fps<br>
> and received<br>
> > similar results.<br>
> > >><br>
> > >> I will test with the values you<br>
> mentioned. Can you explain<br>
> > how<br>
> > >> num_units_in_tick and time_scale work?<br>
> (What is a tick?)<br>
> > >><br>
> > >> Also, is there a good place in the Intel<br>
> driver to dump the<br>
> > QP value used<br>
> > >> for each frame? I'd like to add some QP<br>
> logging when an<br>
> > env variable is<br>
> > >> set.<br>
> > >><br>
> > >> Regards,<br>
> > >><br>
> > >> Chris<br>
> > >><br>
> > >><br>
> > >> On Mon, Aug 18, 2014 at 1:30 AM, Zhao,<br>
> Yakui<br>
> > <<a href="mailto:yakui.zhao@intel.com">yakui.zhao@intel.com</a>> wrote:<br>
> > >>><br>
> > >>> On Mon, 2014-08-18 at 01:13 -0600, Chris<br>
> Healy wrote:<br>
> > >>> > Hi Zhao,<br>
> > >>> ><br>
> > >>> ><br>
> > >>> > I enabled LIBVA_TRACE recently and<br>
> grabbed a bunch of<br>
> > output. Here's<br>
> > >>> > a link to good size fragment of the<br>
> output:<br>
> > >>> ><br>
> > >>> > <a href="http://pastebin.com/KJYzGQAA" target="_blank">http://pastebin.com/KJYzGQAA</a><br>
> > >>> ><br>
> > >>> ><br>
> > >>> > Here's answers to the specific<br>
> questions you asked:<br>
> > (From LIBVA_TRACE<br>
> > >>> > output)<br>
> > >>> ><br>
> > >>> > [57113.237423] intra_period = 30<br>
> > >>> > [57113.237424] intra_idr_period = 30<br>
> > >>> > [57113.237425] ip_period = 1<br>
> > >>> > [57113.237427] bits_per_second =<br>
> 3700000<br>
> > >>> > [57113.237428] max_num_ref_frames = 2<br>
> > >>> > [57113.237469] num_units_in_tick = 15<br>
> > >>> > [57113.237470] time_scale = 900<br>
> > >>><br>
> > >>> If the expected fps is 24, the setting<br>
> of<br>
> > num_units_in_tick/time_scale<br>
> > >>> is incorrect. It will be better that you<br>
> should use the<br>
> > following<br>
> > >>> setting in your tool:<br>
> > >>> num_units_in_tick = 1<br>
> > >>> time_scale = 2 * fps<br>
> > >>><br>
> > >>><br>
> > >>><br>
> > >>> ><br>
> > >>> > I see avenc.c, but it's unclear to me<br>
> if I am dealing<br>
> > with an issue<br>
> > >>> > with the encoder application or<br>
> something lower down in<br>
> > libva or<br>
> > >>> > libva-driver-intel or the HW itself.<br>
> > >>> ><br>
> > >>> ><br>
> > >>> > Am I correct in believing (simplified)<br>
> that the HW is<br>
> > just given a raw<br>
> > >>> > video frame and a QP and the HW<br>
> returns a chunk of<br>
> > encoded data that<br>
> > >>> > is "some size" and that it is the<br>
> responsibility of the<br>
> > SW above the<br>
> > >>> > HW to dynamically adjust the QP to hit<br>
> the target<br>
> > bitrate to meet<br>
> > >>> > whatever the rate control algorithm<br>
> deems correct?<br>
> > >>> ><br>
> > >>><br>
> > >>> When the CBR mode is used, the driver<br>
> will adjust QP<br>
> > dynamically so that<br>
> > >>> the encoded bitrate can meet with the<br>
> requirement of<br>
> > target bitrate<br>
> > >>> based on the input encoding<br>
> parameter(For example:<br>
> > intra_period,<br>
> > >>> ip_period, time_scale, num_units_in_tick<br>
> and so on).<br>
> > >>><br>
> > >>><br>
> > >>> > If this is the case, where is the code<br>
> that is<br>
> > dynamically adjusting<br>
> > >>> > the QP? Also, in the HW, where are<br>
> the registers and<br>
> > bits control the<br>
> > >>> > QP? (I'm looking at the "Intel ®<br>
> OpenSource HD Graphics<br>
> > Programmer’s<br>
> > >>> > Reference Manual (PRM) Volume 2 Part<br>
> 3: Multi-Format<br>
> > Transcoder – MFX<br>
> > >>> > (Ivy Bridge)" so a reference to the<br>
> registers might be<br>
> > helpful for me<br>
> > >>> > to understand better.)<br>
> > >>> ><br>
> > >>> ><br>
> > >>> > Regards,<br>
> > >>> ><br>
> > >>> > Chris<br>
> > >>> ><br>
> > >>> ><br>
> > >>> ><br>
> > >>> > On Sun, Aug 17, 2014 at 11:58 PM,<br>
> Zhao, Yakui<br>
> > <<a href="mailto:yakui.zhao@intel.com">yakui.zhao@intel.com</a>><br>
> > >>> > wrote:<br>
> > >>> > On Sun, 2014-08-17 at 19:27<br>
> -0600, Chris Healy<br>
> > wrote:<br>
> > >>> > > I've done some further<br>
> analysis with our real<br>
> > stream and we<br>
> > >>> > experience<br>
> > >>> > > the same inconsistent<br>
> bitrate behaviour as<br>
> > with the test<br>
> > >>> > app. It<br>
> > >>> > > seems to me that the way the<br>
> bitrate control<br>
> > works doesn't<br>
> > >>> > do a good<br>
> > >>> > > job of handling certain<br>
> input video sequences<br>
> > and the<br>
> > >>> > encoded bitrate<br>
> > >>> > > subsequently spikes as a<br>
> result of this.<br>
> > >>> > ><br>
> > >>> > > To help understand what I'm<br>
> dealing with, I've<br>
> > posted a<br>
> > >>> > video on<br>
> > >>> > > youtube showing the video<br>
> being encoded:<br>
> > >>> > ><br>
> > >>> > ><br>
> <a href="http://www.youtube.com/watch?v=LpYS_9IB0jU" target="_blank">www.youtube.com/watch?v=LpYS_9IB0jU</a><br>
> > >>> > ><br>
> > >>> > ><br>
> > >>> > > I've also posted a bitrate<br>
> graph online too<br>
> > that shows what<br>
> > >>> > happens<br>
> > >>> > > when encoding the video<br>
> referenced above:<br>
> > >>> > ><br>
> > >>> > > <a href="http://snag.gy/imvBe.jpg" target="_blank">http://snag.gy/imvBe.jpg</a><br>
> > >>> > ><br>
> > >>> > ><br>
> > >>> > > In the above graph, I set<br>
> the targeted encode<br>
> > bitrate to<br>
> > >>> > 3.7Mbps, CBR,<br>
> > >>> > > and High Profile H.264.<br>
> Most of the time the<br>
> > bitrate hovers<br>
> > >>> > around<br>
> > >>> > > 3.7Mbps, but sometimes the<br>
> bitrate drops very<br>
> > low then<br>
> > >>> > spikes up very<br>
> > >>> > > high. I also notice that<br>
> when the bitrate<br>
> > drops down low<br>
> > >>> > then spikes<br>
> > >>> > > up real high, the "highness"<br>
> seems to be a<br>
> > function of how<br>
> > >>> > much and<br>
> > >>> > > long the bitrate was under<br>
> 3.7Mbps. It seems<br>
> > that the rate<br>
> > >>> > control<br>
> > >>> > > logic is taking a 20 second<br>
> running bitrate<br>
> > average and<br>
> > >>> > trying it's<br>
> > >>> > > best to keep the aggregate<br>
> bitrate at 3.7Mbps,<br>
> > so if the<br>
> > >>> > scene<br>
> > >>> > > complexity drops, the rate<br>
> control logic<br>
> > reacts by cranking<br>
> > >>> > the QP to<br>
> > >>> > > a very low value (high<br>
> quality) to bring the<br>
> > bitrate back<br>
> > >>> > up. This<br>
> > >>> > > behaviour combined with the<br>
> fact that the<br>
> > video goes to a<br>
> > >>> > simple fixed<br>
> > >>> > > image, then crossfades to<br>
> something complex in<br>
> > less than 20<br>
> > >>> > seconds<br>
> > >>> > > when the QP is a very low<br>
> value results in the<br>
> > massive spike<br>
> > >>> > in<br>
> > >>> > > bitrate. (This is my naive<br>
> understanding of<br>
> > what’s going<br>
> > >>> > on.)<br>
> > >>> > ><br>
> > >>> > > The code I'm using to encode<br>
> and stream is<br>
> > based in large<br>
> > >>> > part on<br>
> > >>> > ><br>
> libva/test/encode/h264encode.c. I'm not sure<br>
> > if the logic<br>
> > >>> > for doing<br>
> > >>> > > rate control is in libva,<br>
> libva-driver-intel,<br>
> > or supposed to<br>
> > >>> > be driven<br>
> > >>> > > by the code that uses libva.<br>
> Am I dealing<br>
> > with an issue<br>
> > >>> > with the<br>
> > >>> > > encoder itself or is it more<br>
> likely my code<br>
> > not correctly<br>
> > >>> > driving the<br>
> > >>> > > encoder?<br>
> > >>> ><br>
> > >>> ><br>
> > >>> > Hi, Chris<br>
> > >>> ><br>
> > >>> > Thank you for reporting<br>
> the issue.<br>
> > >>> > Will you please check the<br>
> encoding<br>
> > parameters required by<br>
> > >>> > CBR? (For<br>
> > >>> > example:<br>
> intra_period/ip_period/<br>
> > >>> ><br>
> num_units_in_tick/time_scale/bits_per_second in<br>
> > >>> ><br>
> VAEncSequenceParameterBufferH264.)<br>
> > >>> ><br>
> > >>> > Will you please take a<br>
> look at the example<br>
> > of<br>
> > >>> > libva/test/encode/avcenc.c and<br>
> see whether it is<br>
> > helpful?<br>
> > >>> > (There exist two h264 encoding<br>
> examples because<br>
> > of history<br>
> > >>> > reasons. The<br>
> > >>> > avcenc case is more consistent<br>
> with the<br>
> > libva-intel-driver.)<br>
> > >>> ><br>
> > >>> > Thanks.<br>
> > >>> > Yakui<br>
> > >>> ><br>
> > >>> > > What can be changed to keep<br>
> the actual bitrate<br>
> > from being so<br>
> > >>> > bursty<br>
> > >>> > > given the video behaviour?<br>
> > >>> > ><br>
> > >>> > ><br>
> > >>> > > Regards,<br>
> > >>> > ><br>
> > >>> > > Chris<br>
> > >>> > ><br>
> > >>> > ><br>
> > >>> > ><br>
> > >>> > ><br>
> > >>> > ><br>
> > >>> > ><br>
> > >>> > ><br>
> > >>> > ><br>
> > >>> > ><br>
> > >>> > > On Fri, Aug 15, 2014 at 6:03<br>
> PM, Chris Healy<br>
> > >>> > <<a href="mailto:cphealy@gmail.com">cphealy@gmail.com</a>><br>
> > >>> > > wrote:<br>
> > >>> > > I've been encoding<br>
> h264 content using<br>
> > HD 4000 HW and<br>
> > >>> > am not<br>
> > >>> > > able to make heads<br>
> or tails of the way<br>
> > the encoder<br>
> > >>> > is behaving<br>
> > >>> > > from the standpoint<br>
> of the data size<br>
> > coming out of<br>
> > >>> > the<br>
> > >>> > > encoder.<br>
> > >>> > ><br>
> > >>> > > I have a 24 fps 720p<br>
> video that is the<br>
> > same image<br>
> > >>> > for ~8<br>
> > >>> > > seconds, then a 1.5<br>
> second fade to the<br>
> > next image<br>
> > >>> > followed by<br>
> > >>> > > another ~8 seconds<br>
> on that image.<br>
> > This goes on and<br>
> > >>> > on<br>
> > >>> > > indefinitely. I<br>
> would have expected<br>
> > that the<br>
> > >>> > bitrate would<br>
> > >>> > > have been pretty<br>
> low, then spike for<br>
> > 1.5 seconds<br>
> > >>> > then go back<br>
> > >>> > > to a similarly low<br>
> value.<br>
> > >>> > ><br>
> > >>> > ><br>
> > >>> > > When I look at the<br>
> data coming out of<br>
> > the encoder<br>
> > >>> > with a 4Mb/s<br>
> > >>> > > bitrate set and CBR,<br>
> I'm seeing almost<br>
> > the inverse<br>
> > >>> > where most<br>
> > >>> > > of the time, the<br>
> bitrate is pretty<br>
> > close to 4Mb/s<br>
> > >>> > then it<br>
> > >>> > > spikes above 4Mb/s<br>
> (presumably for the<br>
> > fade), then<br>
> > >>> > it drops<br>
> > >>> > > down to ~2Mbps for a<br>
> second or so<br>
> > before going back<br>
> > >>> > up to<br>
> > >>> > > ~4Mb/s.<br>
> > >>> > ><br>
> > >>> > > The strangest part<br>
> is that for the<br>
> > first ~30 seconds<br>
> > >>> > of<br>
> > >>> > > encode, across the<br>
> board, the bitrate<br>
> > is ~2x the<br>
> > >>> > bitrate from<br>
> > >>> > > second 31 -> end of<br>
> encode. (So, I'm<br>
> > hitting a<br>
> > >>> > typical rate<br>
> > >>> > > of 7Mbps and peaking<br>
> out at 13Mbps.)<br>
> > >>> > ><br>
> > >>> > ><br>
> > >>> > > Is this behaviour<br>
> expected with gen7<br>
> > HW? Is there<br>
> > >>> > something I<br>
> > >>> > > can do in the<br>
> initial setup that will<br>
> > cap the MAX<br>
> > >>> > bitrate<br>
> > >>> > > regardless of the<br>
> impact on encode<br>
> > quality?<br>
> > >>> > ><br>
> > >>> > > Regards,<br>
> > >>> > ><br>
> > >>> > > Chris<br>
> > >>> > ><br>
> > >>> > ><br>
> > >>> > ><br>
> > >>> ><br>
> > >>> ><br>
> > >>> ><br>
> > >>> ><br>
> > >>> ><br>
> > >>><br>
> > >>><br>
> > >><br>
> > ><br>
> > ><br>
> ><br>
> > ><br>
> _______________________________________________<br>
> > > Libva mailing list<br>
> > > <a href="mailto:Libva@lists.freedesktop.org">Libva@lists.freedesktop.org</a><br>
> > ><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/libva" target="_blank">http://lists.freedesktop.org/mailman/listinfo/libva</a><br>
> > ><br>
> ><br>
> ><br>
> > Regards,<br>
> > --<br>
> > Gwenole Beauchesne<br>
> > Intel Corporation SAS / 2 rue de Paris,<br>
> 92196 Meudon Cedex,<br>
> > France<br>
> > Registration Number (RCS): Nanterre B 302<br>
> 456 199<br>
> ><br>
> ><br>
><br>
><br>
><br>
><br>
><br>
><br>
> _______________________________________________<br>
> Libva mailing list<br>
> <a href="mailto:Libva@lists.freedesktop.org">Libva@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/libva" target="_blank">http://lists.freedesktop.org/mailman/listinfo/libva</a><br>
><br>
><br>
><br>
> _______________________________________________<br>
> Libva mailing list<br>
> <a href="mailto:Libva@lists.freedesktop.org">Libva@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/libva" target="_blank">http://lists.freedesktop.org/mailman/listinfo/libva</a><br>
<br>
<br>
</div></div></blockquote></div><br></div>