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

Stefano Sabatini stefasab at gmail.com
Sun Jun 17 14:17:25 CEST 2012


On date Saturday 2012-06-16 10:19:22 +0200, Clément Bœsch encoded:
> On Sat, Jun 16, 2012 at 01:49:40AM +0200, Stefano Sabatini wrote:
[...]
> > +static int request_frame(AVFilterLink *outlink)
> > +{
> > +    ShowWavesContext *showwaves = outlink->src->priv;
> > +    AVFilterLink *inlink = outlink->src->inputs[0];
> > +    AVFilterBufferRef *outpicref = showwaves->outpicref;
> > +    int ret;
> > +
> > +    showwaves->req_fullfilled = 0;
> > +    do {
> > +        ret = avfilter_request_frame(inlink);
> > +    } while (!showwaves->req_fullfilled && ret >= 0);
> > +
> > +    if (ret == AVERROR_EOF && showwaves->outpicref) {
> > +        int j, linesize = showwaves->outpicref->linesize[0];
> > +
> > +        /* fill last frame with zeroes */
> > +        while (showwaves->buf_idx < showwaves->w) {
> > +            for (j = 0; j < showwaves->nb_channels; j++)
> > +                *(showwaves->outpicref->data[0]
> > +                  + showwaves->buf_idx + showwaves->h/2 * linesize) = 255;
> > +            showwaves->buf_idx++;
> > +        }
> 
> The comment looks clumsy; it looks more correct to say "fill gap in the
> last frame with a zero signal" or something like that. You clearly are not
> creating silence/zero which is then drawn here.
> 
> Maybe you can create a function for this so it can be called with either 0
> or *p++ (in filter_samples()).

Removed, after all the samples are missing are not set to zero.

> > +
> > +        /* push frame */
> > +        ff_start_frame(outlink, outpicref);
> > +        ff_draw_slice(outlink, 0, outlink->h, 1);
> > +        ff_end_frame(outlink);
> > +        showwaves->req_fullfilled = 1;
> > +        showwaves->outpicref = NULL;
> > +        showwaves->buf_idx = 0;
> 
> You have the exact same chunk in filter_samples(), can't it be factorized?

Factorized.

> 
> > +    }
> > +
> > +    return ret;
> > +}
> > +
> > +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 i, j, h;
> > +
> > +    showwaves->nb_channels = av_get_channel_layout_nb_channels(insamples->audio->channel_layout);
> 
> Can't this be in a config_props() instead? Or just call a second time
> av_get_channel_layout_nb_channels() in request_frame()?

Removed, no longer required.
-- 
FFmpeg = Fancy and Fierce Magic Puritan Evangelical Gorilla
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-lavfi-add-showwaves-filter.patch
Type: text/x-diff
Size: 9405 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120617/7df92bba/attachment.bin>


More information about the ffmpeg-devel mailing list