Opened 3 years ago

Closed 3 years ago

#8475 closed defect (duplicate)

pad filter fails in certain edge cases because of rounding

Reported by: Ivan Middleton Owned by:
Priority: normal Component: avfilter
Version: git-master Keywords: pad
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no


In certain cases, the pad filter fails to configure itself properly. Here's an example, using imagemagick to create an appropriate test file:

$ convert -size 15x15 xc:red -sampling-factor 4:2:0 red.jpg
$ ffmpeg -i red.jpg -vf pad=iw+16:ih+16:ow-iw:oh-ih pad.png
...Input area 16:16:31:31 not within the padded area 0:0:30:30...

It seems like ow-iw and oh-ih should always work as values of x and y; this should put the image in the lower right corner.

The failure occurs because the values of w:h:x:y are first computed as 31:31:16:16 and then rounded down (via ff_draw_round_to_sub) to 30:30:16:16 due to chroma considerations. Since the values of w and h have shrunk but x and y have not, the image is no longer validly placed.

A possible solution is to round off w and h before evaluating x and y. In my example, this would result in w:h being evaluated as 31:31 and rounded to 30:30, then x:y being evaluated as 15:15 and rounded to 14:14.

Change History (1)

comment:1 by Carl Eugen Hoyos, 3 years ago

Keywords: filter rounding removed
Resolution: duplicate
Status: newclosed

For future tickets, please remember to always provide the FFmpeg command line you tested together with the complete, uncut console output.

Looks like a duplicate of ticket #1618

Note: See TracTickets for help on using tickets.