From 82123e133db6d556f3366a1cbb4f0439d70539d4 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Wed, 4 Aug 2021 22:42:44 +0200 Subject: [PATCH] avfilter/avf_showspectrum: add lreplace sliding mode --- doc/filters.texi | 2 ++ libavfilter/avf_showspectrum.c | 29 +++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 66c0f87e47..7a266c2a32 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -26749,6 +26749,8 @@ the samples scroll from right to left frames are only produced when the samples reach the right @item rscroll the samples scroll from left to right +@item lreplace +the samples start again on the right when they reach the left @end table Default value is @code{replace}. diff --git a/libavfilter/avf_showspectrum.c b/libavfilter/avf_showspectrum.c index b9391a6efb..c9cdccad11 100644 --- a/libavfilter/avf_showspectrum.c +++ b/libavfilter/avf_showspectrum.c @@ -49,7 +49,7 @@ enum DataMode { D_MAGNITUDE, D_PHASE, NB_DMODES }; enum FrequencyScale { F_LINEAR, F_LOG, NB_FSCALES }; enum DisplayScale { LINEAR, SQRT, CBRT, LOG, FOURTHRT, FIFTHRT, NB_SCALES }; enum ColorMode { CHANNEL, INTENSITY, RAINBOW, MORELAND, NEBULAE, FIRE, FIERY, FRUIT, COOL, MAGMA, GREEN, VIRIDIS, PLASMA, CIVIDIS, TERRAIN, NB_CLMODES }; -enum SlideMode { REPLACE, SCROLL, FULLFRAME, RSCROLL, NB_SLIDES }; +enum SlideMode { REPLACE, SCROLL, FULLFRAME, RSCROLL, LREPLACE, NB_SLIDES }; enum Orientation { VERTICAL, HORIZONTAL, NB_ORIENTATIONS }; typedef struct ShowSpectrumContext { @@ -115,6 +115,7 @@ static const AVOption showspectrum_options[] = { { "scroll", "scroll from right to left", 0, AV_OPT_TYPE_CONST, {.i64=SCROLL}, 0, 0, FLAGS, "slide" }, { "fullframe", "return full frames", 0, AV_OPT_TYPE_CONST, {.i64=FULLFRAME}, 0, 0, FLAGS, "slide" }, { "rscroll", "scroll from left to right", 0, AV_OPT_TYPE_CONST, {.i64=RSCROLL}, 0, 0, FLAGS, "slide" }, + { "lreplace", "replace from right to left", 0, AV_OPT_TYPE_CONST, {.i64=LREPLACE}, 0, 0, FLAGS, "slide" }, { "mode", "set channel display mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=COMBINED}, COMBINED, NB_MODES-1, FLAGS, "mode" }, { "combined", "combined mode", 0, AV_OPT_TYPE_CONST, {.i64=COMBINED}, 0, 0, FLAGS, "mode" }, { "separate", "separate mode", 0, AV_OPT_TYPE_CONST, {.i64=SEPARATE}, 0, 0, FLAGS, "mode" }, @@ -1187,6 +1188,13 @@ static int config_output(AVFilterLink *outlink) (s->orientation == HORIZONTAL && s->xpos >= s->h)) s->xpos = 0; + if (s->sliding == LREPLACE) { + if (s->orientation == VERTICAL) + s->xpos = s->w - 1; + if (s->orientation == HORIZONTAL) + s->xpos = s->h - 1; + } + s->auto_frame_rate = av_make_q(inlink->sample_rate, s->hop_size); if (s->orientation == VERTICAL && s->sliding == FULLFRAME) s->auto_frame_rate = av_mul_q(s->auto_frame_rate, av_make_q(1, s->w)); @@ -1377,11 +1385,20 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples) if (s->sliding != FULLFRAME || s->xpos == 0) outpicref->pts = av_rescale_q(insamples->pts, inlink->time_base, outlink->time_base); - s->xpos++; - if (s->orientation == VERTICAL && s->xpos >= s->w) - s->xpos = 0; - if (s->orientation == HORIZONTAL && s->xpos >= s->h) - s->xpos = 0; + if (s->sliding == LREPLACE) { + s->xpos--; + if (s->orientation == VERTICAL && s->xpos < 0) + s->xpos = s->w - 1; + if (s->orientation == HORIZONTAL && s->xpos < 0) + s->xpos = s->h - 1; + } else { + s->xpos++; + if (s->orientation == VERTICAL && s->xpos >= s->w) + s->xpos = 0; + if (s->orientation == HORIZONTAL && s->xpos >= s->h) + s->xpos = 0; + } + if (!s->single_pic && (s->sliding != FULLFRAME || s->xpos == 0)) { if (s->old_pts < outpicref->pts) { AVFrame *clone;