[FFmpeg-devel] [PATCH] avfilter/f_realtime: add option to scale speed
Nicolas George
george at nsup.org
Wed Dec 26 19:37:42 EET 2018
Moritz Barsnick (2018-12-25):
> Signed-off-by: Moritz Barsnick <barsnick at gmx.net>
> ---
> This adds two double precision divisions per frame, which seems acceptable.
>
> I'm not sure scaling the limit by the factor is the correct idea. It feels
> right regarding the discontinuities, but not according to the limit option's
> description.
I think it would be more logical to keep limit expressed as real time.
This option is a safety net, it is not nimble enough to select time gaps
to ignore in files that contain them.
>
>
> doc/filters.texi | 4 ++++
> libavfilter/f_realtime.c | 7 +++++--
> 2 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 65ce25bc18..60ebf2aa99 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -20829,6 +20829,10 @@ They accept the following options:
> @item limit
> Time limit for the pauses. Any pause longer than that will be considered
> a timestamp discontinuity and reset the timer. Default is 2 seconds.
> + at item speed
> +Speed factor for processing. The value must be a float larger than zero.
> +Values larger than 1.0 will speed up processing, smaller will slow it down.
> +The @var{limit} is automatically adapted accordingly. Default is 1.0.
> @end table
>
> @anchor{select}
> diff --git a/libavfilter/f_realtime.c b/libavfilter/f_realtime.c
> index 171c16aaaa..8d4fbf642b 100644
> --- a/libavfilter/f_realtime.c
> +++ b/libavfilter/f_realtime.c
> @@ -22,11 +22,13 @@
> #include "libavutil/time.h"
> #include "avfilter.h"
> #include "internal.h"
> +#include <float.h>
>
> typedef struct RealtimeContext {
> const AVClass *class;
> int64_t delta;
> int64_t limit;
> + double speed;
> unsigned inited;
> } RealtimeContext;
>
> @@ -36,7 +38,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
> RealtimeContext *s = ctx->priv;
>
> if (frame->pts != AV_NOPTS_VALUE) {
> - int64_t pts = av_rescale_q(frame->pts, inlink->time_base, AV_TIME_BASE_Q);
> + int64_t pts = av_rescale_q(frame->pts, inlink->time_base, AV_TIME_BASE_Q) / s->speed;
> int64_t now = av_gettime_relative();
> int64_t sleep = pts - now + s->delta;
> if (!s->inited) {
> @@ -44,7 +46,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
> sleep = 0;
> s->delta = now - pts;
> }
> - if (sleep > s->limit || sleep < -s->limit) {
> + if (sleep > s->limit / s->speed || sleep < -s->limit / s->speed) {
I should have used FFABS(sleep); if this hunk stays, then better make
the change to have only one division:
if (FFABS(sleep) > s->limit / s->speed)
> av_log(ctx, AV_LOG_WARNING,
> "time discontinuity detected: %"PRIi64" us, resetting\n",
> sleep);
> @@ -65,6 +67,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
> #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
> static const AVOption options[] = {
> { "limit", "sleep time limit", OFFSET(limit), AV_OPT_TYPE_DURATION, { .i64 = 2000000 }, 0, INT64_MAX, FLAGS },
> + { "speed", "speed factor", OFFSET(speed), AV_OPT_TYPE_DOUBLE, { .dbl = 1.0 }, DBL_MIN, DBL_MAX, FLAGS },
> { NULL }
> };
>
LGTM apart from these nitpicks.
Regards,
--
Nicolas George
More information about the ffmpeg-devel
mailing list