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 789847 - msdkenc: Add support for YV12, YUY2, UYVY and BGRA
msdkenc: Add support for YV12, YUY2, UYVY and BGRA
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-bad
unspecified
Other All
: Normal enhancement
: 1.13.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks: 789886
 
 
Reported: 2017-11-03 09:04 UTC by Sebastian Dröge (slomo)
Modified: 2017-12-07 18:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
msdkenc: Add support for YV12, YUY2, UYVY and BGRA (21.82 KB, patch)
2017-11-03 09:04 UTC, Sebastian Dröge (slomo)
none Details | Review
msdkenc: Add support for YV12, YUY2, UYVY and BGRA (22.04 KB, patch)
2017-11-06 08:26 UTC, Sebastian Dröge (slomo)
none Details | Review
msdkenc: Add support for YV12, YUY2, UYVY and BGRA (21.86 KB, patch)
2017-11-06 08:44 UTC, Sebastian Dröge (slomo)
none Details | Review
msdkenc: Add support for YV12, YUY2, UYVY and BGRA (21.75 KB, patch)
2017-11-16 09:33 UTC, Sebastian Dröge (slomo)
none Details | Review
msdkenc: Add support for YV12, YUY2, UYVY and BGRA (21.75 KB, patch)
2017-11-16 09:34 UTC, Sebastian Dröge (slomo)
committed Details | Review
msdkenc: fix handling YUY2,YV12,BGRA surface (2.61 KB, patch)
2017-11-17 08:59 UTC, Hyunjun Ko
none Details | Review
msdkenc: fix handling YUY2,UYVY,BGRA surface (2.61 KB, patch)
2017-11-17 09:02 UTC, Hyunjun Ko
committed Details | Review

Description Sebastian Dröge (slomo) 2017-11-03 09:04:46 UTC
This does not work yet, I'm only putting it into Bugzilla for discussion now
Comment 1 Sebastian Dröge (slomo) 2017-11-03 09:04:52 UTC
Created attachment 362882 [details] [review]
msdkenc: Add support for YV12, YUY2, UYVY and BGRA

By doing conversion with VPP to NV12 before the actual encoding.
Comment 2 Sebastian Dröge (slomo) 2017-11-06 08:26:25 UTC
Created attachment 363035 [details] [review]
msdkenc: Add support for YV12, YUY2, UYVY and BGRA

By doing conversion with VPP to NV12 before the actual encoding.
Comment 3 Sebastian Dröge (slomo) 2017-11-06 08:31:02 UTC
Review of attachment 363035 [details] [review]:

Still does not work, but some notes for later

