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

Stefano Sabatini stefasab at gmail.com
Mon Apr 8 20:12:34 CEST 2013


TODO: bump micro, add docs
---
 libavfilter/f_select.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/libavfilter/f_select.c b/libavfilter/f_select.c
index 351b7f8..d46852e 100644
--- a/libavfilter/f_select.c
+++ b/libavfilter/f_select.c
@@ -136,6 +136,7 @@ typedef struct {
 #endif
     AVFrame *prev_picref; ///< previous frame                            (scene detect only)
     double select;
+    int branch;
 } SelectContext;
 
 #define OFFSET(x) offsetof(SelectContext, x)
@@ -143,6 +144,7 @@ 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 },
     {NULL},
 };
 
@@ -158,6 +160,16 @@ 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");
+        if (!pad.name)
+            return AVERROR(ENOMEM);
+        ff_insert_outpad(ctx, 1, &pad);
+    }
+
     return 0;
 }
 
@@ -339,6 +351,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
     select->select = select_frame(inlink->dst, frame);
     if (select->select)
         return ff_filter_frame(inlink->dst->outputs[0], frame);
+    else if (select->branch)
+        return ff_filter_frame(inlink->dst->outputs[1], frame);
 
     av_frame_free(&frame);
     return 0;
@@ -367,6 +381,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);
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list