[FFmpeg-devel] [PATCH] lavfi: add showspectrum filter.

Clément Bœsch ubitux at gmail.com
Mon Aug 20 23:04:14 CEST 2012


On Thu, Aug 16, 2012 at 05:34:07PM +0200, Stefano Sabatini wrote:
> On date Wednesday 2012-08-15 17:56:37 +0200, Clément Bœsch encoded:
> [...]
> > From 6e17f2d21b40a4c65fd6961034d8a98f8ee3c22e Mon Sep 17 00:00:00 2001
> > From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <ubitux at gmail.com>
> > Date: Thu, 29 Dec 2011 23:45:45 +0100
> > Subject: [PATCH] lavfi: add showspectrum filter.
> > 
> > TODO: bump
> > TODO: changelog
> > ---
> >  doc/filters.texi               |  13 ++
> >  libavfilter/Makefile           |   1 +
> >  libavfilter/allfilters.c       |   1 +
> >  libavfilter/avf_showspectrum.c | 316 +++++++++++++++++++++++++++++++++++++++++
> >  4 files changed, 331 insertions(+)
> >  create mode 100644 libavfilter/avf_showspectrum.c
> > 
> > diff --git a/doc/filters.texi b/doc/filters.texi
> > index 763085c..c5eafc9 100644
> > --- a/doc/filters.texi
> > +++ b/doc/filters.texi
> > @@ -4139,6 +4139,19 @@ do not have exactly the same duration in the first file.
> >  
> >  @end itemize
> >  
> > + at section showspectrum
> > +
> > +Convert input audio to a video output, representing the audio spectrum.
> 
> Uhm maybe explains a bit of the math, e.g. what the video plane
> represent.
> 

I added "frequency" in the sentence; it should be fairly obvious for
anyone familiar with "audio spectrum". Feel free to extend the
description.

[...]
> > +typedef struct {
> > +    const AVClass *class;
> > +    int w, h;
> > +    AVFilterBufferRef *outpicref;
> > +    int req_fullfilled;
> > +    int xpos;                   ///< x position (current column)
> > +    RDFTContext *rdft;          ///< Real Discrete Fourier Transform context
> > +    int rdft_bits;              ///< number of bits (RDFT window size = 1<<rdft_bits)
> > +    FFTSample *rdft_data;       ///< bins holder for each (displayed) channels
> > +    int filled;                 ///< number of samples (per channel) filled in current rdft_buffer
> > +    int consumed;               ///< number of samples (per channel) consumed from the input frame
> 
> > +    float *windowing;           ///< Window function LUT
> 
> uhm... more meaningful name?
> 

Renamed to window_func_lut

[...]
> 
> > +        /* RDFT buffers: x2 for each (display) channel buffer */
> > +        av_free(showspectrum->rdft_data);
> > +        showspectrum->rdft_data = av_malloc(2 * win_size * sizeof(*showspectrum->rdft_data));
> > +        if (!showspectrum->rdft_data)
> > +            return AVERROR(ENOMEM);
> 
> av_realloc_f?
> 

Yup, changed.

> > +        showspectrum->filled = 0;
> > +
> > +        /* pre-calc windowing function (hann here) */
> > +        av_free(showspectrum->windowing);
> > +        showspectrum->windowing = av_malloc(win_size * sizeof(*showspectrum->windowing));
> > +        if (!showspectrum->windowing)
> > +            return AVERROR(ENOMEM);
> 
> As above
> 

Changed as well.

> > +        for (i = 0; i < win_size; i++)
> > +            showspectrum->windowing[i] = .5f * (1 - cos(2*M_PI*i / (win_size-1)));
> > +
> > +        /* prepare the initial picref buffer (black frame) */
> > +        avfilter_unref_bufferp(&showspectrum->outpicref);
> > +        showspectrum->outpicref = outpicref =
> > +            ff_get_video_buffer(outlink, AV_PERM_WRITE|AV_PERM_PRESERVE|AV_PERM_REUSE2,
> > +                                outlink->w, outlink->h);
> > +        if (!outpicref)
> > +            return AVERROR(ENOMEM);
> > +        outlink->sample_aspect_ratio = (AVRational){1,1};
> > +        memset(outpicref->data[0], 0, outlink->h * outpicref->linesize[0]);
> > +    }
> > +
> > +    if (showspectrum->xpos >= outlink->w)
> > +        showspectrum->xpos = 0;
> > +
> > +    av_log(ctx, AV_LOG_VERBOSE, "s:%dx%d RDFT window size:%d\n",
> > +           showspectrum->w, showspectrum->h, win_size);
> > +    return 0;
> > +}
> > +
> > +inline static void push_frame(AVFilterLink *outlink)
> > +{
> > +    ShowSpectrumContext *showspectrum = outlink->src->priv;
> > +
> > +    showspectrum->xpos++;
> > +    if (showspectrum->xpos >= outlink->w)
> > +        showspectrum->xpos = 0;
> > +    showspectrum->filled = 0;
> > +    showspectrum->req_fullfilled = 1;
> > +
> > +    ff_start_frame(outlink, avfilter_ref_buffer(showspectrum->outpicref, ~AV_PERM_READ));
> 
> ~AV_PERM_WRITE?
> 

Yeah, Nicolas pointed that out too, fixed.

> [...]
> 
> Looks good to me otherwise.

...and pushed with various other changes.

Thanks for the review

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120820/96926706/attachment.asc>


More information about the ffmpeg-devel mailing list