::: sys/msdk/gstmsdkenc.c
@@ +393,3 @@
+    request[0].NumFrameSuggested =
+        MAX (request[0].NumFrameSuggested, request[1].NumFrameSuggested);
+  if (request[0].NumFrameSuggested < thiz->param.AsyncDepth) {

This should probably be 1 more if vpp

@@ +881,3 @@
+
+    /* Wait for VPP operation to complete */
+    MFXVideoCORE_SyncOperation (session, vpp_sync_point, 10000);

Instead of waiting for completion here, according to the encoding example from the MediaSDK code, it would also be possible to directly encode it and the encoder takes care of the waiting once needed.
Comment 4 Sebastian Dröge (slomo) 2017-11-06 08:44:51 UTC
Created attachment 363036 [details] [review]
msdkenc: Add support for YV12, YUY2, UYVY and BGRA

By doing conversion with VPP to NV12 before the actual encoding.
Comment 5 Hyunjun Ko 2017-11-16 03:14:08 UTC
Review of attachment 363036 [details] [review]:

::: sys/msdk/gstmsdkenc.c
@@ +297,3 @@
+    thiz->vpp_surfaces = g_new0 (mfxFrameSurface1, thiz->num_vpp_surfaces);
+    for (i = 0; i < thiz->num_vpp_surfaces; i++) {
+        thiz->vpp_param.vpp.In.FourCC = MFX_FOURCC_RGB4;

This should be thiz->vpp_param.vpp instead of param.vpp.
Comment 6 Hyunjun Ko 2017-11-16 03:20:54 UTC
(In reply to Sebastian Dröge (slomo) from comment #3)
 
> @@ +881,3 @@
> +
> +    /* Wait for VPP operation to complete */
> +    MFXVideoCORE_SyncOperation (session, vpp_sync_point, 10000);
> 
> Instead of waiting for completion here, according to the encoding example
> from the MediaSDK code, it would also be possible to directly encode it and
> the encoder takes care of the waiting once needed.


Yeah, as far as I tested, it seems to work without the operation.
Comment 7 Hyunjun Ko 2017-11-16 03:23:30 UTC
With this patch(modified by comment 5) and the patch in #bug 790312, it works except for YUY2, BGRA.

I'm looking into it.
Comment 8 Hyunjun Ko 2017-11-16 04:42:53 UTC
(In reply to Hyunjun Ko from comment #7)
> With this patch(modified by comment 5) and the patch in #bug 790312, it
> works except for YUY2, BGRA.
> 
> I'm looking into it.

YUY2 is only for jpeg encoder as per sample, but not working with msdkmjpegenc.

eg. gst-launch-1.0 videotestsrc num-buffers=100 ! video/x-raw,format=YUY2,width=640,height=320 ! msdkmjpegenc ! filesink location=test.jpeg
Comment 9 Hyunjun Ko 2017-11-16 04:43:28 UTC
Review of attachment 363036 [details] [review]:

::: sys/msdk/msdk.c
@@ +92,3 @@
+        surface->Data.Y = GST_VIDEO_FRAME_COMP_DATA (frame, 0);
+        surface->Data.U = GST_VIDEO_FRAME_COMP_DATA (frame, 1);
+        break;

Probably this should be 2?
Comment 10 Sebastian Dröge (slomo) 2017-11-16 09:33:04 UTC
Created attachment 363814 [details] [review]
msdkenc: Add support for YV12, YUY2, UYVY and BGRA

By doing conversion with VPP to NV12 before the actual encoding.
Comment 11 Sebastian Dröge (slomo) 2017-11-16 09:34:08 UTC
Created attachment 363815 [details] [review]
msdkenc: Add support for YV12, YUY2, UYVY and BGRA

By doing conversion with VPP to NV12 before the actual encoding.
Comment 12 Sebastian Dröge (slomo) 2017-11-16 09:35:07 UTC
Thanks for the review Hyunjun, and for finding my silly mistakes :)

YUY2 should work for other codecs too AFAIU, from where do you have the information that it only works for JPEG?
Comment 13 Sebastian Dröge (slomo) 2017-11-16 09:37:01 UTC
Also the conversion is done by VPP, so first converting YUY2 to NV12 and then passing it to the h264 encoder for example should work fine, or not?

Or do you mean YUY2 is supposed to be *natively* handled by the JPEG encoder but not by others?
Comment 14 Hyunjun Ko 2017-11-17 05:53:51 UTC
(In reply to Sebastian Dröge (slomo) from comment #13)
> Also the conversion is done by VPP, so first converting YUY2 to NV12 and
> then passing it to the h264 encoder for example should work fine, or not?
> 
> Or do you mean YUY2 is supposed to be *natively* handled by the JPEG encoder
> but not by others?

No, I meant YUY2 -> NV12 -> encoding seems to be only for jpeg encoder.
This was according to the sample_encoder's help, which says "YUY2 is for JPEG encode only." But I realized I'm wrong.

I modified the sample encoder and verified it(yuy2) also works for h264encoder.
So please forget my previous comment about yuy2 :)
Comment 15 Hyunjun Ko 2017-11-17 08:59:42 UTC
Created attachment 363896 [details] [review]
msdkenc: fix handling YUY2,YV12,BGRA surface
Comment 16 Hyunjun Ko 2017-11-17 09:02:16 UTC
Created attachment 363897 [details] [review]
msdkenc: fix handling YUY2,UYVY,BGRA surface

Based on slomo's patch.
Comment 17 Hyunjun Ko 2017-11-17 09:02:35 UTC
Sebastian, could you test on this patch?
Comment 18 Hyunjun Ko 2017-11-17 09:04:28 UTC
Looks weird to handle YUY2,UYVY,BGRA surface.
I referenced to sample source code.
Comment 19 Sebastian Dröge (slomo) 2017-11-17 10:10:47 UTC
(In reply to Hyunjun Ko from comment #14)
> (In reply to Sebastian Dröge (slomo) from comment #13)
> > Also the conversion is done by VPP, so first converting YUY2 to NV12 and
> > then passing it to the h264 encoder for example should work fine, or not?
> > 
> > Or do you mean YUY2 is supposed to be *natively* handled by the JPEG encoder
> > but not by others?
> 
> No, I meant YUY2 -> NV12 -> encoding seems to be only for jpeg encoder.
> This was according to the sample_encoder's help, which says "YUY2 is for
> JPEG encode only." But I realized I'm wrong.

That doesn't seem to make any sense :) If VPP can handle YUY2, it shouldn't matter if the encoder comes afterwards or not, and even less if the JPEG or another encoder comes afterwards.

Either that comment is wrong, or what they mean is that the JPEG encoder can directly take YUY2 without conversion.
Comment 20 Sebastian Dröge (slomo) 2017-11-17 10:12:33 UTC
Review of attachment 363897 [details] [review]:

This is necessary for anything to work?

I assume this would also allow to support NV21, RGBA/BGRA/ARGB/ABGR then :)
Comment 21 Sebastian Dröge (slomo) 2017-11-20 12:40:58 UTC
commit 3c611da315f3755f4675fe4e874389e033f44d08
Author: Hyunjun Ko <zzoon@igalia.com>
Date:   Fri Nov 17 17:49:16 2017 +0900

    msdkenc: Fix handling of YUY2, UYVY, BGRA surfaces
    
    https://bugzilla.gnome.org/show_bug.cgi?id=789847

commit d3eeb98f0ce298324f844c3678614afc27c3ce7d
Author: Sebastian Dröge <sebastian@centricular.com>
Date:   Thu Nov 16 11:32:52 2017 +0200

    msdkenc: Add support for YV12, YUY2, UYVY and BGRA
    
    By doing conversion with VPP to NV12 before the actual encoding.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=789847
Comment 22 sreerenj 2017-12-06 23:26:08 UTC
IIUC, NV12 should be the only input format accepted by the encoders except for JPEG which can support yuy2 too.

This is the same case for open source driver(one we use in gstremaer-vaapi) too. but open source driver can work with other input formats because there is an internal VPP for NV12 CSC inside the driver. I don't think msdk is doing it like this. AFAIK msdk is very strict on input format which should be Tiled NV12.
Comment 23 Sebastian Dröge (slomo) 2017-12-07 07:54:03 UTC
Doing conversion in the encoder, especially if so simple, makes it easier for applications to use the encoder. Also doing the conversion in the encoder is potentially faster as you can schedule both the conversion and encoding together (as is done here now) instead of waiting first for the conversion to finish.
Comment 24 Víctor Manuel Jáquez Leal 2017-12-07 15:06:26 UTC
Yes, current encoders in gst-msdk uses VPP if the color format is different from NV12. Remove this option and force to add a VPP element before the encoders would be a regression under the sight of many.

Also, in te case of decoders, a VPP processing can be included in the srcpad buffers to offer more formats as output. But that's not the case currently.

Another improvement to this approach would be to query VPP the supported color transformation when registering the elements.

And later on, create encapsulate all the logic related to VPP so it could be reused by different elements.
Comment 25 sreerenj 2017-12-07 18:47:51 UTC
Ok, So I guess we will be having 2 vpp paths in msdk elements.
1: implicit conversions in decoders and encoder
2: explicit conversion with vpp element.


BTW, this reminds me of something I have noticed in gstremaer-vaapi + open source  driver.
The open source driver does CSC internally for all non-nv12 formats (and also for non-tiled nv12). But unfortunately, the code path of explicit vpp(which is using optimized 3D sampler) and the vpp path used by the driver internally(avs sampler) are different. Explicit vpp (vaapipostproc) seems to be more performant than the internal conversion . This is visible if you run parallel encode use cases.