[FFmpeg-devel] [PATCH] lavfi: add showwaves filter

Stefano Sabatini stefasab at gmail.com
Mon Jun 18 18:19:26 CEST 2012


On date Sunday 2012-06-17 14:56:35 +0200, Nicolas George encoded:
[...]
> > +static int query_formats(AVFilterContext *ctx)
> > +{
> > +    AVFilterFormats *formats = NULL;
> > +    AVFilterChannelLayouts *layouts = NULL;
> > +    AVFilterLink *inlink = ctx->inputs[0];
> > +    AVFilterLink *outlink = ctx->outputs[0];
> > +    static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_DBL, -1 };
> 
> Using S16 would make the filter require less conversions and be bit-exact on
> various architectures. You can use av_rescale to compute the height of the
> bars.

Changed.

[...] 
> > +static int config_output(AVFilterLink *outlink)
> > +{
> > +    AVFilterContext *ctx = outlink->src;
> > +    ShowWavesContext *showwaves = ctx->priv;
> > +
> > +    outlink->w = showwaves->w;
> > +    outlink->h = showwaves->h;
> 
> outlink->frame_rate = av_div_q((AVRational){ inlink->sample_rate, 1},
>                                (AVRational){ showwaves->w, 1 });
> 
> ... or something like that should allow it to work with -filter_complex too.> 

Fixed.

[...]
> > +static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
> > +{
> > +    AVFilterContext *ctx = inlink->dst;
> > +    AVFilterLink *outlink = ctx->outputs[0];
> > +    ShowWavesContext *showwaves = ctx->priv;
> > +    const int nb_samples = insamples->audio->nb_samples;
> > +    AVFilterBufferRef *outpicref = showwaves->outpicref;
> > +    int linesize = outpicref ? outpicref->linesize[0] : 0;
> > +    double *p = (double *)insamples->data[0];
> > +    int nb_channels = av_get_channel_layout_nb_channels(insamples->audio->channel_layout);
> > +    int i, j, h;
> > +
> > +    /* draw data in the buffer */
> > +    for (i = 0; i < nb_samples; i++) {
> > +        if (showwaves->buf_idx == 0) {
> > +            showwaves->outpicref = outpicref =
> > +                ff_get_video_buffer(outlink, AV_PERM_WRITE|AV_PERM_ALIGN,
> > +                                    outlink->w, outlink->h);
> > +            outpicref->video->w = outlink->w;
> > +            outpicref->video->h = outlink->h;
> > +            outpicref->pts = insamples->pts;
> > +            outlink->out_buf = outpicref;
> > +            linesize = outpicref->linesize[0];
> > +            memset(outpicref->data[0], 0, showwaves->h*linesize);
> > +        }
> > +        for (j = 0; j < nb_channels; j++) {
> > +            h = showwaves->h/2 - (*p++ * showwaves->h/2);
> > +            if (h < outlink->h)
> > +                *(outpicref->data[0] + showwaves->buf_idx + h * linesize) = 255;
> > +        }
> > +        showwaves->buf_idx++;
> > +
> > +        if (showwaves->buf_idx == showwaves->w)
> > +            push_frame(outlink);
> 
> With sample_rate = 44100 and w = 320, that makes 138 frames per second, it
> is probably too much. What about incrementing buf_idx only once in n times,
> n being an option defaulting to maybe 4.
> 
> And in that case, "= 255" may be replaced by "+= x", where x would be 255 /
> (nb_channels * n)

Very good idea, I changed this and added a new rate parameters, which
changes the n parameter to honor the specified framerate.

I also changed the default size from 320x240 to 800x200, which seems
more useful for visualizing audio data.

[...]
-- 
FFmpeg = Formidable and Forgiving Mystic Portentous Epic God
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-lavfi-add-showwaves-filter.patch
Type: text/x-diff
Size: 11926 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120618/73b44ecd/attachment.bin>


More information about the ffmpeg-devel mailing list