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 791637 - msdk: encode: Add more tuning options
msdk: encode: Add more tuning options
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-bad
git master
Other Linux
: Normal enhancement
: 1.13.90
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks: 789886
 
 
Reported: 2017-12-15 00:24 UTC by sreerenj
Modified: 2018-06-22 14:34 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
msdk: encoder: register only the required properties (20.83 KB, patch)
2018-02-17 00:34 UTC, sreerenj
rejected Details | Review
msdk: encoder: h265: generalize the behavior of "i-frames" property (1.57 KB, patch)
2018-02-17 00:35 UTC, sreerenj
rejected Details | Review
msdk: encode: Add property to set slice/partitioning (3.66 KB, patch)
2018-02-17 00:35 UTC, sreerenj
rejected Details | Review
msdk: encode: Add more rate control options (11.82 KB, patch)
2018-02-17 00:36 UTC, sreerenj
rejected Details | Review
msdk: h264_enc: Add LookaheadDownsampling support (4.87 KB, patch)
2018-02-17 00:36 UTC, sreerenj
rejected Details | Review
msdk: encoder: h264: Enable trellis quantization tuning (4.53 KB, patch)
2018-02-17 00:37 UTC, sreerenj
rejected Details | Review
msdk: move enum definitions to separate file (12.48 KB, patch)
2018-02-17 00:37 UTC, sreerenj
rejected Details | Review
msdk: h264_enc: Add slice size tuning option (3.92 KB, patch)
2018-02-17 00:38 UTC, sreerenj
rejected Details | Review
msdk: Add more tuning options (10.11 KB, patch)
2018-02-17 00:38 UTC, sreerenj
rejected Details | Review
msdk: h264_enc: Enable B-pyramid prediction support (3.76 KB, patch)
2018-02-17 00:39 UTC, sreerenj
rejected Details | Review

Description sreerenj 2017-12-15 00:24:05 UTC
MediaSDK is providing a number of tuning options. It doesn't make sense to add all of them as properties, but we should still add some of the important ones.

I guess we need to change few of the property names in msdkXXXenc elements.
Currently we have three properties qp-i, qp-p and qp-b to set quant values for each frame type.

I would prefer either:

A)  qp, qp-ip and qp-ib (somewhat similar to gstremaer-vaapi , where qp-ip and qp-ib indicates the qp value difference (if there any) from i-frame)

B) qp, qp-p, qp-b (qp is the general quant value, qp-p and qp-b are for P and B frames)


For me, A seems to be clean. The user only need to set one qp value which is for I,P and B frames. Also there is no qp-i in JPEG encoder, so a generic "qp" is more preferred. 
Intelligent CQP BRC algorithm requires only one quantization value. So considering all these, I would go for option-A :)
Comment 1 sreerenj 2017-12-15 01:34:11 UTC
It seems qp-i/p/b can be zero in msdk which means "no limitation on QA". If that is the case, it could be better stick with qp-i/qp-p/qp-b than "qp-difference". Also, jpegenc need separate range (1 to 100). Sorry for the noise.
Comment 2 sreerenj 2017-12-22 02:06:19 UTC
I am adding the missing features and some code rearrange here:
https://github.com/sreerenjb/gst-plugins-bad/commits/devel

