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 CF54F47A38 for ; Fri, 29 Dec 2023 11:51:25 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2775368CCE5; Fri, 29 Dec 2023 13:51:22 +0200 (EET) Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A61FA68C9A1 for ; Fri, 29 Dec 2023 13:51:15 +0200 (EET) Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-40b5155e154so89652735e9.3 for ; Fri, 29 Dec 2023 03:51:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703850673; x=1704455473; 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=u0hFaoH/lzSRWFImW7TUmrcOj1ER4Wo8oS27FuB4QLc=; b=lSL7Mt8orcRUTw9rf/s5/54vaUWXmBqetoi0JYp+66rUKA28bakZV//yAx9PXA3MKz V+G0ow5DiqN4ZywLuxL+L9+0eA9D1OtxAI+LRzD58zW1BL2g94fgDDonOVT+HSw1PDzk 8Mf5INtTwWitPIdgoOJtoHpJRaC8GHyGLyccBGhE1pPqHiBQlMaywF6QvEw10Sy4IQVQ ndhHTWrOGrEudC0w1m9e68XkxPNOBK/Rlgo/ZnbJn9MV8zNikjIcRwmDBdGVuWtTaA/Q qPCBwUZoTjUXcMj02ZhqU8KWRQGw4QGhFmbJ6tub+p3qH1+MFJTvYHzsVxWAmbCjJEeF I/Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703850673; x=1704455473; 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=u0hFaoH/lzSRWFImW7TUmrcOj1ER4Wo8oS27FuB4QLc=; b=mMgXatNK0BpPt0/xPEa1LP+9uJU36oN81eOSwvAmZr5Rwb7+WuXO9/memhucIzsTnC Jt+5XioqeiLkLkG5xkloV6W3IUjqTywrdRQL9x6okG0JCSFVMdrb4u2ggl5I7lxO1GSh vzcDHyGEAZ+tpqm9dwepVE7KzF2eDvPdDmD6EzXKBnYRgNOhxWmjABXdxmzo4nf0y8YI T9tpHNyAmATf4jNRbQbuYOrqGKdRQtLPPNz43h5Jv2HBuSAbsux8OHxZYpnaxtL+kjtU NFIxu14M/gz/8IPbkumSZsJjaOUnbZeL3PIi1tseG430mDIi5zG53/HNQR2xPl8RiSli qzFw== X-Gm-Message-State: AOJu0YylWL4rHldgIyM1WlVminqd0FyQVrBslap3YyzPbaDHXX5HLb5y iUs+hG1Q3CCVb3l+zM2g0PDoKa/Thec= X-Google-Smtp-Source: AGHT+IGcNdDLfa4tyZZ8Ue92RB64NM0gusRhORjj9jtxhK1ysoSE8XxeUFHEltIEoaLgjN9j8VXBrw== X-Received: by 2002:a05:600c:2116:b0:40d:60e2:d628 with SMTP id u22-20020a05600c211600b0040d60e2d628mr1681165wml.113.1703850673095; Fri, 29 Dec 2023 03:51:13 -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 p9-20020a170907910900b00a26ac5e3683sm7542228ejq.100.2023.12.29.03.51.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Dec 2023 03:51:12 -0800 (PST) Received: by mariano (Postfix, from userid 1000) id 99D97BFCDC; Fri, 29 Dec 2023 12:51:10 +0100 (CET) Date: Fri, 29 Dec 2023 12:51:10 +0100 From: Stefano Sabatini To: FFmpeg development discussions and patches Message-ID: Mail-Followup-To: FFmpeg development discussions and patches References: <20231228003839.860894-1-stefasab@gmail.com> <20231228212508.GZ6420@pb2> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="tKNp1jWuIPp1aDra" Content-Disposition: inline In-Reply-To: <20231228212508.GZ6420@pb2> User-Agent: Mutt/2.1.4 (2021-12-11) Subject: Re: [FFmpeg-devel] [PATCH 2/2] lavfi/setpts: introduce rand() function in expression 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --tKNp1jWuIPp1aDra Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On date Thursday 2023-12-28 22:25:08 +0100, Michael Niedermayer wrote: > On Thu, Dec 28, 2023 at 07:49:18PM +0100, Stefano Sabatini wrote: > > On date Thursday 2023-12-28 16:00:57 +0100, Stefano Sabatini wrote: > > > On date Thursday 2023-12-28 12:02:59 +0100, Andreas Rheinhardt wrote: > > > > Stefano Sabatini: > > > > > This is useful to simulate random jitter. > > > > > --- > > > > > Changelog | 1 + > > > > > doc/filters.texi | 10 +++++++++- > > > > > libavfilter/setpts.c | 39 +++++++++++++++++++++++++++++++++------ > > > > > 3 files changed, 43 insertions(+), 7 deletions(-) > > [...] > > > > Why is this added here and not in lavu/eval so that it is available with > > > > all expressions? > > > > > > There is no specific reason. Sometimes you need to have a control over > > > the seed, in this case you need to provide the PRNG context. > > > > > > For the general case, probably we can place a global LFG in the eval > > > module and fetch its generated values. > > > > Another possible solution in attachment, leveraging the same affine > > PRNG used in random(). For other use cases you might need to use a > > high-quality PRNG and this might not be good enough. > > > eval.c | 18 +++++++++++++++--- > > 1 file changed, 15 insertions(+), 3 deletions(-) > > 94413dcc88e3046b4987715f6c152aeb1c24c703 0001-lavu-eval-add-randomi-function-to-compute-random-val.patch > > From 4dc5213b0913a2585f75dfd03b497ca2efc093de Mon Sep 17 00:00:00 2001 > > From: Stefano Sabatini > > Date: Thu, 28 Dec 2023 19:09:22 +0100 > > Subject: [PATCH] lavu/eval: add randomi function to compute random value in > > interval > > probably ok if this is usefull > > thx Will apply the edited patch in a few days if I see no comments. --tKNp1jWuIPp1aDra Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-lavu-eval-add-randomi-function-to-compute-random-val.patch" >From c4c9eef66401f930a6428c6889020ff5e65c60d6 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Thu, 28 Dec 2023 19:09:22 +0100 Subject: [PATCH 1/2] lavu/eval: add randomi function to compute random value in interval --- Changelog | 1 + doc/utils.texi | 12 +++++++++--- libavutil/eval.c | 26 +++++++++++++++++++------- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Changelog b/Changelog index 424bfc11af..419075dc56 100644 --- a/Changelog +++ b/Changelog @@ -15,6 +15,7 @@ version : - tiltandshift filter - qrencode filter and qrencodesrc source - quirc filter +- lavu/eval: introduce randomi() function in expressions version 6.1: - libaribcaption decoder diff --git a/doc/utils.texi b/doc/utils.texi index a0b8d4b62d..0c4f146f4f 100644 --- a/doc/utils.texi +++ b/doc/utils.texi @@ -939,9 +939,15 @@ Returns the value of the expression printed. Prints t with loglevel l -@item random(x) -Return a pseudo random value between 0.0 and 1.0. @var{x} is the index of the -internal variable which will be used to save the seed/state. +@item random(idx) +Return a pseudo random value between 0.0 and 1.0. @var{idx} is the +index of the internal variable which will be used to save the +seed/state. + +@item randomi(idx, min, max) +Return a pseudo random value in the interval between @var{min} and +@var{max}. @var{idx} is the index of the internal variable which will +be used to save the seed/state. @item root(expr, max) Find an input value for which the function represented by @var{expr} diff --git a/libavutil/eval.c b/libavutil/eval.c index bad9e4ecb8..dc6b3697bc 100644 --- a/libavutil/eval.c +++ b/libavutil/eval.c @@ -162,7 +162,7 @@ struct AVExpr { e_last, e_st, e_while, e_taylor, e_root, e_floor, e_ceil, e_trunc, e_round, e_sqrt, e_not, e_random, e_hypot, e_gcd, e_if, e_ifnot, e_print, e_bitand, e_bitor, e_between, e_clip, e_atan2, e_lerp, - e_sgn, + e_sgn, e_randomi } type; double value; // is sign in other types int const_index; @@ -228,12 +228,22 @@ static double eval_expr(Parser *p, AVExpr *e) av_log(p, level, "%f\n", x); return x; } - case e_random:{ - int idx= av_clip(eval_expr(p, e->param[0]), 0, VARS-1); - uint64_t r= isnan(p->var[idx]) ? 0 : p->var[idx]; - r= r*1664525+1013904223; - p->var[idx]= r; - return e->value * (r * (1.0/UINT64_MAX)); + +#define COMPUTE_NEXT_RANDOM() \ + int idx = av_clip(eval_expr(p, e->param[0]), 0, VARS-1); \ + uint64_t r = isnan(p->var[idx]) ? 0 : p->var[idx]; \ + r = r * 1664525 + 1013904223; \ + p->var[idx] = r; \ + + case e_random: { + COMPUTE_NEXT_RANDOM(); + return r * (1.0/UINT64_MAX); + } + case e_randomi: { + double min = eval_expr(p, e->param[1]); + double max = eval_expr(p, e->param[2]); + COMPUTE_NEXT_RANDOM(); + return min + (max - min) * r / UINT64_MAX; } case e_while: { double d = NAN; @@ -461,6 +471,7 @@ static int parse_primary(AVExpr **e, Parser *p) else if (strmatch(next, "pow" )) d->type = e_pow; else if (strmatch(next, "print" )) d->type = e_print; else if (strmatch(next, "random")) d->type = e_random; + else if (strmatch(next, "randomi")) d->type = e_randomi; else if (strmatch(next, "hypot" )) d->type = e_hypot; else if (strmatch(next, "gcd" )) d->type = e_gcd; else if (strmatch(next, "if" )) d->type = e_if; @@ -674,6 +685,7 @@ static int verify_expr(AVExpr *e) case e_between: case e_clip: case e_lerp: + case e_randomi: return verify_expr(e->param[0]) && verify_expr(e->param[1]) && verify_expr(e->param[2]); -- 2.34.1 --tKNp1jWuIPp1aDra Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0002-doc-filters-setpts-add-random-jitter-generation-exam.patch" >From 9f7bc9370ad853392622ac3008f14df99ed6210a Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Fri, 29 Dec 2023 12:48:08 +0100 Subject: [PATCH 2/2] doc/filters/setpts: add random jitter generation example --- doc/filters.texi | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/filters.texi b/doc/filters.texi index d1f95b9781..6a9c7d532c 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -31039,6 +31039,12 @@ Set fixed rate of 25 frames per second: setpts=N/(25*TB) @end example +@item +Apply a random jitter effect of +/-100 TB units: +@example +setpts=PTS+randomi(0, -100\,100) +@end example + @item Set fixed rate 25 fps with some jitter: @example -- 2.34.1 --tKNp1jWuIPp1aDra Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --tKNp1jWuIPp1aDra--