From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id A1E0E47BBB for ; Sun, 3 Dec 2023 14:52:20 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4B26268CAA1; Sun, 3 Dec 2023 16:52:18 +0200 (EET) Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E562368003C for ; Sun, 3 Dec 2023 16:52:11 +0200 (EET) Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a1b03886fd7so86477066b.2 for ; Sun, 03 Dec 2023 06:52:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701615130; x=1702219930; darn=ffmpeg.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=2B4VOlzRxY3qbq1y6XtB16jBCC8WNhIfFlKPf6pkLYA=; b=HCMNnIG3BJBOfg7qFQArU6CE4MMYUGK9yhsUw6ASOKuO1lRNKWUU+Yfm1ygLQ551lG wMpu4Lrk6CGcfNhKpdct9QIJ+yw0Gpr3ibHHrmMZn59S44ZsfJ6DElqSzZz1X7bBe+mY /eD+JWD2a9FwBfvEUAjzEL92qK4xzPqfgqzPFWcV7YFBiIpSTD7qMSw/Jl9khYNTDYHK M/r6cRbg1mTXdSBVS1VJHfmQDJq3QyoUFPPbiF7LkL1fgyv8wQG3SCIBLXxNRl1SQtZZ j7KJnMBqkQIFHzajEEpWXDlOEa3PkVhe3a3R+3WjR1DdAIBzUo41d4UpFrZvjCABqBOu DZAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701615130; x=1702219930; h=user-agent:in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=2B4VOlzRxY3qbq1y6XtB16jBCC8WNhIfFlKPf6pkLYA=; b=VLiROeaG3ZMXd+UzxWLKUSvVuawpRfRGcyaqlZsMAJGowtNE9G/URUiVti9t92PitY v1XaaUYwa6NKkla0M/mEcHpfMLehJ+hQ/ii/o2A05JNDfrX3vyg9RWlBJYC2YzrulA/8 eaNabW6nylksvIG3u9StiuIwt9m+AaoW2YBHLt10nPz4ffNAAfjQKj2S7oIsvLZh+DmJ 6E6EJnqu1zaBBuJO4GkoK9poYRMZtfagGfzeBoPe9DL2ApoIsUP0pXExSapZHDTN4Dbw zeV3Mdgyzph7HL5GAv3RVL4uLGmry3OgBbvM9TmlxpWuzQsGE5u5Cs4dOfgjhFdwtnYJ EX5A== X-Gm-Message-State: AOJu0YwBjBsvd1Tjgjwd/EXxAwA2uhRVQIcFhWg6BWit4ECCEyBIPpKs jtfay+vQhkSDhtWo6rHSlVgzRkFrRgk= X-Google-Smtp-Source: AGHT+IEJlXebbt/F6Q3csqZyl6hlt6lG5vwKFUUXrxs6olfJIA1+2RnPAQIgP6lTY/XhOfJv2mZjLg== X-Received: by 2002:a17:906:34da:b0:a19:a1ba:da37 with SMTP id h26-20020a17090634da00b00a19a1bada37mr2153545ejb.94.1701615130126; Sun, 03 Dec 2023 06:52:10 -0800 (PST) Received: from mariano (dynamic-adsl-84-220-189-10.clienti.tiscali.it. [84.220.189.10]) by smtp.gmail.com with ESMTPSA id re17-20020a170906d8d100b009b2ba067b37sm4165814ejb.202.2023.12.03.06.52.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 06:52:09 -0800 (PST) Received: by mariano (Postfix, from userid 1000) id 731E9BFCDA; Sun, 3 Dec 2023 15:52:08 +0100 (CET) Date: Sun, 3 Dec 2023 15:52:08 +0100 From: Stefano Sabatini To: FFmpeg development discussions and patches Message-ID: Mail-Followup-To: FFmpeg development discussions and patches References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.1.4 (2021-12-11) Subject: Re: [FFmpeg-devel] [PATCH] avfilter: allow floating point formatting in expr_int_format (vf_drawtext.c) X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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" > 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".