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