History

avfilter/vf_stack: add fill option for xstack

Paul B Mahol committed 6 years ago

Commit a3e67c21 parent 07b3dbb2 files · +33 −0Browse files

Unified · Split

2 files
  1. doc/filters.texi +4 −0
  2. libavfilter/vf_stack.c +29 −0
doc/filters.texi+4−0
@@ -20062,6 +20062,10 @@ a layout must be set by the user. · 20061 unmodified lines
2006220062 @item shortest
2006320063 If set to 1, force the output to terminate when the shortest input
2006420064 terminates. Default value is 0.
20065+
20066+@item fill
20067+If set to valid color, all unused pixels will be filled with that color.
20068+By default fill is set to none, so it is disabled.
2006520069 @end table
2006620070
2006720071 @subsection Examples
libavfilter/vf_stack.c+29−0
@@ -21,9 +21,11 @@ · 20 unmodified lines
2121 #include "libavutil/avstring.h"
2222 #include "libavutil/imgutils.h"
2323 #include "libavutil/opt.h"
24+#include "libavutil/parseutils.h"
2425 #include "libavutil/pixdesc.h"
2526
2627 #include "avfilter.h"
28+#include "drawutils.h"
2729 #include "formats.h"
2830 #include "internal.h"
2931 #include "framesync.h"
@@ -44,6 +46,12 @@ typedef struct StackContext { · 14 unmodified lines
4446 int is_vertical;
4547 int is_horizontal;
4648 int nb_planes;
49+ uint8_t fillcolor[4];
50+ char *fillcolor_str;
51+ int fillcolor_enable;
52+
53+ FFDrawContext draw;
54+ FFDrawColor color;
4755
4856 StackItem *items;
4957 AVFrame **frames;
@@ -53,8 +61,13 @@ typedef struct StackContext { · 3 unmodified lines
5361 static int query_formats(AVFilterContext *ctx)
5462 {
5563 AVFilterFormats *pix_fmts = NULL;
64+ StackContext *s = ctx->priv;
5665 int fmt, ret;
5766
67+ if (s->fillcolor_enable) {
68+ return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
69+ }
70+
5871 for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
5972 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
6073 if (!(desc->flags & AV_PIX_FMT_FLAG_PAL ||
@@ -87,6 +100,12 @@ static av_cold int init(AVFilterContext *ctx) · 26 unmodified lines
87100 return AVERROR(ENOMEM);
88101
89102 if (!strcmp(ctx->filter->name, "xstack")) {
103+ if (strcmp(s->fillcolor_str, "none") &&
104+ av_parse_color(s->fillcolor, s->fillcolor_str, -1, ctx) >= 0) {
105+ s->fillcolor_enable = 1;
106+ } else {
107+ s->fillcolor_enable = 0;
108+ }
90109 if (!s->layout) {
91110 if (s->nb_inputs == 2) {
92111 s->layout = av_strdup("0_0|w0_0");
@@ -159,6 +178,10 @@ static int process_frame(FFFrameSync *fs) · 66 unmodified lines
159178 out->pts = av_rescale_q(s->fs.pts, s->fs.time_base, outlink->time_base);
160179 out->sample_aspect_ratio = outlink->sample_aspect_ratio;
161180
181+ if (s->fillcolor_enable)
182+ ff_fill_rectangle(&s->draw, &s->color, out->data, out->linesize,
183+ 0, 0, outlink->w, outlink->h);
184+
162185 ctx->internal->execute(ctx, process_slice, out, NULL, FFMIN(s->nb_inputs, ff_filter_get_nb_threads(ctx)));
163186
164187 return ff_filter_frame(outlink, out);
@@ -234,6 +257,11 @@ static int config_output(AVFilterLink *outlink) · 69 unmodified lines
234257 char *arg3, *p3, *saveptr3 = NULL;
235258 int inw, inh, size;
236259
260+ if (s->fillcolor_enable) {
261+ ff_draw_init(&s->draw, ctx->inputs[0]->format, 0);
262+ ff_draw_color(&s->draw, &s->color, s->fillcolor);
263+ }
264+
237265 for (i = 0; i < s->nb_inputs; i++) {
238266 AVFilterLink *inlink = ctx->inputs[i];
239267 StackItem *item = &s->items[i];
@@ -425,6 +453,7 @@ static const AVOption xstack_options[] = { · 185 unmodified lines
425453 { "inputs", "set number of inputs", OFFSET(nb_inputs), AV_OPT_TYPE_INT, {.i64=2}, 2, INT_MAX, .flags = FLAGS },
426454 { "layout", "set custom layout", OFFSET(layout), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, .flags = FLAGS },
427455 { "shortest", "force termination when the shortest input terminates", OFFSET(shortest), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, .flags = FLAGS },
456+ { "fill", "set the color for unused pixels", OFFSET(fillcolor_str), AV_OPT_TYPE_STRING, {.str = "none"}, .flags = FLAGS },
428457 { NULL },
429458 };
430459

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t