[FFmpeg-devel] [PATCH] make width and height available as parameters in vf_scale
Stefano Sabatini
stefano.sabatini-lala
Thu Jul 1 02:06:09 CEST 2010
On date Wednesday 2010-05-19 14:00:31 -0700, Baptiste Coudurier encoded:
> Hi
>
> $subject.
>
> --
> Baptiste COUDURIER
> Key fingerprint 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
> FFmpeg maintainer http://www.ffmpeg.org
> Index: libavfilter/vf_scale.c
> ===================================================================
> --- libavfilter/vf_scale.c (revision 23157)
> +++ libavfilter/vf_scale.c (working copy)
> @@ -24,9 +24,22 @@
> */
>
> #include "avfilter.h"
> +#include "libavcodec/eval.h"
> #include "libavutil/pixdesc.h"
> #include "libswscale/swscale.h"
>
> +static const char *var_names[] = {
> + "w", ///< width of the main video
> + "h", ///< height of the main video
> + NULL
> +};
> +
> +enum var_name {
> + W,
> + H,
> + VARS_NB,
> +};
> +
> typedef struct {
> struct SwsContext *sws; ///< software scaler context
>
> @@ -41,6 +54,7 @@
> int hsub, vsub; ///< chroma subsampling
> int slice_y; ///< top of current output slice
> int input_is_pal; ///< set to 1 if the input format is paletted
> + char w_expr[255], h_expr[255];
> } ScaleContext;
>
> static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
> @@ -50,19 +64,12 @@
>
> scale->flags = SWS_BILINEAR;
> if (args){
> - sscanf(args, "%d:%d", &scale->w, &scale->h);
> + sscanf(args, "%255[^:]:%255[^:]", scale->w_expr, scale->h_expr);
> p= strstr(args,"flags=");
> if(p) scale->flags= strtoul(p+6, NULL, 0);
> + av_log(ctx, AV_LOG_INFO, "flags %#x\n", scale->flags);
Unrelated, also IIRC I added a similar log.
> }
>
> - /* sanity check params */
> - if (scale->w < -1 || scale->h < -1) {
> - av_log(ctx, AV_LOG_ERROR, "Size values less than -1 are not acceptable.\n");
> - return -1;
> - }
> - if (scale->w == -1 && scale->h == -1)
> - scale->w = scale->h = 0;
> -
> return 0;
> }
>
> @@ -110,6 +117,31 @@
> ScaleContext *scale = ctx->priv;
> int64_t w, h;
>
> + const char *error = NULL, *expr;
> + double var_values[VARS_NB];
> +
> + /* Finish the configuration by evaluating the expressions
> + now when both inputs are configured. */
> + var_values[W] = ctx->inputs[0]->w;
> + var_values[H] = ctx->inputs[0]->h;
> +
> + scale->w = ff_parse_and_eval_expr((expr = scale->w_expr), var_names, var_values,
> + NULL, NULL, NULL, NULL, NULL, &error);
> + if (error)
> + return -1;
> + scale->h = ff_parse_and_eval_expr((expr = scale->h_expr), var_names, var_values,
> + NULL, NULL, NULL, NULL, NULL, &error);
> + if (error)
> + return -1;
> +
> + /* sanity check params */
> + if (scale->w < -1 || scale->h < -1) {
> + av_log(ctx, AV_LOG_ERROR, "Size values less than -1 are not acceptable.\n");
> + return -1;
> + }
Should be updated to the new API and return AVERROR(EINVAL).
> + if (scale->w == -1 && scale->h == -1)
> + scale->w = scale->h = 0;
> +
> if (!(w = scale->w))
> w = inlink->w;
> if (!(h = scale->h))
Regards.
--
FFmpeg = Fast & Fancy Mastodontic Practical Epic Glue
More information about the ffmpeg-devel
mailing list