History

avfilter/vf_maskfun: add support for commands

Paul B Mahol committed 5 years ago

Commit ca042671 parent 8e027ca2 files · +71 −31Browse files

Unified · Split

2 files
  1. doc/filters.texi +4 −0
  2. libavfilter/vf_maskfun.c +67 −31
doc/filters.texi+4−0
@@ -14403,6 +14403,10 @@ average, output frame will be completely filled with value set by @var{fill} opt · 14402 unmodified lines
14403Typically useful for scene changes when used in combination with @code{tblend} filter.14403Typically useful for scene changes when used in combination with @code{tblend} filter.
14404@end table14404@end table
14405 14405
14406@subsection Commands
14407
14408This filter supports the all above options as @ref{commands}.
14409
14406@section mcdeint14410@section mcdeint
14407 14411
14408Apply motion-compensation deinterlacing.14412Apply motion-compensation deinterlacing.
libavfilter/vf_maskfun.c+67−31
@@ -47,14 +47,14 @@ typedef struct MaskFunContext { · 46 unmodified lines
47} MaskFunContext;47} MaskFunContext;
48 48
49#define OFFSET(x) offsetof(MaskFunContext, x)49#define OFFSET(x) offsetof(MaskFunContext, x)
50#define VF AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM50#define VFT AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
51 51
52static const AVOption maskfun_options[] = {52static const AVOption maskfun_options[] = {
53 { "low", "set low threshold", OFFSET(low), AV_OPT_TYPE_INT, {.i64=10}, 0, UINT16_MAX, VF },53 { "low", "set low threshold", OFFSET(low), AV_OPT_TYPE_INT, {.i64=10}, 0, UINT16_MAX, VFT },
54 { "high", "set high threshold", OFFSET(high), AV_OPT_TYPE_INT, {.i64=10}, 0, UINT16_MAX, VF },54 { "high", "set high threshold", OFFSET(high), AV_OPT_TYPE_INT, {.i64=10}, 0, UINT16_MAX, VFT },
55 { "planes", "set planes", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=0xF}, 0, 0xF, VF },55 { "planes", "set planes", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=0xF}, 0, 0xF, VFT },
56 { "fill", "set fill value", OFFSET(fill), AV_OPT_TYPE_INT, {.i64=0}, 0, UINT16_MAX, VF },56 { "fill", "set fill value", OFFSET(fill), AV_OPT_TYPE_INT, {.i64=0}, 0, UINT16_MAX, VFT },
57 { "sum", "set sum value", OFFSET(sum), AV_OPT_TYPE_INT, {.i64=10}, 0, UINT16_MAX, VF },57 { "sum", "set sum value", OFFSET(sum), AV_OPT_TYPE_INT, {.i64=10}, 0, UINT16_MAX, VFT },
58 { NULL }58 { NULL }
59};59};
60 60
@@ -182,6 +182,45 @@ static int maskfun##name(AVFilterContext *ctx, void *arg, \ · 121 unmodified lines
182MASKFUN(8, uint8_t, 1)182MASKFUN(8, uint8_t, 1)
183MASKFUN(16, uint16_t, 2)183MASKFUN(16, uint16_t, 2)
184 184
185static void fill_frame(AVFilterContext *ctx)
186{
187 MaskFunContext *s = ctx->priv;
188
189 s->fill = FFMIN(s->fill, s->max);
190 if (s->depth == 8) {
191 for (int p = 0; p < s->nb_planes; p++) {
192 uint8_t *dst = s->empty->data[p];
193
194 for (int y = 0; y < s->height[p]; y++) {
195 memset(dst, s->fill, s->width[p]);
196 dst += s->empty->linesize[p];
197 }
198 }
199 } else {
200 for (int p = 0; p < s->nb_planes; p++) {
201 uint16_t *dst = (uint16_t *)s->empty->data[p];
202
203 for (int y = 0; y < s->height[p]; y++) {
204 for (int x = 0; x < s->width[p]; x++)
205 dst[x] = s->fill;
206 dst += s->empty->linesize[p] / 2;
207 }
208 }
209 }
210}
211
212static void set_max_sum(AVFilterContext *ctx)
213{
214 MaskFunContext *s = ctx->priv;
215
216 s->max_sum = 0;
217 for (int p = 0; p < s->nb_planes; p++) {
218 if (!((1 << p) & s->planes))
219 continue;
220 s->max_sum += (uint64_t)s->sum * s->width[p] * s->height[p];
221 }
222}
223
185static int config_input(AVFilterLink *inlink)224static int config_input(AVFilterLink *inlink)
186{225{
187 AVFilterContext *ctx = inlink->dst;226 AVFilterContext *ctx = inlink->dst;
@@ -203,7 +242,6 @@ static int config_input(AVFilterLink *inlink) · 15 unmodified lines
203 242
204 s->depth = desc->comp[0].depth;243 s->depth = desc->comp[0].depth;
205 s->max = (1 << s->depth) - 1;244 s->max = (1 << s->depth) - 1;
206 s->fill = FFMIN(s->fill, s->max);
207 245
208 if (s->depth == 8) {246 if (s->depth == 8) {
209 s->maskfun = maskfun8;247 s->maskfun = maskfun8;
@@ -217,33 +255,30 @@ static int config_input(AVFilterLink *inlink) · 7 unmodified lines
217 if (!s->empty)255 if (!s->empty)
218 return AVERROR(ENOMEM);256 return AVERROR(ENOMEM);
219 257
220 if (s->depth == 8) {258 fill_frame(ctx);
221 for (int p = 0; p < s->nb_planes; p++) {
222 uint8_t *dst = s->empty->data[p];
223 259
224 for (int y = 0; y < s->height[p]; y++) {260 set_max_sum(ctx);
225 memset(dst, s->fill, s->width[p]);
226 dst += s->empty->linesize[p];
227 }
228 }
229 } else {
230 for (int p = 0; p < s->nb_planes; p++) {
231 uint16_t *dst = (uint16_t *)s->empty->data[p];
232 261
233 for (int y = 0; y < s->height[p]; y++) {262 return 0;
234 for (int x = 0; x < s->width[p]; x++)263}
235 dst[x] = s->fill;
236 dst += s->empty->linesize[p] / 2;
237 }
238 }
239 }
240 264
241 s->max_sum = 0;265static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
242 for (int p = 0; p < s->nb_planes; p++) {266 char *res, int res_len, int flags)
243 if (!((1 << p) & s->planes))267{
244 continue;268 MaskFunContext *s = ctx->priv;
245 s->max_sum += (uint64_t)s->sum * s->width[p] * s->height[p];269 int fill = s->fill;
246 }270 int sum = s->sum;
271 int ret;
272
273 ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
274 if (ret < 0)
275 return ret;
276
277 if (sum != s->sum)
278 set_max_sum(ctx);
279
280 if (fill != s->fill)
281 fill_frame(ctx);
247 282
248 return 0;283 return 0;
249}284}
@@ -284,4 +319,5 @@ AVFilter ff_vf_maskfun = { · 34 unmodified lines
284 .outputs = maskfun_outputs,319 .outputs = maskfun_outputs,
285 .priv_class = &maskfun_class,320 .priv_class = &maskfun_class,
286 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,321 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
322 .process_command = process_command,
287};323};

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