GNOME Bugzilla – Bug 766832
encoder: Add CBR and VBR support in VP9
Last modified: 2017-06-07 15:42:27 UTC
Add Constant Bit Rate and Variable Bit Rate mode encoding support for vp9 encoder. Driver patches are here: https://lists.freedesktop.org/archives/libva/2016-May/003987.html
Initial implementation here: https://cgit.freedesktop.org/~sree/gstreamer-vaapi/commit/?h=vp9_enc_cbr&id=e1a4f29a0487341f5c6841e31c286d9ba5e87a89
Created attachment 352505 [details] [review] libs: encoder: vp9: Adds CBR and VBR Encoding support Just rebased Sree's commit and added a bit. (Added HRD and FrameRate)
Created attachment 352508 [details] [review] libs: encoder: vp9: Adds CBR and VBR Encoding support
Review of attachment 352508 [details] [review]: ::: gst-libs/gst/vaapi/gstvaapiencoder_vp9.c @@ +310,3 @@ + memset (rate_control, 0, sizeof (VAEncMiscParameterRateControl)); + rate_control->bits_per_second = encoder->bitrate_bits; + rate_control->target_percentage = 70; same thing of the target_percentage as I mentioned in bug 778732 @@ +313,3 @@ + rate_control->window_size = encoder->cpb_length; + rate_control->initial_qp = encoder->yac_qi; + rate_control->min_qp = 1; /* Fixme: provide user control */ I not sure if 1 is a good "default". vp9enc uses 0. Also ffmpeg, if I understand correctly. @@ +314,3 @@ + rate_control->initial_qp = encoder->yac_qi; + rate_control->min_qp = 1; /* Fixme: provide user control */ + rate_control->basic_unit_size = 0; not required size memset is set to zero @@ +551,3 @@ encoder->sharpness_level = DEFAULT_SHARPNESS_LEVEL; encoder->yac_qi = DEFAULT_YAC_QINDEX; + encoder->bitrate_bits = 0; this is not needed since it is the default
(In reply to Víctor Manuel Jáquez Leal from comment #5) > Review of attachment 352508 [details] [review] [review]: > > @@ +313,3 @@ > + rate_control->window_size = encoder->cpb_length; > + rate_control->initial_qp = encoder->yac_qi; > + rate_control->min_qp = 1; /* Fixme: provide user control */ > > I not sure if 1 is a good "default". vp9enc uses 0. Also ffmpeg, if I > understand correctly. > It's ok to set 0 as default. But I doubt even driver is handling this parameter for VP8/VP9 encoding, especially for CBR/VBR. As you said, bitrate and target percentage is important in this case. Sree may know about this in detail :)
Created attachment 353045 [details] [review] libs: encoder: vp9: Adds CBR and VBR Encoding support This is Sree's patch originally. I rebased and modified a bit.
Quick note: Fractional fps should be submitting like this: /* * The framerate is specified as a number of frames per second, as a * fraction. The denominator of the fraction is given in the top half * (the high two bytes) of the framerate field, and the numerator is * given in the bottom half (the low two bytes). * * That is: * denominator = framerate >> 16 & 0xffff; * numerator = framerate & 0xffff; * fps = numerator / denominator; * * For example, if framerate is set to (100 << 16 | 750), this is * 750 / 100, hence 7.5fps. * * If the denominator is zero (the high two bytes are both zero) then * it takes the value one instead, so the framerate is just the integer * in the low 2 bytes. */
(In reply to sreerenj from comment #8) > Quick note: > Fractional fps should be submitting like this: > /* > * The framerate is specified as a number of frames per second, as a > * fraction. The denominator of the fraction is given in the top half > * (the high two bytes) of the framerate field, and the numerator is > * given in the bottom half (the low two bytes). > * > * That is: > * denominator = framerate >> 16 & 0xffff; > * numerator = framerate & 0xffff; > * fps = numerator / denominator; > * > * For example, if framerate is set to (100 << 16 | 750), this is > * 750 / 100, hence 7.5fps. > * > * If the denominator is zero (the high two bytes are both zero) then > * it takes the value one instead, so the framerate is just the integer > * in the low 2 bytes. > */ Thanks for information! I should be working on this.
Created attachment 353055 [details] [review] libs: encoder: vp9: Adds CBR and VBR Encoding support
Created attachment 353058 [details] [review] libs: encoder: vp9: Adds CBR and VBR Encoding support
(In reply to Hyunjun Ko from comment #6) > (In reply to Víctor Manuel Jáquez Leal from comment #5) > > Review of attachment 352508 [details] [review] [review] [review]: > > > > @@ +313,3 @@ > > + rate_control->window_size = encoder->cpb_length; > > + rate_control->initial_qp = encoder->yac_qi; > > + rate_control->min_qp = 1; /* Fixme: provide user control */ > > > > I not sure if 1 is a good "default". vp9enc uses 0. Also ffmpeg, if I > > understand correctly. > > > > It's ok to set 0 as default. But I doubt even driver is handling this > parameter for VP8/VP9 encoding, especially for CBR/VBR. > As you said, bitrate and target percentage is important in this case. > Sree may know about this in detail :) BRC in vp9 encoder using intial_buffer_fullness and buffer_size (from HRD),target_percentage, window_size and bitrate (from RateControl) and framerate(from Framerate). No usage of initial_qp and min_qp in driver brc code.
Created attachment 353297 [details] [review] libs: encoder: vp9: Adds CBR and VBR Encoding support https://bugzilla.gnome.org/show_bug.cgi?id=766832 Signed-off-by: Víctor Manuel Jáquez Leal <vjaquez@igalia.com>
Created attachment 353307 [details] [review] libs: encoder: vp9: Adds CBR and VBR Encoding support https://bugzilla.gnome.org/show_bug.cgi?id=766832 Signed-off-by: Hyunjun Ko <zzoon@igalia.com> Signed-off-by: Víctor Manuel Jáquez Leal <vjaquez@igalia.com>
Attachment 353307 [details] pushed as 4bf8ef7 - libs: encoder: vp9: Adds CBR and VBR Encoding support