[FFmpeg-user] How to create trapezoid videos with ffmpeg?

Zenny garbytrash at gmail.com
Sat Oct 18 08:03:25 CEST 2014


@Moritz and @Nick: Thanks for the very useful inputs. Appreciate that!

On 10/17/14, Nicholas Robbins <nickrobbins-at-yahoo.com at ffmpeg.org> wrote:
>> On Thursday, October 16, 2014 11:59 AM, Moritz Barsnick <barsnick at gmx.net>
>> wrote:
>
>> > Hi Zenny,
>>
>> On Wed, Oct 15, 2014 at 10:55:40 +0200, Zenny wrote:
>>>  New to ffmpeg. How can one create a trapezoid shaped video as a
>>>  overlay to the background as seen at
>>>  http://www.youtube.com/watch?v=_380o5B9MrA (starts at 00:02:25) using
>>>  ffmpeg command?
>>
>> I can't seem to find a filter which does that directly, but the
>> "perspective" does a similar transformation, in an inverse way. I
>> believe it "virtually pulls the given viewpoints to the corners."
>> Using
>>
>> ....
>>
>> Note the reference points _outside_ of the frame to achieve a trapezoid
>> size reduction. The filter you are looking for should probably accept
>> actual corner values. That said, such a filter could probably be
>> derived from the "perspective" filter's code. (I failed at finding
>> an
>> easy way to do this though.)
>>
>> Moritz
>
> Ok, I'm not sure what you meant by an easy way, but the formula for what to
> put into the perspective filter options to essentially have it be the
> inverse (where to send the corners, not what to send to the corners) is huge
> mess, so it can't be done easily for any given picture (just change the x0
> to a -x0 or whatever). However it might be able to be hardcoded into a
> different filter (vf_keystone?) I'll inquire on ffmpeg-devel if that is
> possible, to have one filter basically just call another filter with
> different options.
>
> For example, if you wanted the original corners to go to
> x0:y0:x1:y1:x2:y2:x3:y3 the first option (x0 for that filter) you would want
> to give to vf_perspective is
>
> (W (x2 y0 - x0 y2) (x3 (y0 - y1) + x0 (y1 - y3) +
>      x1 (-y0 + y3)) (x3 (y1 - y2) + x1 (y2 - y3) +
>      x2 (-y1 + y3)))/(-x0 (x3^2 (y1 - y2) (-2 y1 y2 + y0 (y1 + y2)) -
>       2 x2 x3 y1 (y1 - y2) (y0 - y3) + x2^2 y0 (y1 - y3)^2) +
>    x2 x3 (y0 - y1)^2 (-x3 y2 + x2 y3) +
>    x1 (x3^2 y1 (y0 - y2)^2 + 2 x0 x3 (y1 - y2) y2 (y0 - y3) -
>       x0^2 y1 (y2 - y3)^2 - 2 x2 (y1 - y2) (y0 - y3) (x3 y0 + x0 y3) +
>        x2^2 (y0 - y3) (y0 (y1 - 2 y3) + y1 y3)) +
>    x0^2 (x2 y2 (y1 - y3)^2 - x3 (y1 - y2) (2 y1 y2 - y1 y3 - y2 y3)) +
>     x1^2 (x0 y0 (y2 - y3)^2 - x3 (y0 - y2)^2 y3 -
>       x2 (y0 - y3) (y0 (y2 - 2 y3) + y2 y3)))
>
> so, yeah, not easily computed, but totally something you could compute once
> when you initialize the filter.
>
> -Nick
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>


More information about the ffmpeg-user mailing list