From: Stefano Sabatini <stefasab@gmail.com> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: Re: [FFmpeg-devel] [PATCH 2/2] lavfi/setpts: introduce rand() function in expression Date: Thu, 28 Dec 2023 16:00:57 +0100 Message-ID: <ZY2NqdzYyqujkc3E@mariano> (raw) In-Reply-To: <AS8P250MB0744B9266C6D265E238EA03F8F9EA@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> 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(-) > > > > diff --git a/Changelog b/Changelog > > index 424bfc11af..ed01c53264 100644 > > --- a/Changelog > > +++ b/Changelog > > @@ -15,6 +15,7 @@ version <next>: > > - tiltandshift filter > > - qrencode filter and qrencodesrc source > > - quirc filter > > +- lavfi/setpts: introduce rand() function in expression > > > > version 6.1: > > - libaribcaption decoder > > diff --git a/doc/filters.texi b/doc/filters.texi > > index d1f95b9781..1d9a5d6c7d 100644 > > --- a/doc/filters.texi > > +++ b/doc/filters.texi > > @@ -30946,7 +30946,7 @@ The expression which is evaluated for each frame to construct its timestamp. > > @end table > > > > The expression is evaluated through the eval API and can contain the following > > -constants: > > +constants and functions: > > > > @table @option > > @item FRAME_RATE, FR > > @@ -31010,6 +31010,8 @@ The timebase of the input timestamps. > > @item T_CHANGE > > Time of the first frame after command was applied or time of the first frame if no commands. > > > > +@item rand(min, max) > > +a random number included between min and max > > @end table > > > > @subsection Examples > > @@ -31021,6 +31023,12 @@ Start counting PTS from zero > > setpts=PTS-STARTPTS > > @end example > > > > +@item > > +Apply a random jitter effect of +/-100 TB units: > > +@example > > +setpts=PTS+100rand(-100\,100) > > +@end example > > + > > @item > > Apply fast motion effect: > > @example > > diff --git a/libavfilter/setpts.c b/libavfilter/setpts.c > > index 88a8d6af86..0f24a900b3 100644 > > --- a/libavfilter/setpts.c > > +++ b/libavfilter/setpts.c > > @@ -32,6 +32,8 @@ > > #include "libavutil/internal.h" > > #include "libavutil/mathematics.h" > > #include "libavutil/opt.h" > > +#include "libavutil/lfg.h" > > +#include "libavutil/random_seed.h" > > #include "libavutil/time.h" > > #include "audio.h" > > #include "avfilter.h" > > @@ -101,18 +103,39 @@ typedef struct SetPTSContext { > > AVExpr *expr; > > double var_values[VAR_VARS_NB]; > > enum AVMediaType type; > > + AVLFG lfg; > > } SetPTSContext; > > > > #define V(name_) \ > > setpts->var_values[VAR_##name_] > > > > +static double drand(void *ctx, double min, double max) > > +{ > > + SetPTSContext *setpts = ((AVFilterContext *)ctx)->priv; > > + > > + return min + (max-min) / UINT_MAX * av_lfg_get(&setpts->lfg); > > +} > > + [...] > > 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. _______________________________________________ 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".
next prev parent reply other threads:[~2023-12-28 15:01 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-12-28 0:38 Stefano Sabatini 2023-12-28 11:02 ` Andreas Rheinhardt 2023-12-28 15:00 ` Stefano Sabatini [this message] 2023-12-28 18:49 ` Stefano Sabatini 2023-12-28 21:25 ` Michael Niedermayer 2023-12-29 11:51 ` Stefano Sabatini 2024-01-02 21:12 ` Stefano Sabatini
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=ZY2NqdzYyqujkc3E@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