* [FFmpeg-devel] [PATCH] libavfilter/vf_drawtext: add letter_spacing as an evaluated parameter
@ 2023-06-19 16:33 Mark Ren
2023-06-19 16:39 ` Paul B Mahol
0 siblings, 1 reply; 5+ messages in thread
From: Mark Ren @ 2023-06-19 16:33 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Mark Ren
When enabled it will add pixels (or subtract if given a negative value) between each letters,
set use_kerning to false,
and add the pixels to text_w.
Signed-off-by: Mark Ren <mark.ren77@gmail.com>
---
libavfilter/vf_drawtext.c | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index 71ab851462..ec8313820d 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -183,6 +183,7 @@ typedef struct DrawTextContext {
unsigned int fontsize; ///< font size to use
unsigned int default_fontsize; ///< default font size to use
+ int letter_spacing; ///< letter spacing in pixels
int line_spacing; ///< lines spacing in pixels
short int draw_box; ///< draw box around text - true or false
int boxborderw; ///< box border width
@@ -208,6 +209,8 @@ typedef struct DrawTextContext {
char *a_expr;
AVExpr *a_pexpr;
int alpha;
+ char* letter_spacing_expr; ///< expression for letter spacing
+ AVExpr* letter_spacing_pexpr; ///< parsed expression for letter spacing
AVLFG prng; ///< random
char *tc_opt_string; ///< specified timecode option string
AVRational tc_rate; ///< frame rate for timecode
@@ -237,6 +240,7 @@ static const AVOption drawtext_options[]= {
{"shadowcolor", "set shadow color", OFFSET(shadowcolor.rgba), AV_OPT_TYPE_COLOR, {.str="black"}, 0, 0, FLAGS},
{"box", "set box", OFFSET(draw_box), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 , FLAGS},
{"boxborderw", "set box border width", OFFSET(boxborderw), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX , FLAGS},
+ {"letter_spacing", "set letter spacing in pixels", OFFSET(letter_spacing_expr), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS},
{"line_spacing", "set line spacing in pixels", OFFSET(line_spacing), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX,FLAGS},
{"fontsize", "set font size", OFFSET(fontsize_expr), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0 , FLAGS},
{"x", "set x expression", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS},
@@ -812,7 +816,7 @@ static av_cold int init(AVFilterContext *ctx)
FT_STROKER_LINEJOIN_ROUND, 0);
}
- s->use_kerning = FT_HAS_KERNING(s->face);
+ s->use_kerning = FT_HAS_KERNING(s->face) && !s->letter_spacing;
/* load the fallback glyph with code 0 */
load_glyph(ctx, NULL, 0);
@@ -857,8 +861,9 @@ static av_cold void uninit(AVFilterContext *ctx)
av_expr_free(s->y_pexpr);
av_expr_free(s->a_pexpr);
av_expr_free(s->fontsize_pexpr);
+ av_expr_free(s->letter_spacing_pexpr);
- s->x_pexpr = s->y_pexpr = s->a_pexpr = s->fontsize_pexpr = NULL;
+ s->x_pexpr = s->y_pexpr = s->a_pexpr = s->fontsize_pexpr = s->letter_spacing_pexpr = NULL;
av_freep(&s->positions);
s->nb_positions = 0;
@@ -903,13 +908,16 @@ static int config_input(AVFilterLink *inlink)
av_expr_free(s->x_pexpr);
av_expr_free(s->y_pexpr);
av_expr_free(s->a_pexpr);
- s->x_pexpr = s->y_pexpr = s->a_pexpr = NULL;
+ av_expr_free(s->letter_spacing_pexpr);
+ s->x_pexpr = s->y_pexpr = s->a_pexpr = s->letter_spacing_pexpr = NULL;
if ((ret = av_expr_parse(&s->x_pexpr, expr = s->x_expr, var_names,
NULL, NULL, fun2_names, fun2, 0, ctx)) < 0 ||
(ret = av_expr_parse(&s->y_pexpr, expr = s->y_expr, var_names,
NULL, NULL, fun2_names, fun2, 0, ctx)) < 0 ||
(ret = av_expr_parse(&s->a_pexpr, expr = s->a_expr, var_names,
+ NULL, NULL, fun2_names, fun2, 0, ctx)) < 0 ||
+ (ret = av_expr_parse(&s->letter_spacing_pexpr, expr = s->letter_spacing_expr, var_names,
NULL, NULL, fun2_names, fun2, 0, ctx)) < 0) {
av_log(ctx, AV_LOG_ERROR, "Failed to parse expression: %s \n", expr);
return AVERROR(EINVAL);
@@ -1525,6 +1533,9 @@ continue_on_invalid2:
dummy.fontsize = s->fontsize;
glyph = av_tree_find(s->glyphs, &dummy, glyph_cmp, NULL);
+ /* letter spacing */
+ x += s->letter_spacing;
+
/* kerning */
if (s->use_kerning && prev_glyph && glyph->code) {
FT_Get_Kerning(s->face, prev_glyph->code, glyph->code,
@@ -1539,7 +1550,12 @@ continue_on_invalid2:
else x += glyph->advance;
}
- max_text_line_w = FFMAX(x, max_text_line_w);
+ s->letter_spacing = av_expr_eval(s->letter_spacing_pexpr, s->var_values, &s->prng);
+ if (s->letter_spacing < 0) {
+ max_text_line_w = x+ s->letter_spacing;
+ } else {
+ max_text_line_w = FFMAX(x, max_text_line_w) + s->letter_spacing;
+ }
s->var_values[VAR_TW] = s->var_values[VAR_TEXT_W] = max_text_line_w;
s->var_values[VAR_TH] = s->var_values[VAR_TEXT_H] = y + s->max_glyph_h;
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [FFmpeg-devel] [PATCH] libavfilter/vf_drawtext: add letter_spacing as an evaluated parameter
2023-06-19 16:33 [FFmpeg-devel] [PATCH] libavfilter/vf_drawtext: add letter_spacing as an evaluated parameter Mark Ren
@ 2023-06-19 16:39 ` Paul B Mahol
2023-06-19 17:56 ` Mark Ren
0 siblings, 1 reply; 5+ messages in thread
From: Paul B Mahol @ 2023-06-19 16:39 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Mark Ren
On Mon, Jun 19, 2023 at 6:34 PM Mark Ren <mark.ren77@gmail.com> wrote:
> When enabled it will add pixels (or subtract if given a negative value)
> between each letters,
> set use_kerning to false,
> and add the pixels to text_w.
>
Conflicts with big drawtext filter set that will be pushed soon.
>
> Signed-off-by: Mark Ren <mark.ren77@gmail.com>
> ---
> libavfilter/vf_drawtext.c | 24 ++++++++++++++++++++----
> 1 file changed, 20 insertions(+), 4 deletions(-)
>
> diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
> index 71ab851462..ec8313820d 100644
> --- a/libavfilter/vf_drawtext.c
> +++ b/libavfilter/vf_drawtext.c
> @@ -183,6 +183,7 @@ typedef struct DrawTextContext {
> unsigned int fontsize; ///< font size to use
> unsigned int default_fontsize; ///< default font size to use
>
> + int letter_spacing; ///< letter spacing in pixels
> int line_spacing; ///< lines spacing in pixels
> short int draw_box; ///< draw box around text - true or
> false
> int boxborderw; ///< box border width
> @@ -208,6 +209,8 @@ typedef struct DrawTextContext {
> char *a_expr;
> AVExpr *a_pexpr;
> int alpha;
> + char* letter_spacing_expr; ///< expression for letter spacing
> + AVExpr* letter_spacing_pexpr; ///< parsed expression for letter
> spacing
> AVLFG prng; ///< random
> char *tc_opt_string; ///< specified timecode option string
> AVRational tc_rate; ///< frame rate for timecode
> @@ -237,6 +240,7 @@ static const AVOption drawtext_options[]= {
> {"shadowcolor", "set shadow color", OFFSET(shadowcolor.rgba),
> AV_OPT_TYPE_COLOR, {.str="black"}, 0, 0, FLAGS},
> {"box", "set box", OFFSET(draw_box),
> AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 , FLAGS},
> {"boxborderw", "set box border width", OFFSET(boxborderw),
> AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX , FLAGS},
> + {"letter_spacing", "set letter spacing in pixels",
> OFFSET(letter_spacing_expr), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS},
> {"line_spacing", "set line spacing in pixels",
> OFFSET(line_spacing), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN,
> INT_MAX,FLAGS},
> {"fontsize", "set font size", OFFSET(fontsize_expr),
> AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0 , FLAGS},
> {"x", "set x expression", OFFSET(x_expr),
> AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS},
> @@ -812,7 +816,7 @@ static av_cold int init(AVFilterContext *ctx)
> FT_STROKER_LINEJOIN_ROUND, 0);
> }
>
> - s->use_kerning = FT_HAS_KERNING(s->face);
> + s->use_kerning = FT_HAS_KERNING(s->face) && !s->letter_spacing;
>
> /* load the fallback glyph with code 0 */
> load_glyph(ctx, NULL, 0);
> @@ -857,8 +861,9 @@ static av_cold void uninit(AVFilterContext *ctx)
> av_expr_free(s->y_pexpr);
> av_expr_free(s->a_pexpr);
> av_expr_free(s->fontsize_pexpr);
> + av_expr_free(s->letter_spacing_pexpr);
>
> - s->x_pexpr = s->y_pexpr = s->a_pexpr = s->fontsize_pexpr = NULL;
> + s->x_pexpr = s->y_pexpr = s->a_pexpr = s->fontsize_pexpr =
> s->letter_spacing_pexpr = NULL;
>
> av_freep(&s->positions);
> s->nb_positions = 0;
> @@ -903,13 +908,16 @@ static int config_input(AVFilterLink *inlink)
> av_expr_free(s->x_pexpr);
> av_expr_free(s->y_pexpr);
> av_expr_free(s->a_pexpr);
> - s->x_pexpr = s->y_pexpr = s->a_pexpr = NULL;
> + av_expr_free(s->letter_spacing_pexpr);
> + s->x_pexpr = s->y_pexpr = s->a_pexpr = s->letter_spacing_pexpr = NULL;
>
> if ((ret = av_expr_parse(&s->x_pexpr, expr = s->x_expr, var_names,
> NULL, NULL, fun2_names, fun2, 0, ctx)) < 0 ||
> (ret = av_expr_parse(&s->y_pexpr, expr = s->y_expr, var_names,
> NULL, NULL, fun2_names, fun2, 0, ctx)) < 0 ||
> (ret = av_expr_parse(&s->a_pexpr, expr = s->a_expr, var_names,
> + NULL, NULL, fun2_names, fun2, 0, ctx)) < 0 ||
> + (ret = av_expr_parse(&s->letter_spacing_pexpr, expr =
> s->letter_spacing_expr, var_names,
> NULL, NULL, fun2_names, fun2, 0, ctx)) < 0) {
> av_log(ctx, AV_LOG_ERROR, "Failed to parse expression: %s \n",
> expr);
> return AVERROR(EINVAL);
> @@ -1525,6 +1533,9 @@ continue_on_invalid2:
> dummy.fontsize = s->fontsize;
> glyph = av_tree_find(s->glyphs, &dummy, glyph_cmp, NULL);
>
> + /* letter spacing */
> + x += s->letter_spacing;
> +
> /* kerning */
> if (s->use_kerning && prev_glyph && glyph->code) {
> FT_Get_Kerning(s->face, prev_glyph->code, glyph->code,
> @@ -1539,7 +1550,12 @@ continue_on_invalid2:
> else x += glyph->advance;
> }
>
> - max_text_line_w = FFMAX(x, max_text_line_w);
> + s->letter_spacing = av_expr_eval(s->letter_spacing_pexpr,
> s->var_values, &s->prng);
> + if (s->letter_spacing < 0) {
> + max_text_line_w = x+ s->letter_spacing;
> + } else {
> + max_text_line_w = FFMAX(x, max_text_line_w) + s->letter_spacing;
> + }
>
> s->var_values[VAR_TW] = s->var_values[VAR_TEXT_W] = max_text_line_w;
> s->var_values[VAR_TH] = s->var_values[VAR_TEXT_H] = y +
> s->max_glyph_h;
> --
> 2.40.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [FFmpeg-devel] [PATCH] libavfilter/vf_drawtext: add letter_spacing as an evaluated parameter
2023-06-19 16:39 ` Paul B Mahol
@ 2023-06-19 17:56 ` Mark Ren
2023-06-20 14:27 ` Francesco Carusi
0 siblings, 1 reply; 5+ messages in thread
From: Mark Ren @ 2023-06-19 17:56 UTC (permalink / raw)
To: Paul B Mahol; +Cc: FFmpeg development discussions and patches
Ah alright I see. When might that push come through and is there somewhere
I can look at the kind of changes in the meantime?
On Mon, Jun 19, 2023 at 12:39 PM Paul B Mahol <onemda@gmail.com> wrote:
>
>
> On Mon, Jun 19, 2023 at 6:34 PM Mark Ren <mark.ren77@gmail.com> wrote:
>
>> When enabled it will add pixels (or subtract if given a negative value)
>> between each letters,
>> set use_kerning to false,
>> and add the pixels to text_w.
>>
>
> Conflicts with big drawtext filter set that will be pushed soon.
>
>
>>
>> Signed-off-by: Mark Ren <mark.ren77@gmail.com>
>> ---
>> libavfilter/vf_drawtext.c | 24 ++++++++++++++++++++----
>> 1 file changed, 20 insertions(+), 4 deletions(-)
>>
>> diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
>> index 71ab851462..ec8313820d 100644
>> --- a/libavfilter/vf_drawtext.c
>> +++ b/libavfilter/vf_drawtext.c
>> @@ -183,6 +183,7 @@ typedef struct DrawTextContext {
>> unsigned int fontsize; ///< font size to use
>> unsigned int default_fontsize; ///< default font size to use
>>
>> + int letter_spacing; ///< letter spacing in pixels
>> int line_spacing; ///< lines spacing in pixels
>> short int draw_box; ///< draw box around text - true or
>> false
>> int boxborderw; ///< box border width
>> @@ -208,6 +209,8 @@ typedef struct DrawTextContext {
>> char *a_expr;
>> AVExpr *a_pexpr;
>> int alpha;
>> + char* letter_spacing_expr; ///< expression for letter spacing
>> + AVExpr* letter_spacing_pexpr; ///< parsed expression for letter
>> spacing
>> AVLFG prng; ///< random
>> char *tc_opt_string; ///< specified timecode option string
>> AVRational tc_rate; ///< frame rate for timecode
>> @@ -237,6 +240,7 @@ static const AVOption drawtext_options[]= {
>> {"shadowcolor", "set shadow color", OFFSET(shadowcolor.rgba),
>> AV_OPT_TYPE_COLOR, {.str="black"}, 0, 0, FLAGS},
>> {"box", "set box", OFFSET(draw_box),
>> AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 , FLAGS},
>> {"boxborderw", "set box border width", OFFSET(boxborderw),
>> AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX , FLAGS},
>> + {"letter_spacing", "set letter spacing in pixels",
>> OFFSET(letter_spacing_expr), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS},
>> {"line_spacing", "set line spacing in pixels",
>> OFFSET(line_spacing), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN,
>> INT_MAX,FLAGS},
>> {"fontsize", "set font size", OFFSET(fontsize_expr),
>> AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0 , FLAGS},
>> {"x", "set x expression", OFFSET(x_expr),
>> AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS},
>> @@ -812,7 +816,7 @@ static av_cold int init(AVFilterContext *ctx)
>> FT_STROKER_LINEJOIN_ROUND, 0);
>> }
>>
>> - s->use_kerning = FT_HAS_KERNING(s->face);
>> + s->use_kerning = FT_HAS_KERNING(s->face) && !s->letter_spacing;
>>
>> /* load the fallback glyph with code 0 */
>> load_glyph(ctx, NULL, 0);
>> @@ -857,8 +861,9 @@ static av_cold void uninit(AVFilterContext *ctx)
>> av_expr_free(s->y_pexpr);
>> av_expr_free(s->a_pexpr);
>> av_expr_free(s->fontsize_pexpr);
>> + av_expr_free(s->letter_spacing_pexpr);
>>
>> - s->x_pexpr = s->y_pexpr = s->a_pexpr = s->fontsize_pexpr = NULL;
>> + s->x_pexpr = s->y_pexpr = s->a_pexpr = s->fontsize_pexpr =
>> s->letter_spacing_pexpr = NULL;
>>
>> av_freep(&s->positions);
>> s->nb_positions = 0;
>> @@ -903,13 +908,16 @@ static int config_input(AVFilterLink *inlink)
>> av_expr_free(s->x_pexpr);
>> av_expr_free(s->y_pexpr);
>> av_expr_free(s->a_pexpr);
>> - s->x_pexpr = s->y_pexpr = s->a_pexpr = NULL;
>> + av_expr_free(s->letter_spacing_pexpr);
>> + s->x_pexpr = s->y_pexpr = s->a_pexpr = s->letter_spacing_pexpr =
>> NULL;
>>
>> if ((ret = av_expr_parse(&s->x_pexpr, expr = s->x_expr, var_names,
>> NULL, NULL, fun2_names, fun2, 0, ctx)) < 0
>> ||
>> (ret = av_expr_parse(&s->y_pexpr, expr = s->y_expr, var_names,
>> NULL, NULL, fun2_names, fun2, 0, ctx)) < 0
>> ||
>> (ret = av_expr_parse(&s->a_pexpr, expr = s->a_expr, var_names,
>> + NULL, NULL, fun2_names, fun2, 0, ctx)) < 0
>> ||
>> + (ret = av_expr_parse(&s->letter_spacing_pexpr, expr =
>> s->letter_spacing_expr, var_names,
>> NULL, NULL, fun2_names, fun2, 0, ctx)) < 0)
>> {
>> av_log(ctx, AV_LOG_ERROR, "Failed to parse expression: %s \n",
>> expr);
>> return AVERROR(EINVAL);
>> @@ -1525,6 +1533,9 @@ continue_on_invalid2:
>> dummy.fontsize = s->fontsize;
>> glyph = av_tree_find(s->glyphs, &dummy, glyph_cmp, NULL);
>>
>> + /* letter spacing */
>> + x += s->letter_spacing;
>> +
>> /* kerning */
>> if (s->use_kerning && prev_glyph && glyph->code) {
>> FT_Get_Kerning(s->face, prev_glyph->code, glyph->code,
>> @@ -1539,7 +1550,12 @@ continue_on_invalid2:
>> else x += glyph->advance;
>> }
>>
>> - max_text_line_w = FFMAX(x, max_text_line_w);
>> + s->letter_spacing = av_expr_eval(s->letter_spacing_pexpr,
>> s->var_values, &s->prng);
>> + if (s->letter_spacing < 0) {
>> + max_text_line_w = x+ s->letter_spacing;
>> + } else {
>> + max_text_line_w = FFMAX(x, max_text_line_w) + s->letter_spacing;
>> + }
>>
>> s->var_values[VAR_TW] = s->var_values[VAR_TEXT_W] = max_text_line_w;
>> s->var_values[VAR_TH] = s->var_values[VAR_TEXT_H] = y +
>> s->max_glyph_h;
>> --
>> 2.40.1
>>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>>
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [FFmpeg-devel] [PATCH] libavfilter/vf_drawtext: add letter_spacing as an evaluated parameter
2023-06-19 17:56 ` Mark Ren
@ 2023-06-20 14:27 ` Francesco Carusi
2023-06-20 15:57 ` Paul B Mahol
0 siblings, 1 reply; 5+ messages in thread
From: Francesco Carusi @ 2023-06-20 14:27 UTC (permalink / raw)
To: ffmpeg-devel
You can find an overview of the changes here:
https://github.com/yethie/FFmpeg/blob/master/drawtext/CHANGES.md
and the new code here:
https://github.com/yethie/FFmpeg/blob/master/libavfilter/vf_drawtext.c
On 19/06/2023 19:56, Mark Ren wrote:
> Ah alright I see. When might that push come through and is there somewhere
> I can look at the kind of changes in the meantime?
>
> On Mon, Jun 19, 2023 at 12:39 PM Paul B Mahol <onemda@gmail.com> wrote:
>
>>
>> On Mon, Jun 19, 2023 at 6:34 PM Mark Ren <mark.ren77@gmail.com> wrote:
>>
>>> When enabled it will add pixels (or subtract if given a negative value)
>>> between each letters,
>>> set use_kerning to false,
>>> and add the pixels to text_w.
>>>
>> Conflicts with big drawtext filter set that will be pushed soon.
>>
>>
>>> Signed-off-by: Mark Ren <mark.ren77@gmail.com>
>>> ---
>>> libavfilter/vf_drawtext.c | 24 ++++++++++++++++++++----
>>> 1 file changed, 20 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
>>> index 71ab851462..ec8313820d 100644
>>> --- a/libavfilter/vf_drawtext.c
>>> +++ b/libavfilter/vf_drawtext.c
>>> @@ -183,6 +183,7 @@ typedef struct DrawTextContext {
>>> unsigned int fontsize; ///< font size to use
>>> unsigned int default_fontsize; ///< default font size to use
>>>
>>> + int letter_spacing; ///< letter spacing in pixels
>>> int line_spacing; ///< lines spacing in pixels
>>> short int draw_box; ///< draw box around text - true or
>>> false
>>> int boxborderw; ///< box border width
>>> @@ -208,6 +209,8 @@ typedef struct DrawTextContext {
>>> char *a_expr;
>>> AVExpr *a_pexpr;
>>> int alpha;
>>> + char* letter_spacing_expr; ///< expression for letter spacing
>>> + AVExpr* letter_spacing_pexpr; ///< parsed expression for letter
>>> spacing
>>> AVLFG prng; ///< random
>>> char *tc_opt_string; ///< specified timecode option string
>>> AVRational tc_rate; ///< frame rate for timecode
>>> @@ -237,6 +240,7 @@ static const AVOption drawtext_options[]= {
>>> {"shadowcolor", "set shadow color", OFFSET(shadowcolor.rgba),
>>> AV_OPT_TYPE_COLOR, {.str="black"}, 0, 0, FLAGS},
>>> {"box", "set box", OFFSET(draw_box),
>>> AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 , FLAGS},
>>> {"boxborderw", "set box border width", OFFSET(boxborderw),
>>> AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX , FLAGS},
>>> + {"letter_spacing", "set letter spacing in pixels",
>>> OFFSET(letter_spacing_expr), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS},
>>> {"line_spacing", "set line spacing in pixels",
>>> OFFSET(line_spacing), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN,
>>> INT_MAX,FLAGS},
>>> {"fontsize", "set font size", OFFSET(fontsize_expr),
>>> AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0 , FLAGS},
>>> {"x", "set x expression", OFFSET(x_expr),
>>> AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS},
>>> @@ -812,7 +816,7 @@ static av_cold int init(AVFilterContext *ctx)
>>> FT_STROKER_LINEJOIN_ROUND, 0);
>>> }
>>>
>>> - s->use_kerning = FT_HAS_KERNING(s->face);
>>> + s->use_kerning = FT_HAS_KERNING(s->face) && !s->letter_spacing;
>>>
>>> /* load the fallback glyph with code 0 */
>>> load_glyph(ctx, NULL, 0);
>>> @@ -857,8 +861,9 @@ static av_cold void uninit(AVFilterContext *ctx)
>>> av_expr_free(s->y_pexpr);
>>> av_expr_free(s->a_pexpr);
>>> av_expr_free(s->fontsize_pexpr);
>>> + av_expr_free(s->letter_spacing_pexpr);
>>>
>>> - s->x_pexpr = s->y_pexpr = s->a_pexpr = s->fontsize_pexpr = NULL;
>>> + s->x_pexpr = s->y_pexpr = s->a_pexpr = s->fontsize_pexpr =
>>> s->letter_spacing_pexpr = NULL;
>>>
>>> av_freep(&s->positions);
>>> s->nb_positions = 0;
>>> @@ -903,13 +908,16 @@ static int config_input(AVFilterLink *inlink)
>>> av_expr_free(s->x_pexpr);
>>> av_expr_free(s->y_pexpr);
>>> av_expr_free(s->a_pexpr);
>>> - s->x_pexpr = s->y_pexpr = s->a_pexpr = NULL;
>>> + av_expr_free(s->letter_spacing_pexpr);
>>> + s->x_pexpr = s->y_pexpr = s->a_pexpr = s->letter_spacing_pexpr =
>>> NULL;
>>>
>>> if ((ret = av_expr_parse(&s->x_pexpr, expr = s->x_expr, var_names,
>>> NULL, NULL, fun2_names, fun2, 0, ctx)) < 0
>>> ||
>>> (ret = av_expr_parse(&s->y_pexpr, expr = s->y_expr, var_names,
>>> NULL, NULL, fun2_names, fun2, 0, ctx)) < 0
>>> ||
>>> (ret = av_expr_parse(&s->a_pexpr, expr = s->a_expr, var_names,
>>> + NULL, NULL, fun2_names, fun2, 0, ctx)) < 0
>>> ||
>>> + (ret = av_expr_parse(&s->letter_spacing_pexpr, expr =
>>> s->letter_spacing_expr, var_names,
>>> NULL, NULL, fun2_names, fun2, 0, ctx)) < 0)
>>> {
>>> av_log(ctx, AV_LOG_ERROR, "Failed to parse expression: %s \n",
>>> expr);
>>> return AVERROR(EINVAL);
>>> @@ -1525,6 +1533,9 @@ continue_on_invalid2:
>>> dummy.fontsize = s->fontsize;
>>> glyph = av_tree_find(s->glyphs, &dummy, glyph_cmp, NULL);
>>>
>>> + /* letter spacing */
>>> + x += s->letter_spacing;
>>> +
>>> /* kerning */
>>> if (s->use_kerning && prev_glyph && glyph->code) {
>>> FT_Get_Kerning(s->face, prev_glyph->code, glyph->code,
>>> @@ -1539,7 +1550,12 @@ continue_on_invalid2:
>>> else x += glyph->advance;
>>> }
>>>
>>> - max_text_line_w = FFMAX(x, max_text_line_w);
>>> + s->letter_spacing = av_expr_eval(s->letter_spacing_pexpr,
>>> s->var_values, &s->prng);
>>> + if (s->letter_spacing < 0) {
>>> + max_text_line_w = x+ s->letter_spacing;
>>> + } else {
>>> + max_text_line_w = FFMAX(x, max_text_line_w) + s->letter_spacing;
>>> + }
>>>
>>> s->var_values[VAR_TW] = s->var_values[VAR_TEXT_W] = max_text_line_w;
>>> s->var_values[VAR_TH] = s->var_values[VAR_TEXT_H] = y +
>>> s->max_glyph_h;
>>> --
>>> 2.40.1
>>>
>>> _______________________________________________
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel@ffmpeg.org
>>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>>
>>> To unsubscribe, visit link above, or email
>>> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>>>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [FFmpeg-devel] [PATCH] libavfilter/vf_drawtext: add letter_spacing as an evaluated parameter
2023-06-20 14:27 ` Francesco Carusi
@ 2023-06-20 15:57 ` Paul B Mahol
0 siblings, 0 replies; 5+ messages in thread
From: Paul B Mahol @ 2023-06-20 15:57 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Tue, Jun 20, 2023 at 4:27 PM Francesco Carusi <klimklim@tiscali.it>
wrote:
> You can find an overview of the changes here:
>
> https://github.com/yethie/FFmpeg/blob/master/drawtext/CHANGES.md
>
> and the new code here:
>
> https://github.com/yethie/FFmpeg/blob/master/libavfilter/vf_drawtext.c
This have been already merged, with some minor changes.
>
>
>
> On 19/06/2023 19:56, Mark Ren wrote:
> > Ah alright I see. When might that push come through and is there
> somewhere
> > I can look at the kind of changes in the meantime?
> >
> > On Mon, Jun 19, 2023 at 12:39 PM Paul B Mahol <onemda@gmail.com> wrote:
> >
> >>
> >> On Mon, Jun 19, 2023 at 6:34 PM Mark Ren <mark.ren77@gmail.com> wrote:
> >>
> >>> When enabled it will add pixels (or subtract if given a negative value)
> >>> between each letters,
> >>> set use_kerning to false,
> >>> and add the pixels to text_w.
> >>>
> >> Conflicts with big drawtext filter set that will be pushed soon.
> >>
> >>
> >>> Signed-off-by: Mark Ren <mark.ren77@gmail.com>
> >>> ---
> >>> libavfilter/vf_drawtext.c | 24 ++++++++++++++++++++----
> >>> 1 file changed, 20 insertions(+), 4 deletions(-)
> >>>
> >>> diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
> >>> index 71ab851462..ec8313820d 100644
> >>> --- a/libavfilter/vf_drawtext.c
> >>> +++ b/libavfilter/vf_drawtext.c
> >>> @@ -183,6 +183,7 @@ typedef struct DrawTextContext {
> >>> unsigned int fontsize; ///< font size to use
> >>> unsigned int default_fontsize; ///< default font size to use
> >>>
> >>> + int letter_spacing; ///< letter spacing in pixels
> >>> int line_spacing; ///< lines spacing in pixels
> >>> short int draw_box; ///< draw box around text - true
> or
> >>> false
> >>> int boxborderw; ///< box border width
> >>> @@ -208,6 +209,8 @@ typedef struct DrawTextContext {
> >>> char *a_expr;
> >>> AVExpr *a_pexpr;
> >>> int alpha;
> >>> + char* letter_spacing_expr; ///< expression for letter spacing
> >>> + AVExpr* letter_spacing_pexpr; ///< parsed expression for letter
> >>> spacing
> >>> AVLFG prng; ///< random
> >>> char *tc_opt_string; ///< specified timecode option
> string
> >>> AVRational tc_rate; ///< frame rate for timecode
> >>> @@ -237,6 +240,7 @@ static const AVOption drawtext_options[]= {
> >>> {"shadowcolor", "set shadow color", OFFSET(shadowcolor.rgba),
> >>> AV_OPT_TYPE_COLOR, {.str="black"}, 0, 0, FLAGS},
> >>> {"box", "set box", OFFSET(draw_box),
> >>> AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 , FLAGS},
> >>> {"boxborderw", "set box border width", OFFSET(boxborderw),
> >>> AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX , FLAGS},
> >>> + {"letter_spacing", "set letter spacing in pixels",
> >>> OFFSET(letter_spacing_expr), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0,
> FLAGS},
> >>> {"line_spacing", "set line spacing in pixels",
> >>> OFFSET(line_spacing), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN,
> >>> INT_MAX,FLAGS},
> >>> {"fontsize", "set font size", OFFSET(fontsize_expr),
> >>> AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0 , FLAGS},
> >>> {"x", "set x expression", OFFSET(x_expr),
> >>> AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS},
> >>> @@ -812,7 +816,7 @@ static av_cold int init(AVFilterContext *ctx)
> >>> FT_STROKER_LINEJOIN_ROUND, 0);
> >>> }
> >>>
> >>> - s->use_kerning = FT_HAS_KERNING(s->face);
> >>> + s->use_kerning = FT_HAS_KERNING(s->face) && !s->letter_spacing;
> >>>
> >>> /* load the fallback glyph with code 0 */
> >>> load_glyph(ctx, NULL, 0);
> >>> @@ -857,8 +861,9 @@ static av_cold void uninit(AVFilterContext *ctx)
> >>> av_expr_free(s->y_pexpr);
> >>> av_expr_free(s->a_pexpr);
> >>> av_expr_free(s->fontsize_pexpr);
> >>> + av_expr_free(s->letter_spacing_pexpr);
> >>>
> >>> - s->x_pexpr = s->y_pexpr = s->a_pexpr = s->fontsize_pexpr = NULL;
> >>> + s->x_pexpr = s->y_pexpr = s->a_pexpr = s->fontsize_pexpr =
> >>> s->letter_spacing_pexpr = NULL;
> >>>
> >>> av_freep(&s->positions);
> >>> s->nb_positions = 0;
> >>> @@ -903,13 +908,16 @@ static int config_input(AVFilterLink *inlink)
> >>> av_expr_free(s->x_pexpr);
> >>> av_expr_free(s->y_pexpr);
> >>> av_expr_free(s->a_pexpr);
> >>> - s->x_pexpr = s->y_pexpr = s->a_pexpr = NULL;
> >>> + av_expr_free(s->letter_spacing_pexpr);
> >>> + s->x_pexpr = s->y_pexpr = s->a_pexpr = s->letter_spacing_pexpr =
> >>> NULL;
> >>>
> >>> if ((ret = av_expr_parse(&s->x_pexpr, expr = s->x_expr,
> var_names,
> >>> NULL, NULL, fun2_names, fun2, 0, ctx))
> < 0
> >>> ||
> >>> (ret = av_expr_parse(&s->y_pexpr, expr = s->y_expr,
> var_names,
> >>> NULL, NULL, fun2_names, fun2, 0, ctx))
> < 0
> >>> ||
> >>> (ret = av_expr_parse(&s->a_pexpr, expr = s->a_expr,
> var_names,
> >>> + NULL, NULL, fun2_names, fun2, 0, ctx)) <
> 0
> >>> ||
> >>> + (ret = av_expr_parse(&s->letter_spacing_pexpr, expr =
> >>> s->letter_spacing_expr, var_names,
> >>> NULL, NULL, fun2_names, fun2, 0, ctx))
> < 0)
> >>> {
> >>> av_log(ctx, AV_LOG_ERROR, "Failed to parse expression: %s
> \n",
> >>> expr);
> >>> return AVERROR(EINVAL);
> >>> @@ -1525,6 +1533,9 @@ continue_on_invalid2:
> >>> dummy.fontsize = s->fontsize;
> >>> glyph = av_tree_find(s->glyphs, &dummy, glyph_cmp, NULL);
> >>>
> >>> + /* letter spacing */
> >>> + x += s->letter_spacing;
> >>> +
> >>> /* kerning */
> >>> if (s->use_kerning && prev_glyph && glyph->code) {
> >>> FT_Get_Kerning(s->face, prev_glyph->code, glyph->code,
> >>> @@ -1539,7 +1550,12 @@ continue_on_invalid2:
> >>> else x += glyph->advance;
> >>> }
> >>>
> >>> - max_text_line_w = FFMAX(x, max_text_line_w);
> >>> + s->letter_spacing = av_expr_eval(s->letter_spacing_pexpr,
> >>> s->var_values, &s->prng);
> >>> + if (s->letter_spacing < 0) {
> >>> + max_text_line_w = x+ s->letter_spacing;
> >>> + } else {
> >>> + max_text_line_w = FFMAX(x, max_text_line_w) +
> s->letter_spacing;
> >>> + }
> >>>
> >>> s->var_values[VAR_TW] = s->var_values[VAR_TEXT_W] =
> max_text_line_w;
> >>> s->var_values[VAR_TH] = s->var_values[VAR_TEXT_H] = y +
> >>> s->max_glyph_h;
> >>> --
> >>> 2.40.1
> >>>
> >>> _______________________________________________
> >>> ffmpeg-devel mailing list
> >>> ffmpeg-devel@ffmpeg.org
> >>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >>>
> >>> To unsubscribe, visit link above, or email
> >>> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> >>>
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-06-20 15:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-19 16:33 [FFmpeg-devel] [PATCH] libavfilter/vf_drawtext: add letter_spacing as an evaluated parameter Mark Ren
2023-06-19 16:39 ` Paul B Mahol
2023-06-19 17:56 ` Mark Ren
2023-06-20 14:27 ` Francesco Carusi
2023-06-20 15:57 ` Paul B Mahol
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git