[FFmpeg-devel] [PATCH 2/2] avfilter: add showspectrumpic filter

Paul B Mahol onemda at gmail.com
Fri Jan 1 19:54:50 CET 2016


On 1/1/16, Clement Boesch <u at pkh.me> wrote:
> On Fri, Jan 01, 2016 at 10:00:31AM +0100, Paul B Mahol wrote:
>> Signed-off-by: Paul B Mahol <onemda at gmail.com>
>> ---
>>  doc/filters.texi               | 106 +++++++++++++++++++
>>  libavfilter/Makefile           |   1 +
>>  libavfilter/allfilters.c       |   1 +
>>  libavfilter/avf_showspectrum.c | 233
>> ++++++++++++++++++++++++++++++++++++++---
>>  4 files changed, 326 insertions(+), 15 deletions(-)
>>
> [...]
>> diff --git a/libavfilter/avf_showspectrum.c
>> b/libavfilter/avf_showspectrum.c
>> index 0fa1be1..2992c2f 100644
>> --- a/libavfilter/avf_showspectrum.c
>> +++ b/libavfilter/avf_showspectrum.c
>> @@ -63,6 +63,7 @@ typedef struct {
>>      int rdft_bits;              ///< number of bits (RDFT window size =
>> 1<<rdft_bits)
>>      FFTSample **rdft_data;      ///< bins holder for each (displayed)
>> channels
>>      float *window_func_lut;     ///< Window function LUT
>> +    float **magnitudes;
>>      int win_func;
>>      int win_size;
>>      double win_scale;
>> @@ -186,6 +187,9 @@ static av_cold void uninit(AVFilterContext *ctx)
>>          av_freep(&s->rdft_data[i]);
>>      av_freep(&s->rdft_data);
>>      av_freep(&s->window_func_lut);
>> +    for (i = 0; i < s->nb_display_channels; i++)
>> +        av_freep(&s->magnitudes[i]);
>> +    av_freep(&s->magnitudes);
>>      av_frame_free(&s->outpicref);
>>      av_audio_fifo_free(s->fifo);
>>  }
>> @@ -267,6 +271,15 @@ static int config_output(AVFilterLink *outlink)
>>          av_freep(&s->rdft_data);
>>          s->nb_display_channels = inlink->channels;
>>
>> +        s->magnitudes = av_calloc(s->nb_display_channels,
>> sizeof(*s->magnitudes));
>> +        if (!s->magnitudes)
>> +            return AVERROR(ENOMEM);
>> +        for (i = 0; i < s->nb_display_channels; i++) {
>> +            s->magnitudes[i] = av_calloc(s->orientation == VERTICAL ?
>> s->h: s->w, sizeof(**s->magnitudes));
>
> nit: space before ':' (you have the same typo later on for some reason)
>
> [...]
>> +static const AVOption showspectrumpic_options[] = {
>> +    { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str
>> = "640x512"}, 0, 0, FLAGS },
>> +    { "s",    "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str
>> = "640x512"}, 0, 0, FLAGS },
>> +    { "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" },
>> +    { "color", "set channel coloring", OFFSET(color_mode),
>> AV_OPT_TYPE_INT, {.i64=CHANNEL}, CHANNEL, NB_CLMODES-1, FLAGS, "color" },
>> +        { "channel",   "separate color for each channel", 0,
>> AV_OPT_TYPE_CONST, {.i64=CHANNEL},   0, 0, FLAGS, "color" },
>> +        { "intensity", "intensity based coloring",        0,
>> AV_OPT_TYPE_CONST, {.i64=INTENSITY}, 0, 0, FLAGS, "color" },
>> +        { "rainbow",   "rainbow based coloring",          0,
>> AV_OPT_TYPE_CONST, {.i64=RAINBOW},   0, 0, FLAGS, "color" },
>> +        { "moreland",  "moreland based coloring",         0,
>> AV_OPT_TYPE_CONST, {.i64=MORELAND},  0, 0, FLAGS, "color" },
>> +        { "nebulae",   "nebulae based coloring",          0,
>> AV_OPT_TYPE_CONST, {.i64=NEBULAE},   0, 0, FLAGS, "color" },
>> +        { "fire",      "fire based coloring",             0,
>> AV_OPT_TYPE_CONST, {.i64=FIRE},      0, 0, FLAGS, "color" },
>> +    { "scale", "set display scale", OFFSET(scale), AV_OPT_TYPE_INT,
>> {.i64=SQRT}, LINEAR, NB_SCALES-1, FLAGS, "scale" },
>> +        { "sqrt", "square root", 0, AV_OPT_TYPE_CONST, {.i64=SQRT},   0,
>> 0, FLAGS, "scale" },
>> +        { "cbrt", "cubic root",  0, AV_OPT_TYPE_CONST, {.i64=CBRT},   0,
>> 0, FLAGS, "scale" },
>> +        { "log",  "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=LOG},    0,
>> 0, FLAGS, "scale" },
>> +        { "lin",  "linear",      0, AV_OPT_TYPE_CONST, {.i64=LINEAR}, 0,
>> 0, FLAGS, "scale" },
>> +    { "saturation", "color saturation multiplier", OFFSET(saturation),
>> AV_OPT_TYPE_FLOAT, {.dbl = 1}, -10, 10, FLAGS },
>> +    { "win_func", "set window function", OFFSET(win_func),
>> AV_OPT_TYPE_INT, {.i64 = WFUNC_HANNING}, 0, NB_WFUNC-1, FLAGS, "win_func"
>> },
>> +        { "rect",     "Rectangular",      0, AV_OPT_TYPE_CONST,
>> {.i64=WFUNC_RECT},     0, 0, FLAGS, "win_func" },
>> +        { "bartlett", "Bartlett",         0, AV_OPT_TYPE_CONST,
>> {.i64=WFUNC_BARTLETT}, 0, 0, FLAGS, "win_func" },
>> +        { "hann",     "Hann",             0, AV_OPT_TYPE_CONST,
>> {.i64=WFUNC_HANNING},  0, 0, FLAGS, "win_func" },
>> +        { "hanning",  "Hanning",          0, AV_OPT_TYPE_CONST,
>> {.i64=WFUNC_HANNING},  0, 0, FLAGS, "win_func" },
>> +        { "hamming",  "Hamming",          0, AV_OPT_TYPE_CONST,
>> {.i64=WFUNC_HAMMING},  0, 0, FLAGS, "win_func" },
>> +        { "blackman", "Blackman",         0, AV_OPT_TYPE_CONST,
>> {.i64=WFUNC_BLACKMAN}, 0, 0, FLAGS, "win_func" },
>> +        { "welch",    "Welch",            0, AV_OPT_TYPE_CONST,
>> {.i64=WFUNC_WELCH},    0, 0, FLAGS, "win_func" },
>> +        { "flattop",  "Flat-top",         0, AV_OPT_TYPE_CONST,
>> {.i64=WFUNC_FLATTOP},  0, 0, FLAGS, "win_func" },
>> +        { "bharris",  "Blackman-Harris",  0, AV_OPT_TYPE_CONST,
>> {.i64=WFUNC_BHARRIS},  0, 0, FLAGS, "win_func" },
>> +        { "bnuttall", "Blackman-Nuttall", 0, AV_OPT_TYPE_CONST,
>> {.i64=WFUNC_BNUTTALL}, 0, 0, FLAGS, "win_func" },
>> +        { "bhann",    "Bartlett-Hann",    0, AV_OPT_TYPE_CONST,
>> {.i64=WFUNC_BHANN},    0, 0, FLAGS, "win_func" },
>> +        { "sine",     "Sine",             0, AV_OPT_TYPE_CONST,
>> {.i64=WFUNC_SINE},     0, 0, FLAGS, "win_func" },
>> +        { "nuttall",  "Nuttall",          0, AV_OPT_TYPE_CONST,
>> {.i64=WFUNC_NUTTALL},  0, 0, FLAGS, "win_func" },
>> +        { "lanczos",  "Lanczos",          0, AV_OPT_TYPE_CONST,
>> {.i64=WFUNC_LANCZOS},  0, 0, FLAGS, "win_func" },
>> +        { "gauss",    "Gauss",            0, AV_OPT_TYPE_CONST,
>> {.i64=WFUNC_GAUSS},    0, 0, FLAGS, "win_func" },
>> +    { "orientation", "set orientation", OFFSET(orientation),
>> AV_OPT_TYPE_INT, {.i64=VERTICAL}, 0, NB_ORIENTATIONS-1, FLAGS,
>> "orientation" },
>> +        { "vertical",   NULL, 0, AV_OPT_TYPE_CONST, {.i64=VERTICAL},   0,
>> 0, FLAGS, "orientation" },
>> +        { "horizontal", NULL, 0, AV_OPT_TYPE_CONST, {.i64=HORIZONTAL}, 0,
>> 0, FLAGS, "orientation" },
>
> The duplication can probably be avoided; I'm assuming you didn't because
> you removed options in the middle?

Yes, the most offending ones, window_func ones can be probably be
moved to header.

>
> [...]
>
> --
> Clement B.
>


More information about the ffmpeg-devel mailing list