But maybe it is better to wait for patches from #790752 to land first because those are the core part of the plugins which is difficult to rebase.
Comment 3 sreerenj 2018-02-17 00:34:55 UTC
Created attachment 368453 [details] [review]
msdk: encoder: register only the required properties
Comment 4 sreerenj 2018-02-17 00:35:26 UTC
Created attachment 368454 [details] [review]
msdk: encoder: h265: generalize the behavior of "i-frames" property
Comment 5 sreerenj 2018-02-17 00:35:49 UTC
Created attachment 368455 [details] [review]
msdk: encode: Add property to set slice/partitioning
Comment 6 sreerenj 2018-02-17 00:36:12 UTC
Created attachment 368456 [details] [review]
msdk: encode: Add more rate control options
Comment 7 sreerenj 2018-02-17 00:36:33 UTC
Created attachment 368457 [details] [review]
msdk: h264_enc: Add LookaheadDownsampling support
Comment 8 sreerenj 2018-02-17 00:37:03 UTC
Created attachment 368458 [details] [review]
msdk: encoder: h264: Enable trellis quantization tuning
Comment 9 sreerenj 2018-02-17 00:37:38 UTC
Created attachment 368459 [details] [review]
msdk: move enum definitions to separate file
Comment 10 sreerenj 2018-02-17 00:38:02 UTC
Created attachment 368460 [details] [review]
msdk: h264_enc: Add slice size tuning option
Comment 11 sreerenj 2018-02-17 00:38:29 UTC
Created attachment 368461 [details] [review]
msdk: Add more tuning options
Comment 12 sreerenj 2018-02-17 00:39:00 UTC
Created attachment 368462 [details] [review]
msdk: h264_enc: Enable B-pyramid prediction support
Comment 13 sreerenj 2018-02-17 20:36:17 UTC
Wondering whether it is the right time to push the patch series now since the pre-release is already out. Any thoughts??

I have done some basic testing(which passed of course) and but ideally, it requires extensive testing to make sure everything works as expected(eg: check slice size whether it works as expected based on the value user given).
Comment 14 Tim-Philipp Müller 2018-02-17 20:42:56 UTC
It's a fairly new plugin and it's -bad, so I'd say get in as much as you can as soon as you can :)
Comment 15 sreerenj 2018-02-17 21:23:17 UTC
(In reply to Tim-Philipp Müller from comment #14)
> It's a fairly new plugin and it's -bad, so I'd say get in as much as you can
> as soon as you can :)

K, will do... thanks, Tim :)
Comment 16 Víctor Manuel Jáquez Leal 2018-02-18 14:36:57 UTC
Review of attachment 368453 [details] [review]:

Overall, the approach looks OK.

Just a couple nitpicks

::: sys/msdk/gstmsdkenc.c
@@ +1262,3 @@
 }
 
+

This patch looks overly complex because of the code swapping. Could be possible to split it two patches, one for the code move and other for the new functions, if the move of code is truly required.

::: sys/msdk/gstmsdkenc.h
@@ +55,2 @@
 #define MAX_EXTRA_PARAMS 8
+#define GST_MSDKENC_COMMON_PROPERTIES 13

I don't see the need to define this macro only. I would expose in the header the whole enum, with a proper name space:

enum
{
  GST_MSDKENC_PROP_HARDWARE = 1,
  GST_MSDKENC_PROP_ASYNC_DEPTH,
  GST_MSDKENC_PROP_TARGET_USAGE,
  GST_MSDKENC_PROP_RATE_CONTROL,
  GST_MSDKENC_PROP_BITRATE,
  GST_MSDKENC_PROP_MAX_FRAME_SIZE,
  GST_MSDKENC_PROP_MAX_VBV_BITRATE,
  GST_MSDKENC_PROP_AVBR_ACCURACY,
  GST_MSDKENC_PROP_AVBR_CONVERGENCE,
  GST_MSDKENC_PROP_RC_LOOKAHEAD_DEPTH,
  GST_MSDKENC_PROP_QPI,
  GST_MSDKENC_PROP_QPP,
  GST_MSDKENC_PROP_QPB,
  GST_MSDKENC_PROP_GOP_SIZE,
  GST_MSDKENC_PROP_REF_FRAMES,
  GST_MSDKENC_PROP_I_FRAMES,
  GST_MSDKENC_PROP_B_FRAMES,
  GST_MSDKENC_PROP_NUM_SLICES,
  GST_MSDKENC_PROP_MBBRC,
  GST_MSDKENC_PROP_ADAPTIVE_I,
  GST_MSDKENC_PROP_ADAPTIVE_B,
  GST_MSDKENC_PROP_MAX
};


Later, others inherited classes could look for those properties by its ID, and also could use GST_MSDKENC_PROP_MAX for the next ID value for their own properties.

