Re: [FFmpeg-devel] [PATCH] avfilter/setpts: add command support

2023-05-14 Thread Stefano Sabatini
On date Wednesday 2023-05-10 00:12:52 +0100, Oleg Afanasyev wrote:
> On Sun, 7 May 2023 at 23:47, Stefano Sabatini  wrote:
[...]
> >
> > what happens in case setpts->expr is freed and this fails?
> >
> > probably it should keep a reference to expr and remove it only in case
> > the new expression was successfully parsed
> 
> Fixed! Didn't realize that encoding continues even if command fails,
> so it was crashing with the previous expression still in place.
> 
> >
> > [...]
> >
> > Looks good to me otherwise.

Applied, thanks.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avfilter/setpts: add command support

2023-05-09 Thread Oleg Afanasyev
On Sun, 7 May 2023 at 23:47, Stefano Sabatini  wrote:
>
> On date Monday 2023-05-01 22:01:05 +0100, Oleg Afanasyev wrote:
> > I'm using setpts to generate timelapses with slowdowns in the middle.
> > Using setpts filter requires complicated expr to handle intervals. This
> > patch allows commands to change expr and also adds a constant that
> > provides time of last command applications to allow specifying gradual
> > changes using difference between time and cmd time.
> >
> > --
> > with best regards
> > Oleg Afanasyev
>
> > From a714a0957a57c1d392feca0ba675ba5ac7c875ee Mon Sep 17 00:00:00 2001
> > From: Oleg 
> > Date: Sat, 29 Apr 2023 19:56:46 +0100
> > Subject: [PATCH] avfilter/setpts: add command support
> >
> > Add support for changing expr on the fly.
> >
> > Signed-off-by: Oleg 
> > ---
> >  doc/filters.texi |  7 +
> >  libavfilter/setpts.c | 68 +---
> >  2 files changed, 58 insertions(+), 17 deletions(-)
> >
> > diff --git a/doc/filters.texi b/doc/filters.texi
> > index 50e1682144..fbdb1f8ecf 100644
> > diff --git a/libavfilter/setpts.c b/libavfilter/setpts.c
> > index 5bcc0c2dcf..7b09ce7707 100644
> > --- a/libavfilter/setpts.c
> > +++ b/libavfilter/setpts.c
> [...]
> > +static int process_command(AVFilterContext *ctx, const char *cmd, const 
> > char *arg,
> > +   char *res, int res_len, int flags)
> > +{
> > +SetPTSContext *setpts = ctx->priv;
> > +int ret;
> > +
> > +ret = ff_filter_process_command(ctx, cmd, arg, res, res_len, flags);
> > +
> > +if (ret < 0)
> > +return ret;
> > +
>
> > +if (!strcmp(cmd, "expr")) {
> > +av_expr_free(setpts->expr);
> > +ret = av_expr_parse(>expr, arg, var_names, NULL, NULL, 
> > NULL, NULL, 0, ctx);
> > +if (ret < 0) {
> > +av_log(ctx, AV_LOG_ERROR, "Error while parsing expression 
> > '%s'\n", arg);
> > +}
>
> what happens in case setpts->expr is freed and this fails?
>
> probably it should keep a reference to expr and remove it only in case
> the new expression was successfully parsed

Fixed! Didn't realize that encoding continues even if command fails,
so it was crashing with the previous expression still in place.

>
> [...]
>
> Looks good to me otherwise.
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
From a50bf9e58a0f90d63aba3c84de40f31dc22ebfce Mon Sep 17 00:00:00 2001
From: Oleg 
Date: Sat, 29 Apr 2023 19:56:46 +0100
Subject: [PATCH] avfilter/setpts: add command support

Add support for changing expr on the fly.

Signed-off-by: Oleg 
---
 doc/filters.texi |  7 +
 libavfilter/setpts.c | 73 +---
 2 files changed, 63 insertions(+), 17 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 50e1682144..fbdb1f8ecf 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -29384,6 +29384,9 @@ The wallclock (RTC) time at the start of the movie in microseconds.
 @item TB
 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.
+
 @end table
 
 @subsection Examples
@@ -29439,6 +29442,10 @@ asetpts=N/SR/TB
 
 @end itemize
 
+@subsection Commands
+
+Both filters support all above options as @ref{commands}.
+
 @section setrange
 
 Force color range for the output video frame.
diff --git a/libavfilter/setpts.c b/libavfilter/setpts.c
index 5bcc0c2dcf..c805a60ee4 100644
--- a/libavfilter/setpts.c
+++ b/libavfilter/setpts.c
@@ -63,6 +63,7 @@ static const char *const var_names[] = {
 "S",   //   Number of samples in the current frame
 "SR",  //   Audio sample rate
 "FR",  ///< defined only for constant frame-rate video
+"T_CHANGE",///< time of first frame after latest command was applied
 NULL
 };
 
@@ -90,7 +91,8 @@ enum var_name {
 VAR_S,
 VAR_SR,
 VAR_FR,
-VAR_VARS_NB
+VAR_T_CHANGE,
+VAR_VARS_NB,
 };
 
 typedef struct SetPTSContext {
@@ -120,6 +122,7 @@ static av_cold int init(AVFilterContext *ctx)
 setpts->var_values[VAR_PREV_OUTT]   = NAN;
 setpts->var_values[VAR_STARTPTS]= NAN;
 setpts->var_values[VAR_STARTT]  = NAN;
+setpts->var_values[VAR_T_CHANGE]= NAN;
 return 0;
 }
 
@@ -163,6 +166,9 @@ static double eval_pts(SetPTSContext *setpts, AVFilterLink *inlink, AVFrame *fra
 setpts->var_values[VAR_STARTPTS] = TS2D(pts);
 setpts->var_values[VAR_STARTT  ] = TS2T(pts, inlink->time_base);
 }
+if (isnan(setpts->var_values[VAR_T_CHANGE])) {
+setpts->var_values[VAR_T_CHANGE] = TS2T(pts, inlink->time_base);
+}
 setpts->var_values[VAR_PTS   ] = TS2D(pts);
 setpts->var_values[VAR_T ] = 

Re: [FFmpeg-devel] [PATCH] avfilter/setpts: add command support

2023-05-07 Thread Stefano Sabatini
On date Monday 2023-05-01 22:01:05 +0100, Oleg Afanasyev wrote:
> I'm using setpts to generate timelapses with slowdowns in the middle.
> Using setpts filter requires complicated expr to handle intervals. This
> patch allows commands to change expr and also adds a constant that
> provides time of last command applications to allow specifying gradual
> changes using difference between time and cmd time.
> 
> --
> with best regards
> Oleg Afanasyev

> From a714a0957a57c1d392feca0ba675ba5ac7c875ee Mon Sep 17 00:00:00 2001
> From: Oleg 
> Date: Sat, 29 Apr 2023 19:56:46 +0100
> Subject: [PATCH] avfilter/setpts: add command support
> 
> Add support for changing expr on the fly.
> 
> Signed-off-by: Oleg 
> ---
>  doc/filters.texi |  7 +
>  libavfilter/setpts.c | 68 +---
>  2 files changed, 58 insertions(+), 17 deletions(-)
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 50e1682144..fbdb1f8ecf 100644
> diff --git a/libavfilter/setpts.c b/libavfilter/setpts.c
> index 5bcc0c2dcf..7b09ce7707 100644
> --- a/libavfilter/setpts.c
> +++ b/libavfilter/setpts.c
[...]
> +static int process_command(AVFilterContext *ctx, const char *cmd, const char 
> *arg,
> +   char *res, int res_len, int flags)
> +{
> +SetPTSContext *setpts = ctx->priv;
> +int ret;
> +
> +ret = ff_filter_process_command(ctx, cmd, arg, res, res_len, flags);
> +
> +if (ret < 0)
> +return ret;
> +

> +if (!strcmp(cmd, "expr")) {
> +av_expr_free(setpts->expr);
> +ret = av_expr_parse(>expr, arg, var_names, NULL, NULL, NULL, 
> NULL, 0, ctx);
> +if (ret < 0) {
> +av_log(ctx, AV_LOG_ERROR, "Error while parsing expression 
> '%s'\n", arg);
> +}

what happens in case setpts->expr is freed and this fails?

probably it should keep a reference to expr and remove it only in case
the new expression was successfully parsed

[...]

Looks good to me otherwise.

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".