[FFmpeg-devel] [PATCH] lavfi/select: add support to branch option
Nicolas George
nicolas.george at normalesup.org
Wed Apr 10 16:54:36 CEST 2013
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)?
>
> av_frame_free(&frame);
> return 0;
> @@ -349,13 +369,15 @@ static int request_frame(AVFilterLink *outlink)
> AVFilterContext *ctx = outlink->src;
> SelectContext *select = ctx->priv;
> AVFilterLink *inlink = outlink->src->inputs[0];
> - select->select = 0;
> + int branch = outlink == ctx->outputs[1];
> +
> + select->select = select->select_branch = 0;
>
> do {
> int ret = ff_request_frame(inlink);
> if (ret < 0)
> return ret;
> - } while (!select->select);
> + } while (!select->select || (branch && !select->select_branch));
>
> return 0;
> }
> @@ -367,6 +389,9 @@ static av_cold void uninit(AVFilterContext *ctx)
> av_expr_free(select->expr);
> select->expr = NULL;
>
> + if (select->branch)
> + av_freep(&ctx->output_pads[1].name);
> +
> #if CONFIG_AVCODEC
> if (select->do_scene_detect) {
> av_frame_free(&select->prev_picref);
Regards,
--
Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130410/13ed3ee3/attachment.asc>
More information about the ffmpeg-devel
mailing list