Rotating video when using compositor (and not losing off-edge-pixels)

Antonio Ospite ao2 at ao2.it
Mon Dec 18 12:00:54 UTC 2017


On Sun, 17 Dec 2017 00:48:32 -0600
Sean DuBois <sean at siobud.com> wrote:

> I am trying to rotate a video by degrees that are not divisible by 90.
> Like this [0] pipeline . However I am not able to find any solutions
> that don't involve losing pixels and/or support alpha.
> 
> So far the best thing I have found is videoflip, and it works well for
> 90/180/270
> 
> Does anyone know a solution, and if not would an element be welcome for
> this? Or maybe I can add a patch to rotate (but for my use case I would
> want the sink to always have alpha) and the height/width would be
> re-calculated every time the angle changed.
>

About the alpha, you have to set caps before the rotation to make sure you
are using a format which does have an alpha channel, like in:

gst-launch-1.0 videotestsrc ! video/x-raw,format=ARGB ! ... ! videoconvert ! autovideosink

About the off-edge-pixels:

1. If you do not want to lose pixels, composite to a bigger
   transparent frame and rotate that:

   gst-launch-1.0 videotestsrc ! video/x-raw,format=ARGB ! compositor background=transparent sink_0::xpos=160 sink_0::ypos=120 ! video/x-raw,width=640,height=480 ! rotate angle=5 ! compositor sink_0::xpos=200 sink_0::ypos=200 ! video/x-raw,width=1280,height=720 ! videoconvert ! autovideosink 

2. If shrinking the image is fine, then use an affine transform to
   rotate scale and translate at the same time, if you cannot use
   gltransformation you can try the "perspective" element which does
   everything on the CPU, you'll have to pass the calculated matrix from
   code.

   The matrix can be calculated with the formula from here:
   https://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html#getrotationmatrix2d

   Adding one last row set to [0,0,1] because "perspective" expects
   a 3x3 matrix.

   Maybe "perspective" wasn't the best name for the element as it
   performs a generic matrix transform.


Ciao,
   Antonio

-- 
Antonio Ospite
https://ao2.it
https://twitter.com/ao2it

A: Because it messes up the order in which people normally read text.
   See http://en.wikipedia.org/wiki/Posting_style
Q: Why is top-posting such a bad thing?


More information about the gstreamer-devel mailing list