@@ +143,3 @@
+gboolean
+gst_msdkenc_get_common_property (GObject * object, guint prop_id,
+                              GValue * value, GParamSpec * pspec);

Indentation doesn't look right.

::: sys/msdk/gstmsdkh264enc.c
@@ +44,3 @@
 enum
 {
+  PROP_CABAC = GST_MSDKENC_COMMON_PROPERTIES + 1,

For example this would be:

PROP_CABAC = GST_MSDKENC_MAX,

::: sys/msdk/gstmsdkh265enc.c
@@ +188,3 @@
 
+  gobject_class->set_property = gst_msdkh265enc_set_property;
+  gobject_class->get_property = gst_msdkh265enc_get_property;

As this is a pattern that repeats in several encodesr (h265, mpeg2 and vp8) I would add helper functions in the base case for set and get properties:

g_object_class->set_property = gst_msdkenc_set_property;
g_object_class->get_property = gst_msdkenc_get_property;
Comment 17 sreerenj 2018-02-18 18:33:47 UTC
(In reply to Víctor Manuel Jáquez Leal from comment #16)
> Review of attachment 368453 [details] [review] [review]:
> 
> Overall, the approach looks OK.
> 
> Just a couple nitpicks
> 
> ::: sys/msdk/gstmsdkenc.c
> @@ +1262,3 @@
>  }
>  
> +
> 
> This patch looks overly complex because of the code swapping. Could be
> possible to split it two patches, one for the code move and other for the
> new functions, if the move of code is truly required.
> 
> ::: sys/msdk/gstmsdkenc.h
> @@ +55,2 @@
>  #define MAX_EXTRA_PARAMS 8
> +#define GST_MSDKENC_COMMON_PROPERTIES 13
> 
> I don't see the need to define this macro only. I would expose in the header
> the whole enum, with a proper name space:
> 
> enum
> {
>   GST_MSDKENC_PROP_HARDWARE = 1,
>   GST_MSDKENC_PROP_ASYNC_DEPTH,
>   GST_MSDKENC_PROP_TARGET_USAGE,
>   GST_MSDKENC_PROP_RATE_CONTROL,
>   GST_MSDKENC_PROP_BITRATE,
>   GST_MSDKENC_PROP_MAX_FRAME_SIZE,
>   GST_MSDKENC_PROP_MAX_VBV_BITRATE,
>   GST_MSDKENC_PROP_AVBR_ACCURACY,
>   GST_MSDKENC_PROP_AVBR_CONVERGENCE,
>   GST_MSDKENC_PROP_RC_LOOKAHEAD_DEPTH,
>   GST_MSDKENC_PROP_QPI,
>   GST_MSDKENC_PROP_QPP,
>   GST_MSDKENC_PROP_QPB,
>   GST_MSDKENC_PROP_GOP_SIZE,
>   GST_MSDKENC_PROP_REF_FRAMES,
>   GST_MSDKENC_PROP_I_FRAMES,
>   GST_MSDKENC_PROP_B_FRAMES,
>   GST_MSDKENC_PROP_NUM_SLICES,
>   GST_MSDKENC_PROP_MBBRC,
>   GST_MSDKENC_PROP_ADAPTIVE_I,
>   GST_MSDKENC_PROP_ADAPTIVE_B,
>   GST_MSDKENC_PROP_MAX
> };
> 
> 
> Later, others inherited classes could look for those properties by its ID,
> and also could use GST_MSDKENC_PROP_MAX for the next ID value for their own
> properties.

Yup, much better. 
I kept whatever code existed before as it is and added news stuff on top :)
Will change it. Thanks!


> 
> @@ +143,3 @@
> +gboolean
> +gst_msdkenc_get_common_property (GObject * object, guint prop_id,
> +                              GValue * value, GParamSpec * pspec);
> 
> Indentation doesn't look right.
> 

Yup, fix on the way.

