[FFmpeg-devel] [PATCH 3/5] lavfi: add a new filtergraph parsing API

Anton Khirnov anton at khirnov.net
Wed Feb 1 09:02:20 EET 2023


Quoting Nicolas George (2023-01-30 13:59:44)
> > +static unsigned
> > +find_linklabel(AVFilterGraphSegment *seg, const char *label,
> > +               int output, size_t idx_chain, size_t idx_filter,
> > +               AVFilterParams **pp)
> > +{
> > +    for (; idx_chain < seg->nb_chains; idx_chain++) {
> > +        AVFilterChain *ch = seg->chains[idx_chain];
> > +
> > +        for (; idx_filter < ch->nb_filters; idx_filter++) {
> > +            AVFilterParams *p = ch->filters[idx_filter];
> > +            AVFilterPadParams **io = output ? p->outputs    : p->inputs;
> > +            unsigned         nb_io = output ? p->nb_outputs : p->nb_inputs;
> > +            AVFilterLink **l;
> > +            unsigned nb_l;
> > +
> > +            if (!p->filter)
> > +                continue;
> > +
> > +            l    = output ? p->filter->outputs    : p->filter->inputs;
> > +            nb_l = output ? p->filter->nb_outputs : p->filter->nb_inputs;
> > +
> > +            for (unsigned i = 0; i < FFMIN(nb_io, nb_l); i++)
> > +                if (!l[i] && io[i]->label && !strcmp(io[i]->label, label)) {
> > +                    *pp = p;
> > +                    return i;
> > +                }
> > +        }
> > +
> > +        idx_filter = 0;
> > +    }
> > +
> > +    *pp = NULL;
> > +    return 0;
> > +}
> 
> If I read this code correctly, it will only find link labels that are
> defined later in the chain or in a later chain. But referring to earlier
> link labels is supported. Even cycles are meant to be supported at
> parsing level (format negotiation will likely fail, though, but being
> able to make cycles was a goal from the start).

The earlier filters have already been processed at this point, so if an
earlier filter had a link label that would match this one, then it's
already been linked. So there's no point in considering earlier filters.

-- 
Anton Khirnov


More information about the ffmpeg-devel mailing list