[FFmpeg-devel] [PATCH] lavfi: phasescope filter

Paul B Mahol onemda at gmail.com
Tue Mar 26 11:36:54 CET 2013


On 3/26/13, Clement Boesch <ubitux at gmail.com> wrote:
> On Mon, Mar 25, 2013 at 10:23:51PM +0000, Paul B Mahol wrote:
>> Signed-off-by: Paul B Mahol <onemda at gmail.com>
>> ---
>>
>> TODO:
>> documentation, more modes, colors, sample formats, channel layouts and
>> fancy output.
>>
> [...]
>> +static av_cold int init(AVFilterContext *ctx, const char *args)
>> +{
>> +    PhaseScopeContext *p = ctx->priv;
>> +    int err;
>> +
>> +    p->class = &phasescope_class;
>> +    av_opt_set_defaults(p);
>> +
>> +    if ((err = av_set_options_string(p, args, "=", ":")) < 0)
>> +        return err;
>> +
>> +    return 0;
>> +}
>> +
>
> You can drop all of this by just specifying a shorthand.

Changed.

>
> [...]
>> +static int config_input(AVFilterLink *inlink)
>> +{
>> +    AVFilterContext *ctx = inlink->dst;
>> +    PhaseScopeContext *p = ctx->priv;
>> +
>> +    p->nb_samples = FFMAX(1024, ((double)inlink->sample_rate /
>> av_q2d(p->frame_rate)) + 0.5);
>> +    inlink->partial_buf_size =
>> +    inlink->min_samples =
>> +    inlink->max_samples = p->nb_samples;
>> +
>
> Note that this might not work in some cases.

When? Why?

>
> [...]
>> +static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
>> +{
>> +    AVFilterContext *ctx = inlink->dst;
>> +    AVFilterLink *outlink = ctx->outputs[0];
>> +    PhaseScopeContext *p = ctx->priv;
>> +    const int nb_samples = insamples->nb_samples;
>> +    const int linesize = p->outpicref->linesize[0];
>> +    const int hw = p->w / 2;
>> +    const int hh = p->h / 2;
>> +    int16_t *ptr = (int16_t *)insamples->data[0];
>> +    int i, j, chan, v, ret;
>> +    uint8_t *dst;
>> +
>> +    p->outpicref->pts = insamples->pts;
>> +
>
>> +    if (p->dissolve) {
>> +        for (i = 0; i < p->h; i++) {
>> +            for (j = 0; j < p->w; j++) {
>> +                dst = &p->outpicref->data[0][i * linesize + j];
>> +                v = *dst;
>> +                *dst = FFMAX(v - p->dissolve, 0);
>> +            }
>> +        }
>> +    }
>> +
>
> I get a nice performance boost here by doing this:
>
>      if (p->dissolve) {
> +        dst = p->outpicref->data[0];
>          for (i = 0; i < p->h; i++) {
>              for (j = 0; j < p->w; j++) {
> -                dst = &p->outpicref->data[0][i * linesize + j];
> -                v = *dst;
> -                *dst = FFMAX(v - p->dissolve, 0);
> +                v = dst[j];
> +                dst[j] = FFMAX(v - p->dissolve, 0);
>              }
> +            dst += linesize;
>          }
>      }

Thanks, changed.

>
> [...]
>
> Interesting filter btw, looking forward the next iteration.
>
> --
> Clement B.
>


More information about the ffmpeg-devel mailing list