diff options
author | Paul B Mahol <onemda@gmail.com> | 2017-08-27 17:11:40 +0200 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2017-08-27 17:13:52 +0200 |
commit | bf39f7eadc684ab291a6f42ee9a85a6c2d804bc7 (patch) | |
tree | 834256836c25b95e74cd16e7867e8fcf1aa0ff8a /libavfilter/vf_zoompan.c | |
parent | 2ce43274e39295e3965c51dcfaf802628a5929f9 (diff) | |
download | ffmpeg-bf39f7eadc684ab291a6f42ee9a85a6c2d804bc7.tar.gz |
avfilter/vf_zoompan: parse zoom,x and y expression during initialization
Fixes #6127.
Signed-off-by: Paul B Mahol <onemda@gmail.com>
Diffstat (limited to 'libavfilter/vf_zoompan.c')
-rw-r--r-- | libavfilter/vf_zoompan.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/libavfilter/vf_zoompan.c b/libavfilter/vf_zoompan.c index 6998441419..0857518217 100644 --- a/libavfilter/vf_zoompan.c +++ b/libavfilter/vf_zoompan.c @@ -81,6 +81,9 @@ typedef struct ZPcontext { char *x_expr_str; char *y_expr_str; char *duration_expr_str; + + AVExpr *zoom_expr, *x_expr, *y_expr; + int w, h; double x, y; double prev_zoom; @@ -123,6 +126,7 @@ static int config_output(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; ZPContext *s = ctx->priv; + int ret; outlink->w = s->w; outlink->h = s->h; @@ -130,6 +134,18 @@ static int config_output(AVFilterLink *outlink) outlink->frame_rate = s->framerate; s->desc = av_pix_fmt_desc_get(outlink->format); + ret = av_expr_parse(&s->zoom_expr, s->zoom_expr_str, var_names, NULL, NULL, NULL, NULL, 0, ctx); + if (ret < 0) + return ret; + + ret = av_expr_parse(&s->x_expr, s->x_expr_str, var_names, NULL, NULL, NULL, NULL, 0, ctx); + if (ret < 0) + return ret; + + ret = av_expr_parse(&s->y_expr, s->y_expr_str, var_names, NULL, NULL, NULL, NULL, 0, ctx); + if (ret < 0) + return ret; + return 0; } @@ -151,28 +167,22 @@ static int output_single_frame(AVFilterContext *ctx, AVFrame *in, double *var_va var_values[VAR_TIME] = pts * av_q2d(outlink->time_base); var_values[VAR_FRAME] = i; var_values[VAR_ON] = outlink->frame_count_in + 1; - if ((ret = av_expr_parse_and_eval(zoom, s->zoom_expr_str, - var_names, var_values, - NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) - return ret; + + *zoom = av_expr_eval(s->zoom_expr, var_values, NULL); *zoom = av_clipd(*zoom, 1, 10); var_values[VAR_ZOOM] = *zoom; w = in->width * (1.0 / *zoom); h = in->height * (1.0 / *zoom); - if ((ret = av_expr_parse_and_eval(dx, s->x_expr_str, - var_names, var_values, - NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) - return ret; + *dx = av_expr_eval(s->x_expr, var_values, NULL); + x = *dx = av_clipd(*dx, 0, FFMAX(in->width - w, 0)); var_values[VAR_X] = *dx; x &= ~((1 << s->desc->log2_chroma_w) - 1); - if ((ret = av_expr_parse_and_eval(dy, s->y_expr_str, - var_names, var_values, - NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) - return ret; + *dy = av_expr_eval(s->y_expr, var_values, NULL); + y = *dy = av_clipd(*dy, 0, FFMAX(in->height - h, 0)); var_values[VAR_Y] = *dy; y &= ~((1 << s->desc->log2_chroma_h) - 1); |