After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 766832 - encoder: Add CBR and VBR support in VP9
encoder: Add CBR and VBR support in VP9
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer-vaapi
unspecified
Other Linux
: Normal enhancement
: 1.13.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on: 766048 783449
Blocks:
 
 
Reported: 2016-05-24 09:19 UTC by sreerenj
Modified: 2017-06-07 15:42 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
libs: encoder: vp9: Adds CBR and VBR Encoding support (8.24 KB, patch)
2017-05-24 14:13 UTC, Hyunjun Ko
none Details | Review
libs: encoder: vp9: Adds CBR and VBR Encoding support (8.24 KB, patch)
2017-05-24 14:17 UTC, Hyunjun Ko
none Details | Review
libs: encoder: vp9: Adds CBR and VBR Encoding support (8.17 KB, patch)
2017-06-02 04:55 UTC, Hyunjun Ko
none Details | Review
libs: encoder: vp9: Adds CBR and VBR Encoding support (8.15 KB, patch)
2017-06-02 09:13 UTC, Hyunjun Ko
none Details | Review
libs: encoder: vp9: Adds CBR and VBR Encoding support (8.17 KB, patch)
2017-06-02 09:17 UTC, Hyunjun Ko
none Details | Review
libs: encoder: vp9: Adds CBR and VBR Encoding support (7.85 KB, patch)
2017-06-07 08:43 UTC, Víctor Manuel Jáquez Leal
none Details | Review
libs: encoder: vp9: Adds CBR and VBR Encoding support (7.81 KB, patch)
2017-06-07 10:09 UTC, Víctor Manuel Jáquez Leal
committed Details | Review

Description sreerenj 2016-05-24 09:19:51 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
Comment 2 Hyunjun Ko 2017-05-24 14:13:09 UTC
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)
Comment 3 Hyunjun Ko 2017-05-24 14:17:21 UTC
Created attachment 352508 [details] [review]
libs: encoder: vp9: Adds CBR and VBR Encoding support
Comment 4 Víctor Manuel Jáquez Leal 2017-05-31 14:57:48 UTC
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
Comment 5 Víctor Manuel Jáquez Leal 2017-05-31 14:57:49 UTC
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
Comment 6 Hyunjun Ko 2017-06-01 09:21:46 UTC
(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 :)
Comment 7 Hyunjun Ko 2017-06-02 04:55:59 UTC
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.
Comment 8 sreerenj 2017-06-02 06:29:02 UTC
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.
     */
Comment 9 Hyunjun Ko 2017-06-02 08:43:39 UTC
(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.
Comment 10 Hyunjun Ko 2017-06-02 09:13:58 UTC
Created attachment 353055 [details] [review]
libs: encoder: vp9: Adds CBR and VBR Encoding support
Comment 11 Hyunjun Ko 2017-06-02 09:17:35 UTC
Created attachment 353058 [details] [review]
libs: encoder: vp9: Adds CBR and VBR Encoding support
Comment 12 sreerenj 2017-06-02 20:53:03 UTC
(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.
Comment 13 Víctor Manuel Jáquez Leal 2017-06-07 08:43:18 UTC
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>
Comment 14 Víctor Manuel Jáquez Leal 2017-06-07 10:09:02 UTC
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>
Comment 15 Víctor Manuel Jáquez Leal 2017-06-07 15:40:31 UTC
Attachment 353307 [details] pushed as 4bf8ef7 - libs: encoder: vp9: Adds CBR and VBR Encoding support