[FFmpeg-cvslog] vf_pad: center image on padded area if negative x/y

Ricardo Constantino git at videolan.org
Fri Apr 7 23:35:36 EEST 2017


ffmpeg | branch: master | Ricardo Constantino <wiiaboo at gmail.com> | Mon Apr  3 19:34:09 2017 +0100| [57c3670896c69714ca1514728edf5ee48b2abcc9] | committer: Rostislav Pehlivanov

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 at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=57c3670896c69714ca1514728edf5ee48b2abcc9
---

 doc/filters.texi     |  3 +++
 libavfilter/vf_pad.c | 12 +++++++-----
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index bc37e66..32720db 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -10430,6 +10430,9 @@ expression, and vice versa.
 
 The default value of @var{x} and @var{y} is 0.
 
+If @var{x} or @var{y} evaluate to a negative number, they'll be changed
+so the input image is centered on the padded area.
+
 @item color
 Specify the color of the padded area. For the syntax of this option,
 check the "Color" section in the ffmpeg-utils manual.
diff --git a/libavfilter/vf_pad.c b/libavfilter/vf_pad.c
index 44a8fec..725dc29 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);



More information about the ffmpeg-cvslog mailing list