[FFmpeg-devel] [PATCH] avfilter/avf_showwaves: add draw grid support
Dave Rice
dave at dericed.com
Tue Nov 21 17:52:26 EET 2017
> On Nov 21, 2017, at 7:36 AM, Paul B Mahol <onemda at gmail.com> wrote:
>
> Signed-off-by: Paul B Mahol <onemda at gmail.com>
> ---
> doc/filters.texi | 6 ++++++
> libavfilter/avf_showwaves.c | 28 ++++++++++++++++++++++++++++
> 2 files changed, 34 insertions(+)
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 62f633c6f8..9c98f1684b 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -19178,6 +19178,12 @@ Cubic root.
> @end table
>
> Default is linear.
> +
> + at item grid
> +Draw grid, default is disabled.
> +
> + at item grid_color
> +Set grid color.
> @end table
>
> @subsection Examples
> diff --git a/libavfilter/avf_showwaves.c b/libavfilter/avf_showwaves.c
> index 0866967984..74d4886cd4 100644
> --- a/libavfilter/avf_showwaves.c
> +++ b/libavfilter/avf_showwaves.c
> @@ -69,6 +69,8 @@ typedef struct ShowWavesContext {
> int mode; ///< ShowWavesMode
> int scale; ///< ShowWavesScale
> int split_channels;
> + int grid;
> + uint8_t grid_rgba[4];
> uint8_t *fg;
>
> int (*get_h)(int16_t sample, int height);
> @@ -104,6 +106,8 @@ static const AVOption showwaves_options[] = {
> { "log", "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=SCALE_LOG}, .flags=FLAGS, .unit="scale"},
> { "sqrt", "square root", 0, AV_OPT_TYPE_CONST, {.i64=SCALE_SQRT}, .flags=FLAGS, .unit="scale"},
> { "cbrt", "cubic root", 0, AV_OPT_TYPE_CONST, {.i64=SCALE_CBRT}, .flags=FLAGS, .unit="scale"},
> + { "grid", "draw grid", OFFSET(grid), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
> + { "grid_color", "set grid color", OFFSET(grid_rgba), AV_OPT_TYPE_COLOR, {.str="0x333300"}, 0, 0, FLAGS },
> { NULL }
> };
>
> @@ -562,6 +566,30 @@ static int alloc_out_frame(ShowWavesContext *showwaves, const int16_t *p,
> outlink->time_base);
> for (j = 0; j < outlink->h; j++)
> memset(out->data[0] + j*out->linesize[0], 0, outlink->w * showwaves->pixstep);
> +
> + if (showwaves->grid) {
> + const int pixstep = showwaves->pixstep;
> + int ystep = showwaves->split_channels ? outlink->h / inlink->channels / 4 : outlink->h / 4;
> + int channels = showwaves->split_channels ? inlink->channels : 1;
> + int x, s, c, yskip = 0;
> +
> + for (c = 0; c < channels; c++) {
> + for (j = 0; j < 4; j++) {
> + for (x = 0; x < outlink->w; x+=3) {
> + for (s = 0; s < pixstep; s++) {
> + out->data[0][(yskip + j * ystep) * out->linesize[0] + x * pixstep + s] = showwaves->grid_rgba[s];
> + }
> + }
> + }
> + for (x = 0; x < outlink->w; x+=3) {
> + for (s = 0; s < pixstep; s++) {
> + out->data[0][(yskip + j * ystep - 1) * out->linesize[0] + x * pixstep + s] = showwaves->grid_rgba[s];
> + }
> + }
> +
> + yskip += j * ystep;
> + }
> + }
> }
> return 0;
> }
> --
> 2.11.0
Seems interesting but do the gridlines convey any meaning? Perhaps a flags value too similar to waveform that should label the lines in dB or as a float. Also perhaps worth adjustment the placement of the gridlines depending on a scale (log vs lin).
Dave Rice
More information about the ffmpeg-devel
mailing list