[FFmpeg-devel] Patch to create trapezoid videos with ffmpeg.

Nicholas Robbins nickrobbins at yahoo.com
Sun Oct 19 00:47:38 CEST 2014


> On Saturday, October 18, 2014 8:55 AM, Nicholas Robbins <nickrobbins-at-yahoo.com at ffmpeg.org> wrote:

> >>  On Saturday, October 18, 2014 8:36 AM, Moritz Barsnick 
> <barsnick at gmx.net> wrote:
> 
>>  You basically got it right. (I happened to follow the thread on
>>  ffmpeg-devel, thanks for forwarding it.)
>> 
>>  a) An inverse calculation, like in your example given. But that's just
>>  totally over the top, no-one can be expected to be capable of such a
>>  calculation. I tried to figure it out from the code, but couldn't.
> 
> I happen to be a mathematician, and I've taught courses on projective 
> geometry and perspective. If you know the right question to ask mathematically 
> it's straight forward, but the answer is a mess.
> 
>>  b) What I meant - and you got it totally right on ffmpeg-devel - is to
>>  re-use the code from the perspective filter, because it contains all
>>  the transformations, considerations, and colorspace cruft. Just the
>>  wrong parameters. So the questions regarding "how to re-use a 
> filter's
>>  algorithms/mechanisms without duplicating its code" are spot-on.
> 
> I'm leaning to making it an option to the perspective filter, so you can say 
> how you want the parameters intrepreted, as the locations in the source of the 
> corners of the new video or the locations in the new video of the corners of the 
> source.
> 
> I don't know anything about the colorspace stuff but that could presumably 
> be put in. If I understand correctly (a big if), the array pv in the context 
> stores the inverse locations of the new image. If that is outside of the 
> original image, it could just be set to [0,0,0,0] or whatever, but I don't 
> know about color formats or anything.
> 
> If you want to handle that, I'll tackle the inverse transformation part.
> 
> -Nick
> 
>>  That said, I pointed out that the perspective filter is doing peculiar
>>  things with the color edges when using such "negative" 
> parameters. 
I see what it is doing, I think it is just interpolating from the data it has. The "peculiar" things you see it doing is probably due to the fact that it might not sample croma at every pixel. I find that if I put a two pixel black frame around the image first it works fine.

>>  Have
>>  a look at my testsrc example's output. Possibly the perspective filter
>>  was only written with "inside" reference points in mind. The 
> opposite
>>  filter would also need to be able to fill the remaining "empty" 
> space
>>  with some kind of transparency/alpha channel, so that overlaying the
>>  warped frame over another stream is possible. That's basically what the
>>  original poster was looking for, and what makes sense to me from a user
>>  perspective.

I imagine you if you add a two pixel pad of transparent black (0x00000000), it would do what you suggest. I've attached a patch. Apply the patch, recompile and see if 

./ffplay -f lavfi -i testsrc -vf pad="iw+4:ih+4:2:2:0x00000000",perspective=x0=W/4:y0=H/4:x1=3*W/4:y1=H/4:sense=destination

does what you want. If this works, I'll add documentation and submit it.





>>  Moritz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: perspective.patch
Type: text/x-patch
Size: 6279 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20141018/8a6316ed/attachment.bin>


More information about the ffmpeg-devel mailing list