X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavfilter%2Fvf_drawtext.c;h=cca2cbcb88bb2e43c284b71a4838dd9ae9cb06ca;hb=936d18fb42bb1776f1b25e16b9d6a72846ee33ac;hp=f6151443bbb5c8ba61186ab71a119791de0a4d02;hpb=4aefe010e30861eb8cbe04aa47223bf64d207dce;p=ffmpeg diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index f6151443bbb..cca2cbcb88b 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -238,7 +238,7 @@ static const AVOption drawtext_options[]= { {"rate", "set rate (timecode only)", OFFSET(tc_rate), AV_OPT_TYPE_RATIONAL, {.dbl=0}, 0, INT_MAX, FLAGS}, {"reload", "reload text file for each frame", OFFSET(reload), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, { "alpha", "apply alpha while rendering", OFFSET(a_expr), AV_OPT_TYPE_STRING, { .str = "1" }, .flags = FLAGS }, - {"fix_bounds", "check and fix text coords to avoid clipping", OFFSET(fix_bounds), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS}, + {"fix_bounds", "check and fix text coords to avoid clipping", OFFSET(fix_bounds), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, {"start_number", "start frame number for n/frame_num variable", OFFSET(start_number), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS}, #if CONFIG_LIBFRIBIDI @@ -916,6 +916,14 @@ static int func_pts(AVFilterContext *ctx, AVBPrint *bp, sign = '-'; ms = -ms; } + if (argc >= 3) { + if (!strcmp(argv[2], "24HH")) { + ms %= 24 * 60 * 60 * 1000; + } else { + av_log(ctx, AV_LOG_ERROR, "Invalid argument '%s'\n", argv[2]); + return AVERROR(EINVAL); + } + } av_bprintf(bp, "%c%02d:%02d:%02d.%03d", sign, (int)(ms / (60 * 60 * 1000)), (int)(ms / (60 * 1000)) % 60, @@ -1390,6 +1398,7 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame, s->x = s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, &s->prng); s->y = s->var_values[VAR_Y] = av_expr_eval(s->y_pexpr, s->var_values, &s->prng); + /* It is necessary if x is expressed from y */ s->x = s->var_values[VAR_X] = av_expr_eval(s->x_pexpr, s->var_values, &s->prng); update_alpha(s); @@ -1398,8 +1407,34 @@ static int draw_text(AVFilterContext *ctx, AVFrame *frame, update_color_with_alpha(s, &bordercolor, s->bordercolor); update_color_with_alpha(s, &boxcolor , s->boxcolor ); - box_w = FFMIN(width - 1 , max_text_line_w); - box_h = FFMIN(height - 1, y + s->max_glyph_h); + box_w = max_text_line_w; + box_h = y + s->max_glyph_h; + + if (s->fix_bounds) { + + /* calculate footprint of text effects */ + int boxoffset = s->draw_box ? FFMAX(s->boxborderw, 0) : 0; + int borderoffset = s->borderw ? FFMAX(s->borderw, 0) : 0; + + int offsetleft = FFMAX3(boxoffset, borderoffset, + (s->shadowx < 0 ? FFABS(s->shadowx) : 0)); + int offsettop = FFMAX3(boxoffset, borderoffset, + (s->shadowy < 0 ? FFABS(s->shadowy) : 0)); + + int offsetright = FFMAX3(boxoffset, borderoffset, + (s->shadowx > 0 ? s->shadowx : 0)); + int offsetbottom = FFMAX3(boxoffset, borderoffset, + (s->shadowy > 0 ? s->shadowy : 0)); + + + if (s->x - offsetleft < 0) s->x = offsetleft; + if (s->y - offsettop < 0) s->y = offsettop; + + if (s->x + box_w + offsetright > width) + s->x = FFMAX(width - box_w - offsetright, 0); + if (s->y + box_h + offsetbottom > height) + s->y = FFMAX(height - box_h - offsetbottom, 0); + } /* draw box */ if (s->draw_box)