[FFmpeg-devel] [PATCH] lavfi/select: add support to branch option

Stefano Sabatini stefasab at gmail.com
Mon Apr 15 00:03:50 CEST 2013


On date Wednesday 2013-04-10 16:54:36 +0200, Nicolas George encoded:
> Le primidi 21 germinal, an CCXXI, Stefano Sabatini a écrit :
> > Updated, with some non-trivial fixes raised by splice.
> > -- 
> > FFmpeg = Formidable and Free Mythic Picky Exploitable Gymnast
> 
> > >From e2985e730f1483fa55521b32b4ecc8c2926f56ae Mon Sep 17 00:00:00 2001
> > From: Stefano Sabatini <stefasab at gmail.com>
> > Date: Mon, 8 Apr 2013 12:58:56 +0200
> > Subject: [PATCH] lavfi/select: add support to branch option
> > 
> > TODO: bump micro, add docs
> > ---
> >  libavfilter/f_select.c |   33 +++++++++++++++++++++++++++++----
> >  1 file changed, 29 insertions(+), 4 deletions(-)
> 
> No docs?
> 
> > 
> > diff --git a/libavfilter/f_select.c b/libavfilter/f_select.c
> > index 351b7f8..adae0be 100644
> > --- a/libavfilter/f_select.c
> > +++ b/libavfilter/f_select.c
> > @@ -135,7 +135,8 @@ typedef struct {
> >      double prev_mafd;               ///< previous MAFD                             (scene detect only)
> >  #endif
> >      AVFrame *prev_picref; ///< previous frame                            (scene detect only)
> > -    double select;
> > +    double select, select_branch;
> > +    int branch;
> >  } SelectContext;
> >  
> >  #define OFFSET(x) offsetof(SelectContext, x)
> > @@ -143,9 +144,13 @@ typedef struct {
> >  static const AVOption options[] = {
> >      { "expr", "set selection expression", OFFSET(expr_str), AV_OPT_TYPE_STRING, {.str = "1"}, 0, 0, FLAGS },
> >      { "e",    "set selection expression", OFFSET(expr_str), AV_OPT_TYPE_STRING, {.str = "1"}, 0, 0, FLAGS },
> > +    { "branch", "enable alternative output", OFFSET(branch), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS },
> > +    { "b",      "enable alternative output", OFFSET(branch), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS },
> >      {NULL},
> >  };
> >  
> > +static int request_frame(AVFilterLink *outlink);
> > +
> >  static av_cold int init(AVFilterContext *ctx, const char *args, const AVClass *class)
> >  {
> >      SelectContext *select = ctx->priv;
> > @@ -158,6 +163,17 @@ static av_cold int init(AVFilterContext *ctx, const char *args, const AVClass *c
> >      }
> >      select->do_scene_detect = !!strstr(select->expr_str, "scene");
> >  
> > +    if (select->branch) {
> > +        AVFilterPad pad = { 0 };
> > +
> > +        pad.type = ctx->filter->inputs[0].type;
> > +        pad.name = av_strdup("branch");
> > +        pad.request_frame = request_frame;
> > +        if (!pad.name)
> > +            return AVERROR(ENOMEM);
> > +        ff_insert_outpad(ctx, 1, &pad);
> > +    }
> > +
> >      return 0;
> >  }
> >  
> > @@ -337,8 +353,12 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
> >      SelectContext *select = inlink->dst->priv;
> >  
> >      select->select = select_frame(inlink->dst, frame);
> > -    if (select->select)
> > +    if (select->select) {
> >          return ff_filter_frame(inlink->dst->outputs[0], frame);
> > +    } else if (select->branch) {
> > +        select->select_branch = 1;
> > +        return ff_filter_frame(inlink->dst->outputs[1], frame);
> > +    }
> 
> If I understand correctly, that means: if the expression returns true, send
> to the normal output, if the expression returns 0, [-discard-] {+send to the
> "branch" output+}. Is that it?
> 

> That looks a bit ad-hoc. What about: outputs=n, and send to output number
> floor(expr)?

Readjusted to make it backward-compatible.

BTW I got this::
ffplay IN -vf "[in]select=n=2:e='random(0)*2'[s1][s2]; [s1] pad=h=2*ih [a]; [a][s2] overlay=y=h [out]"
Assertion !link->frame_requested || link->flags & FF_LINK_FLAG_REQUEST_LOOP failed at libavfilter/avfilter.c:344

Do you know why?
-- 
FFmpeg = F***ing & Fostering Monstrous Plastic Emblematic Gladiator
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-lavfi-select-add-support-for-dynamic-number-of-outpu.patch
Type: text/x-diff
Size: 8190 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130415/83f4e517/attachment.bin>


More information about the ffmpeg-devel mailing list