[FFmpeg-devel] [PATCH] Align overlaied video movie x/y and w/h sizes to chroma subsampling values.

Ronald S. Bultje rsbultje
Fri Jan 28 17:31:22 CET 2011


Hi,

On Thu, Jan 27, 2011 at 6:17 PM, Stefano Sabatini
<stefano.sabatini-lala at poste.it> wrote:
> Fix alignment bands when the input video size or position is not
> chroma-aligned.
> ---
> ?libavfilter/vf_overlay.c | ? 21 ++++++++++++---------
> ?1 files changed, 12 insertions(+), 9 deletions(-)
>
> diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c
> index a170e81..5e73da2 100644
> --- a/libavfilter/vf_overlay.c
> +++ b/libavfilter/vf_overlay.c
> @@ -58,7 +58,8 @@ enum var_name {
> ?#define OVERLAY 1
>
> ?typedef struct {
> - ? ?int x, y; ? ? ? ? ? ? ? ? ? ///< position of overlayed picture
> + ? ?int x, y; ? ? ? ? ? ? ? ? ? ///< chroma-aligned position of overlayed picture
> + ? ?int w, h; ? ? ? ? ? ? ? ? ? ///< chroma-aligned width and heigth of the overlaied video
>
> ? ? AVFilterBufferRef *overpicref;
>
> @@ -129,31 +130,33 @@ static int config_input_overlay(AVFilterLink *inlink)
> ? ? var_values[VAR_PHI] = M_PHI;
> ? ? var_values[VAR_PI ] = M_PI;
>
> + ? ?over->w = ctx->inputs[OVERLAY]->w & ~((1 << over->hsub) - 1);
> + ? ?over->h = ctx->inputs[OVERLAY]->h & ~((1 << over->vsub) - 1);
> +
> ? ? var_values[VAR_MAIN_W ? ] = var_values[VAR_MW] = ctx->inputs[MAIN ? ]->w;
> ? ? var_values[VAR_MAIN_H ? ] = var_values[VAR_MH] = ctx->inputs[MAIN ? ]->h;
> - ? ?var_values[VAR_OVERLAY_W] = var_values[VAR_OW] = ctx->inputs[OVERLAY]->w;
> - ? ?var_values[VAR_OVERLAY_H] = var_values[VAR_OH] = ctx->inputs[OVERLAY]->h;
> + ? ?var_values[VAR_OVERLAY_W] = var_values[VAR_OW] = over->w;
> + ? ?var_values[VAR_OVERLAY_H] = var_values[VAR_OH] = over->h;
>
> ? ? if ((ret = av_expr_parse_and_eval(&res, (expr = over->x_expr), var_names, var_values,
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
> ? ? ? ? goto fail;
> - ? ?over->x = res;
> + ? ?over->x = (int)res & ~((1 << over->hsub) - 1);
> ? ? if ((ret = av_expr_parse_and_eval(&res, (expr = over->y_expr), var_names, var_values,
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NULL, NULL, NULL, NULL, NULL, 0, ctx)))
> ? ? ? ? goto fail;
> - ? ?over->y = res;
> + ? ?over->y = (int)res & ~((1 << over->vsub) - 1);
> ? ? /* x may depend on y */
> ? ? if ((ret = av_expr_parse_and_eval(&res, (expr = over->x_expr), var_names, var_values,
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
> ? ? ? ? goto fail;
> - ? ?over->x = res;
> + ? ?over->x = (int)res & ~((1 << over->hsub) - 1);
>
> ? ? av_log(ctx, AV_LOG_INFO,
> ? ? ? ? ? ?"main w:%d h:%d fmt:%s overlay x:%d y:%d w:%d h:%d fmt:%s\n",
> ? ? ? ? ? ?ctx->inputs[MAIN]->w, ctx->inputs[MAIN]->h,
> ? ? ? ? ? ?av_pix_fmt_descriptors[ctx->inputs[MAIN]->format].name,
> - ? ? ? ? ? over->x, over->y,
> - ? ? ? ? ? ctx->inputs[OVERLAY]->w, ctx->inputs[OVERLAY]->h,
> + ? ? ? ? ? over->x, over->y, over->w, over->h,
> ? ? ? ? ? ?av_pix_fmt_descriptors[ctx->inputs[OVERLAY]->format].name);
>
> ? ? if (over->x < 0 || over->y < 0 ||
> @@ -328,7 +331,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
> ? ? ? ? !(over->x >= outpicref->video->w || over->y >= outpicref->video->h ||
> ? ? ? ? ? y+h < over->y || y >= over->y + over->overpicref->video->h)) {
> ? ? ? ? blend_slice(ctx, outpicref, over->overpicref, over->x, over->y,
> - ? ? ? ? ? ? ? ? ? ?over->overpicref->video->w, over->overpicref->video->h,
> + ? ? ? ? ? ? ? ? ? ?over->w, over->h,
> ? ? ? ? ? ? ? ? ? ? y, outpicref->video->w, h);
> ? ? }
> ? ? avfilter_draw_slice(outlink, y, h, slice_dir);
> --
> 1.7.2.3

OK with me. An alternative, possible slightly more accurate version of
this patch could mix chroma samples between overlay and background if
sizes are not chroma-aligned, but that's all nitpicking on the details
and I don't really care either way... We can always implement that
later if desired.

Ronald



More information about the ffmpeg-devel mailing list