> ::: sys/msdk/gstmsdkh264enc.c
> @@ +44,3 @@
>  enum
>  {
> +  PROP_CABAC = GST_MSDKENC_COMMON_PROPERTIES + 1,
> 
> For example this would be:
> 
> PROP_CABAC = GST_MSDKENC_MAX,
> 
> ::: sys/msdk/gstmsdkh265enc.c
> @@ +188,3 @@
>  
> +  gobject_class->set_property = gst_msdkh265enc_set_property;
> +  gobject_class->get_property = gst_msdkh265enc_get_property;
> 
> As this is a pattern that repeats in several encodesr (h265, mpeg2 and vp8)
> I would add helper functions in the base case for set and get properties:
> 
> g_object_class->set_property = gst_msdkenc_set_property;
> g_object_class->get_property = gst_msdkenc_get_property;

There are other routines like this we can move too. But I think it is better to keep everything simple like other gstreamer elements than providing helper function like we did in gstreamer-vaapi.
Comment 18 Hyunjun Ko 2018-02-19 07:55:09 UTC
(In reply to sreerenj from comment #17)
> > ::: sys/msdk/gstmsdkh265enc.c
> > @@ +188,3 @@
> >  
> > +  gobject_class->set_property = gst_msdkh265enc_set_property;
> > +  gobject_class->get_property = gst_msdkh265enc_get_property;
> > 
> > As this is a pattern that repeats in several encodesr (h265, mpeg2 and vp8)
> > I would add helper functions in the base case for set and get properties:
> > 
> > g_object_class->set_property = gst_msdkenc_set_property;
> > g_object_class->get_property = gst_msdkenc_get_property;
> 
> There are other routines like this we can move too. But I think it is better
> to keep everything simple like other gstreamer elements than providing
> helper function like we did in gstreamer-vaapi.

+1. Align myself with Sree for this.
Comment 19 sreerenj 2018-02-20 20:46:56 UTC
Review of attachment 368453 [details] [review]:

obsolete
Comment 20 sreerenj 2018-02-20 20:47:34 UTC
Review of attachment 368454 [details] [review]:

obsolete
Comment 21 sreerenj 2018-02-20 20:48:28 UTC
Review of attachment 368462 [details] [review]:

Obsolete
Comment 22 sreerenj 2018-02-20 20:48:38 UTC
Review of attachment 368461 [details] [review]:

Obsolete
Comment 23 sreerenj 2018-02-20 20:48:44 UTC
Review of attachment 368460 [details] [review]:

Obsolete
Comment 24 sreerenj 2018-02-20 20:48:50 UTC
Review of attachment 368459 [details] [review]:

Obsolete
Comment 25 sreerenj 2018-02-20 20:48:57 UTC
Review of attachment 368458 [details] [review]:

Obsolete
Comment 26 sreerenj 2018-02-20 20:49:02 UTC
Review of attachment 368457 [details] [review]:

Obsolete
Comment 27 sreerenj 2018-02-20 20:49:08 UTC
Review of attachment 368456 [details] [review]:

Obsolete
Comment 28 sreerenj 2018-02-20 20:49:13 UTC
Review of attachment 368455 [details] [review]:

Obsolete
Comment 29 sreerenj 2018-02-20 20:58:40 UTC
Pushed the patches.

Few of the properties which are currently available (not all of them are introduced by the above patch series) is not making any sense for vp8 encoder (eg: b-frame count).Some of the others have no clarity in msdk spec (eg: slice-count), not sure whether it can be treated as "segment count" for vp8. The vp8 encoder itself is not working for me. So until we have a msdk release (working solution)which can support vp8/vp9 encode, the main focus should be only to mpeg2/h264 and hevc.
Comment 30 Maksim S 2018-06-22 14:27:08 UTC
Hi,

looks like this patch have broken meson builds of MediaSDK plugin: https://github.com/GStreamer/gst-plugins-bad/commit/ddd02be0def33a9be313038bf409cf294c5d2b2d#diff-773108e4589d91efef04623ac5766186R22

Filename should be changed from 'msdk-enum.c' to 'msdk-enums.c' in meson.build script.
Comment 31 Maksim S 2018-06-22 14:34:43 UTC
Disregard my previous comment, I've found that the fix is on the 1.14 branch already, it is just not have ben merged into master.