Opened 9 months ago

Last modified 9 months ago

#10280 new enhancement

Request to add an option to the perspective filter to show through underlying content vs. extending the outside pixels

Reported by: jbmcgx Owned by:
Priority: normal Component: avfilter
Version: 5.1.2 Keywords: perspective
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no


The perspective filter appears to currently only have the option to extend the outside pixels instead of letting the area outside the desired coordinates show through.

With this command to overlay an image on another image with a perspective transform, you can see that the image underneath gets covered up:

ffmpeg -i "" -i "" -filter_complex "[1:v] scale=width=1920:height=1080:out_color_matrix=bt709:flags=lanczos,format=rgba,perspective=x0=534.49:y0=430.43:x1=867.1:y1=396.78:x2=526.01:y2=674.9:x3=887.03:y3=641.32:sense=destination [sized0]; [0:v][sized0] overlay=format=yuv444:x=0:y=0,format=yuv420p" -qscale:v 2 -frames:v 1 -pix_fmt yuvj420p "no_pad_extended_pixels.jpg"

I've discovered that you can get around this issue by adding a transparent border using the pad filter. This way the transparent pixels are extended instead of the edges of the overlaid image and the underlying image is shown. Here's that same command updated with that:

ffmpeg -i "" -i "" -filter_complex "[1:v] scale=width=1920:height=1080:out_color_matrix=bt709:flags=lanczos,pad=iw+4:ih+4:2:2:#00000000,format=rgba,perspective=x0=540.13:y0=430.7:x1=872.14:y1=397.37:x2=531.38:y2=675.01:x3=891.74:y3=641.77:sense=destination [sized0]; [0:v][sized0] overlay=format=yuv444:x=0:y=0,format=yuv420p" -qscale:v 2 -frames:v 1 -pix_fmt yuvj420p "with_pad_showing_underlying.jpg"

This works, however, it throws off the coordinates and it's not easy to calculate the resized border size and adjust accordingly.

It would greatly improve usability to add an option to set the outside pixels to a certain colour or even just something like outer_pixels set to either "extend" or "transparent".

Attachments (2)

no_pad_extended_pixels.jpg (67.8 KB ) - added by jbmcgx 9 months ago.
with_pad_showing_underlying.jpg (96.7 KB ) - added by jbmcgx 9 months ago.

Download all attachments as: .zip

Change History (4)

by jbmcgx, 9 months ago

Attachment: no_pad_extended_pixels.jpg added

by jbmcgx, 9 months ago

comment:1 by jbmcgx, 9 months ago

Version: unspecified5.1.2

comment:2 by Michael Koch, 9 months ago

Duplicate of ticket 8124?

Note: See TracTickets for help on using tickets.