From: Stefano Sabatini <stefasab@gmail.com> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: Re: [FFmpeg-devel] [PATCH] avfilter: allow floating point formatting in expr_int_format (vf_drawtext.c) Date: Sun, 3 Dec 2023 15:52:08 +0100 Message-ID: <ZWyWGEBq0u4D1UPq@mariano> (raw) In-Reply-To: <b5136dca3656a192e71a7575ecac460536fc5b56.camel@t-online.de> On date Saturday 2023-12-02 15:54:34 +0100, Lennart Klebl wrote: > Since I was trying for quite some time to get proper floating point > formatting of positive and negative numbers working with the existing > drawtext/expr_int_format implementation, I added the f format specifier > that is only applied when used in conjunction with a width. > > > From 14c438a2bcf2ea17a6818ef5cdc6a7ee9ef30184 Mon Sep 17 00:00:00 2001 > From: "lennart.klebl@t-online.de" <lennart.klebl@t-online.de> > Date: Sat, 2 Dec 2023 15:53:20 +0100 > Subject: [PATCH] avfilter: allow floating point formatting in expr_int_format > (vf_drawtext.c) > > --- > doc/filters.texi | 12 ++++++++---- > libavfilter/vf_drawtext.c | 19 ++++++++++++++----- > 2 files changed, 22 insertions(+), 9 deletions(-) > > diff --git a/doc/filters.texi b/doc/filters.texi > index de19d130cc..1b11124434 100644 > --- a/doc/filters.texi > +++ b/doc/filters.texi > @@ -12807,14 +12807,18 @@ the constants @var{text_w} and @var{text_h} will have an undefined > value. > > @item expr_int_format, eif > -Evaluate the expression's value and output as formatted integer. > +Evaluate the expression's value and output as formatted integer or floating > +point number. > > The first argument is the expression to be evaluated, just as for the @var{expr} function. > The second argument specifies the output format. Allowed values are @samp{x}, > -@samp{X}, @samp{d} and @samp{u}. They are treated exactly as in the > +@samp{X}, @samp{d}, @samp{u}, and @samp{f}. They are treated exactly as in the > @code{printf} function. > -The third parameter is optional and sets the number of positions taken by the output. > -It can be used to add padding with zeros from the left. > + > +When specifying @samp{f}, the third parameter is required and specifies the > +number of decimal places for floating point formatting. Otherwise, the third I think we want to use a sane default when not specified, in this case you can skip the specification of .N. > +parameter is optional and sets the number of positions taken by the output. It > +can be used to add padding with zeros from the left. > > @item gmtime > The time at which the filter is running, expressed in UTC. > diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c > index c5477cbff1..be0490bbb3 100644 > --- a/libavfilter/vf_drawtext.c > +++ b/libavfilter/vf_drawtext.c > @@ -1359,6 +1359,7 @@ static int func_eval_expr_int_format(AVFilterContext *ctx, AVBPrint *bp, > int ret; > unsigned int positions = 0; > char fmt_str[30] = "%"; > + char fmt_arg = argv[1][0]; > > /* > * argv[0] expression to be converted to `int` > @@ -1376,9 +1377,9 @@ static int func_eval_expr_int_format(AVFilterContext *ctx, AVBPrint *bp, > return ret; > } > > - if (!strchr("xXdu", argv[1][0])) { > + if (!strchr("xXduf", fmt_arg)) { > av_log(ctx, AV_LOG_ERROR, "Invalid format '%c' specified," > - " allowed values: 'x', 'X', 'd', 'u'\n", argv[1][0]); > + " allowed values: 'x', 'X', 'd', 'u', 'f'\n", fmt_arg); > return AVERROR(EINVAL); > } > > @@ -1400,14 +1401,22 @@ static int func_eval_expr_int_format(AVFilterContext *ctx, AVBPrint *bp, > } > #endif > > + if (fmt_arg == 'f' && argc < 3) fmt_arg = 'd'; > + We should avoid this unexpected fallback, just skip the .N specification in this case. > if (argc == 3) > - av_strlcatf(fmt_str, sizeof(fmt_str), "0%u", positions); > - av_strlcatf(fmt_str, sizeof(fmt_str), "%c", argv[1][0]); > + if (fmt_arg == 'f') > + av_strlcatf(fmt_str, sizeof(fmt_str), ".%u", positions); > + else > + av_strlcatf(fmt_str, sizeof(fmt_str), "0%u", positions); > + av_strlcatf(fmt_str, sizeof(fmt_str), "%c", fmt_arg); _______________________________________________ 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".
prev parent reply other threads:[~2023-12-03 14:52 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-12-02 14:54 Lennart Klebl 2023-12-03 14:52 ` Stefano Sabatini [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=ZWyWGEBq0u4D1UPq@mariano \ --to=stefasab@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
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