Before, drawtext filter deliberately altered given text coordinates if
text didn't fully fit on the picture. This breaks the use case of
scrolling large text, e.g. movie closing credits.
Add 'fix_bounds', to make it usable in such cases (by setting its value to 0).
Default behavior is not changed, and non-fitting text coords are fixed.
Note: ffmpeg.org version behaves as with fix_bounds=0, and does not have
an option to fix coords.
---
libavfilter/vf_drawtext.c | 17 +++++++++++------
1 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index 6edd123..57a3fe8 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -122,6 +122,7 @@ typedef struct {
short int draw_box; ///< draw box around text - true or false
int use_kerning; ///< font kerning is used - true/false
int tabsize; ///< tab size
+ int fix_bounds; ///< do we let it go out of frame bounds -
t/f
FT_Library library; ///< freetype font library handle
FT_Face face; ///< freetype font face handle
@@ -157,6 +158,8 @@ static const AVOption drawtext_options[]= {
{"shadowy", "set y", OFFSET(shadowy),
AV_OPT_TYPE_INT, {.dbl=0}, INT_MIN, INT_MAX },
{"tabsize", "set tab size", OFFSET(tabsize),
AV_OPT_TYPE_INT, {.dbl=4}, 0, INT_MAX },
{"draw", "if false do not draw", OFFSET(d_expr),
AV_OPT_TYPE_STRING, {.str="1"}, CHAR_MIN, CHAR_MAX },
+{"fix_bounds", "if true, check and fix text coords to avoid clipping",
+ OFFSET(fix_bounds),
AV_OPT_TYPE_INT, {.dbl=1}, 0, 1 },
/* FT_LOAD_* flags */
{"ft_load_flags", "set font loading flags for libfreetype",
OFFSET(ft_load_flags), AV_OPT_TYPE_FLAGS,
{.dbl=FT_LOAD_DEFAULT|FT_LOAD_RENDER}, 0, INT_MAX, 0, "ft_load_flags" },
@@ -828,12 +831,14 @@ static void start_frame(AVFilterLink *inlink,
AVFilterBufferRef *inpicref)
normalize_double(&dtext->x, dtext->var_values[VAR_X]);
normalize_double(&dtext->y, dtext->var_values[VAR_Y]);
- if (dtext->x < 0) dtext->x = 0;
- if (dtext->y < 0) dtext->y = 0;
- if ((unsigned)dtext->x + (unsigned)dtext->w > inlink->w)
- dtext->x = inlink->w - dtext->w;
- if ((unsigned)dtext->y + (unsigned)dtext->h > inlink->h)
- dtext->y = inlink->h - dtext->h;
+ if (dtext->fix_bounds) {
+ if (dtext->x < 0) dtext->x = 0;
+ if (dtext->y < 0) dtext->y = 0;
+ if ((unsigned)dtext->x + (unsigned)dtext->w > inlink->w)
+ dtext->x = inlink->w - dtext->w;
+ if ((unsigned)dtext->y + (unsigned)dtext->h > inlink->h)
+ dtext->y = inlink->h - dtext->h;
+ }
dtext->x &= ~((1 << dtext->hsub) - 1);
dtext->y &= ~((1 << dtext->vsub) - 1);
--
1.7.7
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel