summaryrefslogtreecommitdiff
path: root/libavfilter/vf_pad.c
diff options
context:
space:
mode:
authorRicardo Constantino <wiiaboo@gmail.com>2017-04-03 19:34:09 +0100
committerRostislav Pehlivanov <atomnuker@gmail.com>2017-04-07 21:35:06 +0100
commit57c3670896c69714ca1514728edf5ee48b2abcc9 (patch)
tree26f36a9106da528cbf67a64f3323e1603a4146ca /libavfilter/vf_pad.c
parent3f8d7342c32c8b22ab177d62f5c7660db213e342 (diff)
downloadffmpeg-57c3670896c69714ca1514728edf5ee48b2abcc9.tar.gz
vf_pad: center image on padded area if negative x/y
or if x/y go beyond padded area. This is mostly useful when paired with the aspect option. Defaults aren't changed. Idea for this was taken from mpv's soon-to-be-removed expand vf. Reviewed-by: Paul B Mahol <onemda@gmail.com>
Diffstat (limited to 'libavfilter/vf_pad.c')
-rw-r--r--libavfilter/vf_pad.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/libavfilter/vf_pad.c b/libavfilter/vf_pad.c
index 44a8fec0cb..725dc29e96 100644
--- a/libavfilter/vf_pad.c
+++ b/libavfilter/vf_pad.c
@@ -173,8 +173,13 @@ static int config_input(AVFilterLink *inlink)
goto eval_fail;
s->x = var_values[VAR_X] = res;
+ if (s->x < 0 || s->x + inlink->w > s->w)
+ s->x = var_values[VAR_X] = (s->w - inlink->w) / 2;
+ if (s->y < 0 || s->y + inlink->h > s->h)
+ s->y = var_values[VAR_Y] = (s->h - inlink->h) / 2;
+
/* sanity check params */
- if (s->w < 0 || s->h < 0 || s->x < 0 || s->y < 0) {
+ if (s->w < 0 || s->h < 0) {
av_log(ctx, AV_LOG_ERROR, "Negative values are not acceptable.\n");
return AVERROR(EINVAL);
}
@@ -192,10 +197,7 @@ static int config_input(AVFilterLink *inlink)
inlink->w, inlink->h, s->w, s->h, s->x, s->y,
s->rgba_color[0], s->rgba_color[1], s->rgba_color[2], s->rgba_color[3]);
- if (s->x < 0 || s->y < 0 ||
- s->w <= 0 || s->h <= 0 ||
- (unsigned)s->x + (unsigned)inlink->w > s->w ||
- (unsigned)s->y + (unsigned)inlink->h > s->h) {
+ if (s->w <= 0 || s->h <= 0) {
av_log(ctx, AV_LOG_ERROR,
"Input area %d:%d:%d:%d not within the padded area 0:0:%d:%d or zero-sized\n",
s->x, s->y, s->x + inlink->w, s->y + inlink->h, s->w, s->h);