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

Clément Bœsch ubitux at gmail.com
Tue Mar 26 01:45:27 CET 2013


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.

[...]
> +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.

[...]
> +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;
         }
     }

[...]

Interesting filter btw, looking forward the next iteration.

-- 
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/20130326/2b5059fa/attachment.asc>


More information about the ffmpeg-devel mailing list