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 765795 - glimagesink: support video frame rotation
glimagesink: support video frame rotation
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-bad
git master
Other Linux
: Normal enhancement
: 1.9.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2016-04-29 06:38 UTC by Haihua Hu
Modified: 2016-05-25 08:30 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Support video rotation in glimagesink (14.47 KB, patch)
2016-05-10 01:21 UTC, Haihua Hu
reviewed Details | Review
modify the patch (14.39 KB, patch)
2016-05-16 12:11 UTC, Haihua Hu
needs-work Details | Review
Add more video rotate method (16.00 KB, patch)
2016-05-18 04:45 UTC, Haihua Hu
committed Details | Review

Description Haihua Hu 2016-04-29 06:38:06 UTC
Hi,
Do we have plan to support video frame rotation in glimagesink? This feature is not hard to realize. For example, add a "rotate" property and re-calculate the texture coordinate when this property changed.
Comment 1 Sebastian Dröge (slomo) 2016-04-29 06:53:37 UTC
That would be a good idea, and it should also come with automatic rotation/flipping based on the GST_TAG_IMAGE_ORIENTATION. Similar to what videoflip does.
Comment 2 Haihua Hu 2016-04-29 07:04:34 UTC
(In reply to Sebastian Dröge (slomo) from comment #1)
> That would be a good idea, and it should also come with automatic
> rotation/flipping based on the GST_TAG_IMAGE_ORIENTATION. Similar to what
> videoflip does.

So,we can implement this two property in glimagesink and also automatic change texture coordinate by GST_TAG_IMAGE_ORIENTATION. This feature will be useful for us and I will try to enable this.
Comment 3 Sebastian Dröge (slomo) 2016-04-29 07:11:29 UTC
Why two properties? Take a look at what videoflip does
Comment 4 Haihua Hu 2016-04-29 07:17:06 UTC
(In reply to Sebastian Dröge (slomo) from comment #3)
> Why two properties? Take a look at what videoflip does

I got your point. I am going to enable this feature just like videoflip does
Comment 5 Sebastian Dröge (slomo) 2016-04-29 07:18:16 UTC
It might also make sense to do this as another element inside glimagesink, just like glvideobalance, etc.
Comment 6 Haihua Hu 2016-04-29 07:27:04 UTC
(In reply to Sebastian Dröge (slomo) from comment #5)
> It might also make sense to do this as another element inside glimagesink,
> just like glvideobalance, etc.

You mean something like "glvideoflip" and put it into glimagesinkbin. The main concern is performance, if we just put it in glimagesink as a property, we only need to calculate texture coordinate when the property changes, but if we treat it as a plugin,we need to do fbo rendering on every buffer, this will cost some time and will cause performance downgrade. So I think property is better.
Comment 7 Sebastian Dröge (slomo) 2016-04-29 07:37:27 UTC
Maybe both :) Performance-wise you're right, it also seems simple enough. A separate element has its advantages too though. Or maybe flipping/rotation can be part of GLUpload/GLDownload too?
Comment 8 Haihua Hu 2016-04-29 08:09:49 UTC
(In reply to Sebastian Dröge (slomo) from comment #7)
> Maybe both :) Performance-wise you're right, it also seems simple enough. A
> separate element has its advantages too though. Or maybe flipping/rotation
> can be part of GLUpload/GLDownload too?

Yes, It is simple enough. Please wait for my patch :)
Comment 9 Haihua Hu 2016-05-06 08:03:56 UTC
Hi Matthew,

I notice that you have already implemented a element named "glvideoflip", what's your opinion about this new feature?
Comment 10 Matthew Waters (ystreet00) 2016-05-06 08:18:57 UTC
My opinion is that removing unnecessary stuff from glimagesinkelement and having separate distinct elements that only do one thing is a good architectural goal.  That comes at the cost of performance though which isn't ideal.

For this, if adding glvideoflip to glimagesinkbin is good enough performance-wise, then that's what should happen.  Otherwise, we should attempt to reuse the GstVideoAffineTransformationMeta for this to avoid adding extra unnecessary code to glimagesink.  See https://cgit.freedesktop.org/gstreamer/gst-plugins-bad/tree/ext/gl/gstglimagesink.c#n2028
Comment 11 Matthew Waters (ystreet00) 2016-05-06 08:23:15 UTC
Another option is to do both and make glvideoflip ! glimagesink negotiate the affine transformation meta and glvideoflip goes passthrough.
Comment 12 Haihua Hu 2016-05-09 05:15:56 UTC
(In reply to Matthew Waters (ystreet00) from comment #10)
> My opinion is that removing unnecessary stuff from glimagesinkelement and
> having separate distinct elements that only do one thing is a good
> architectural goal.  That comes at the cost of performance though which
> isn't ideal.
> 
> For this, if adding glvideoflip to glimagesinkbin is good enough
> performance-wise, then that's what should happen.  Otherwise, we should
> attempt to reuse the GstVideoAffineTransformationMeta for this to avoid
> adding extra unnecessary code to glimagesink.  See

On some embed system, adding glvideoflip to glimagesinkbin will definitely cost performance downgrade. For example on my imx6Q. You mean we also could use transform matrix in vertex shader to get rotation effect? Use a property to control it?

> https://cgit.freedesktop.org/gstreamer/gst-plugins-bad/tree/ext/gl/
> gstglimagesink.c#n2028
Comment 13 Matthew Waters (ystreet00) 2016-05-09 06:20:28 UTC
(In reply to Haihua Hu from comment #12)
> On some embed system, adding glvideoflip to glimagesinkbin will definitely
> cost performance downgrade. For example on my imx6Q. You mean we also could
> use transform matrix in vertex shader to get rotation effect? Use a property
> to control it?

yes, use what's already there, i.e. the GstVideoAffineTransformationMeta.
Comment 14 Haihua Hu 2016-05-10 01:21:44 UTC
Created attachment 327550 [details] [review]
Support video rotation in glimagesink

This patch apply a transform matrix to vertex coordinate to realize rotation
Comment 15 Haihua Hu 2016-05-12 10:05:54 UTC
Hi All,

Any comments for this patch?
Comment 16 Matthew Waters (ystreet00) 2016-05-13 11:26:17 UTC
Review of attachment 327550 [details] [review]:

.

::: ext/gl/gstglimagesink.c
@@ +2290,3 @@
+        (gl_sink->stored_buffer[0]);
+    if (af_meta)
+      gl_sink->transform_matrix = af_meta->matrix;

What if there's a transformation meta and the rotate property is set to !identity?  We need to combine the two transformations.

::: gst-libs/gst/gl/gstglshaderstrings.c
@@ +45,3 @@
+    "   gl_Position = u_transformation * a_position;\n"
+    "   v_texcoord = a_texcoord;\n"
+    "}\n";

Why do you need another shader? You can do the same with the existing gst_gl_shader_string_vertex_mat4_texture_transform shader with a slightly different matrix.
Comment 17 Haihua Hu 2016-05-13 11:37:02 UTC
(In reply to Matthew Waters (ystreet00) from comment #16)
> Review of attachment 327550 [details] [review] [review]:
> 
> .
> 
> ::: ext/gl/gstglimagesink.c
> @@ +2290,3 @@
> +        (gl_sink->stored_buffer[0]);
> +    if (af_meta)
> +      gl_sink->transform_matrix = af_meta->matrix;
> 
> What if there's a transformation meta and the rotate property is set to
> !identity?  We need to combine the two transformations.

Yes, the result should be the multiple of these two transformations.

> 
> ::: gst-libs/gst/gl/gstglshaderstrings.c
> @@ +45,3 @@
> +    "   gl_Position = u_transformation * a_position;\n"
> +    "   v_texcoord = a_texcoord;\n"
> +    "}\n";
> 
> Why do you need another shader? You can do the same with the existing
> gst_gl_shader_string_vertex_mat4_texture_transform shader with a slightly
> different matrix.

I have some issue by using the exist shader. I apply the rotation transform to the texture coordinate,then the video frame seems to be repeat of one single line, is there something wrong with my code?

My transform is such as clockwise-90:
0.0f, -1.0f,  0.0,  0.0f,
1.0f,  0.0f,  0.0,  0.0f,
0.0f,  0.0f,  1.0,  0.0f,
0.0f,  0.0f,  0.0,  1.0f,
Comment 18 Matthew Waters (ystreet00) 2016-05-13 12:15:11 UTC
The current transformation is based on 0 to 1 not -1 to 1 as is normal with transformations so you have to modify the matrix for that.
Comment 19 Haihua Hu 2016-05-16 07:51:17 UTC
(In reply to Matthew Waters (ystreet00) from comment #18)
> The current transformation is based on 0 to 1 not -1 to 1 as is normal with
> transformations so you have to modify the matrix for that.

Hi Matthew,
I met a problem, when I just apply a translation matrix to the texture coordinated which is intent to set the origin to point(0.5 0.5), then nothing happen, the video frame do not move. blow is the matrix

v_texcoord = (u_transformation * vec4(a_texcoord, 0, 1)).xy;

 static const gfloat identity_matrix[] = {
    1.0f,  0.0f,  0.0f,  -0.5f,
    0.0f,  1.0f,  0.0f,  -0.5f,
    0.0f,  0.0f,  1.0f,  0.0f,
    0.0f,  0.0f,  0.0f,  1.0f,
};

but when I just v_texcoord = a_texcoord-0.5, then the origin move to the middle.

What is the difference? where is wrong?
Comment 20 Haihua Hu 2016-05-16 08:33:03 UTC
(In reply to Matthew Waters (ystreet00) from comment #18)
> The current transformation is based on 0 to 1 not -1 to 1 as is normal with
> transformations so you have to modify the matrix for that.

By the way, why do we apply u_transformation to texture coordinate but not vertex coordinate? What effects do you want to realize? Since rotation transform on vertex coordinate is simpler than texture coordinate. Is it ok to change to apply u_transformation to vertex?
Comment 21 Haihua Hu 2016-05-16 12:11:43 UTC
Created attachment 327972 [details] [review]
modify the patch

This patch is based on the lastest master branch of gst-plugins-bad
Comment 22 Matthew Waters (ystreet00) 2016-05-17 19:28:32 UTC
Review of attachment 327972 [details] [review]:

.

::: ext/gl/gstglimagesink.c
@@ +191,3 @@
+  {GST_GL_ROTATE_METHOD_AUTO,
+      "Select rotate method based on image-orientation tag", "automatic"},
+  {0, NULL, NULL},

This is missing the flipped methods that are available in videoflip and glvideoflip, i.e. horizontal-flip, vertical-flip, upper-left-diagonal, upper-right-diagonal.

::: gst-libs/gst/gl/gstglutils.h
@@ +119,3 @@
 
+void gst_gl_get_affine_transformation_meta_as_ndc (GstVideoAffineTransformationMeta * meta, 
+    const gfloat * rotate_matrix, gfloat * matrix);

I don't like the changing of this function.

You should separate out the retrieval and the matrix multiply into another function like gst_gl_matrix_multiply()
Comment 23 Haihua Hu 2016-05-18 04:45:00 UTC
Created attachment 328111 [details] [review]
Add more video rotate method
Comment 24 Haihua Hu 2016-05-19 02:46:54 UTC
(In reply to Matthew Waters (ystreet00) from comment #22)
> Review of attachment 327972 [details] [review] [review]:
> 
> .
> 
> ::: ext/gl/gstglimagesink.c
> @@ +191,3 @@
> +  {GST_GL_ROTATE_METHOD_AUTO,
> +      "Select rotate method based on image-orientation tag", "automatic"},
> +  {0, NULL, NULL},
> 
> This is missing the flipped methods that are available in videoflip and
> glvideoflip, i.e. horizontal-flip, vertical-flip, upper-left-diagonal,
> upper-right-diagonal.

Have add these rotate method.

> 
> ::: gst-libs/gst/gl/gstglutils.h
> @@ +119,3 @@
>  
> +void gst_gl_get_affine_transformation_meta_as_ndc
> (GstVideoAffineTransformationMeta * meta, 
> +    const gfloat * rotate_matrix, gfloat * matrix);
> 
> I don't like the changing of this function.
> 
> You should separate out the retrieval and the matrix multiply into another
> function like gst_gl_matrix_multiply()

Just modify the origin _mulyiply_matrix4() function.
Comment 25 Haihua Hu 2016-05-23 04:59:33 UTC
Any comments for this new patch?
Comment 26 Matthew Waters (ystreet00) 2016-05-25 08:30:04 UTC
commit a5cb7469835e73285aa1b82f8c4defafb5760152
Author: Haihua Hu <jared.hu@nxp.com>
Date:   Mon May 16 20:02:28 2016 +0800

    glimagesink: support video rotation using transform matrix
    
    Add "rotate-method" to glimagesink and apply transform matrix
    to vertex coordinate to control rotation.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=765795