FFmpeg
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vf_overlay.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 Stefano Sabatini
3  * Copyright (c) 2010 Baptiste Coudurier
4  * Copyright (c) 2007 Bobby Bingham
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 /**
24  * @file
25  * overlay one video on top of another
26  */
27 
28 /* #define DEBUG */
29 
30 #include "avfilter.h"
31 #include "formats.h"
32 #include "libavutil/common.h"
33 #include "libavutil/eval.h"
34 #include "libavutil/avstring.h"
35 #include "libavutil/opt.h"
36 #include "libavutil/pixdesc.h"
37 #include "libavutil/imgutils.h"
38 #include "libavutil/mathematics.h"
39 #include "libavutil/timestamp.h"
40 #include "internal.h"
41 #include "bufferqueue.h"
42 #include "drawutils.h"
43 #include "video.h"
44 
45 static const char *const var_names[] = {
46  "main_w", "W", ///< width of the main video
47  "main_h", "H", ///< height of the main video
48  "overlay_w", "w", ///< width of the overlay video
49  "overlay_h", "h", ///< height of the overlay video
50  NULL
51 };
52 
53 enum var_name {
59 };
60 
61 #define MAIN 0
62 #define OVERLAY 1
63 
64 #define R 0
65 #define G 1
66 #define B 2
67 #define A 3
68 
69 #define Y 0
70 #define U 1
71 #define V 2
72 
73 typedef struct {
74  const AVClass *class;
75  int x, y; ///< position of overlayed picture
76 
81  uint8_t main_rgba_map[4];
84  uint8_t overlay_rgba_map[4];
86  enum OverlayFormat { OVERLAY_FORMAT_YUV420, OVERLAY_FORMAT_YUV444, OVERLAY_FORMAT_RGB, OVERLAY_FORMAT_NB} format;
87 
89  struct FFBufQueue queue_main;
90  struct FFBufQueue queue_over;
91 
92  int main_pix_step[4]; ///< steps per pixel for each plane of the main output
93  int overlay_pix_step[4]; ///< steps per pixel for each plane of the overlay
94  int hsub, vsub; ///< chroma subsampling values
95  int shortest; ///< terminate stream when the shortest input terminates
96 
97  char *x_expr, *y_expr;
99 
100 #define OFFSET(x) offsetof(OverlayContext, x)
101 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
102 
103 static const AVOption overlay_options[] = {
104  { "x", "set the x expression", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str = "0"}, CHAR_MIN, CHAR_MAX, FLAGS },
105  { "y", "set the y expression", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str = "0"}, CHAR_MIN, CHAR_MAX, FLAGS },
106  { "rgb", "force packed RGB in input and output (deprecated)", OFFSET(allow_packed_rgb), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS },
107  { "shortest", "force termination when the shortest input terminates", OFFSET(shortest), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
108 
109  { "format", "set output format", OFFSET(format), AV_OPT_TYPE_INT, {.i64=OVERLAY_FORMAT_YUV420}, 0, OVERLAY_FORMAT_NB-1, FLAGS, "format" },
110  { "yuv420", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_YUV420}, .flags = FLAGS, .unit = "format" },
111  { "yuv444", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_YUV444}, .flags = FLAGS, .unit = "format" },
112  { "rgb", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_RGB}, .flags = FLAGS, .unit = "format" },
113 
114  { NULL }
115 };
116 
117 AVFILTER_DEFINE_CLASS(overlay);
118 
119 static av_cold int init(AVFilterContext *ctx, const char *args)
120 {
121  OverlayContext *over = ctx->priv;
122  static const char *shorthand[] = { "x", "y", NULL };
123  int ret;
124 
125  over->class = &overlay_class;
126  av_opt_set_defaults(over);
127 
128  ret = av_opt_set_from_string(over, args, shorthand, "=", ":");
129  if (ret < 0)
130  return ret;
131 
132  if (over->allow_packed_rgb) {
133  av_log(ctx, AV_LOG_WARNING,
134  "The rgb option is deprecated and is overriding the format option, use format instead\n");
135  over->format = OVERLAY_FORMAT_RGB;
136  }
137  return 0;
138 }
139 
140 static av_cold void uninit(AVFilterContext *ctx)
141 {
142  OverlayContext *over = ctx->priv;
143 
144  av_opt_free(over);
145 
149 }
150 
152 {
153  OverlayContext *over = ctx->priv;
154 
155  /* overlay formats contains alpha, for avoiding conversion with alpha information loss */
156  static const enum AVPixelFormat main_pix_fmts_yuv420[] = {
158  };
159  static const enum AVPixelFormat overlay_pix_fmts_yuv420[] = {
161  };
162 
163  static const enum AVPixelFormat main_pix_fmts_yuv444[] = {
165  };
166  static const enum AVPixelFormat overlay_pix_fmts_yuv444[] = {
168  };
169 
170  static const enum AVPixelFormat main_pix_fmts_rgb[] = {
175  };
176  static const enum AVPixelFormat overlay_pix_fmts_rgb[] = {
180  };
181 
182  AVFilterFormats *main_formats;
183  AVFilterFormats *overlay_formats;
184 
185  switch (over->format) {
186  case OVERLAY_FORMAT_YUV420:
187  main_formats = ff_make_format_list(main_pix_fmts_yuv420);
188  overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv420);
189  break;
190  case OVERLAY_FORMAT_YUV444:
191  main_formats = ff_make_format_list(main_pix_fmts_yuv444);
192  overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv444);
193  break;
194  case OVERLAY_FORMAT_RGB:
195  main_formats = ff_make_format_list(main_pix_fmts_rgb);
196  overlay_formats = ff_make_format_list(overlay_pix_fmts_rgb);
197  break;
198  default:
199  av_assert0(0);
200  }
201 
202  ff_formats_ref(main_formats, &ctx->inputs [MAIN ]->out_formats);
203  ff_formats_ref(overlay_formats, &ctx->inputs [OVERLAY]->out_formats);
204  ff_formats_ref(main_formats, &ctx->outputs[MAIN ]->in_formats );
205 
206  return 0;
207 }
208 
209 static const enum AVPixelFormat alpha_pix_fmts[] = {
213 };
214 
215 static int config_input_main(AVFilterLink *inlink)
216 {
217  OverlayContext *over = inlink->dst->priv;
218  const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);
219 
221 
222  over->hsub = pix_desc->log2_chroma_w;
223  over->vsub = pix_desc->log2_chroma_h;
224 
225  over->main_is_packed_rgb =
226  ff_fill_rgba_map(over->main_rgba_map, inlink->format) >= 0;
228  return 0;
229 }
230 
232 {
233  AVFilterContext *ctx = inlink->dst;
234  OverlayContext *over = inlink->dst->priv;
235  char *expr;
236  double var_values[VAR_VARS_NB], res;
237  int ret;
238  const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);
239 
241 
242  /* Finish the configuration by evaluating the expressions
243  now when both inputs are configured. */
244  var_values[VAR_MAIN_W ] = var_values[VAR_MW] = ctx->inputs[MAIN ]->w;
245  var_values[VAR_MAIN_H ] = var_values[VAR_MH] = ctx->inputs[MAIN ]->h;
246  var_values[VAR_OVERLAY_W] = var_values[VAR_OW] = ctx->inputs[OVERLAY]->w;
247  var_values[VAR_OVERLAY_H] = var_values[VAR_OH] = ctx->inputs[OVERLAY]->h;
248 
249  if ((ret = av_expr_parse_and_eval(&res, (expr = over->x_expr), var_names, var_values,
250  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
251  goto fail;
252  over->x = res;
253  if ((ret = av_expr_parse_and_eval(&res, (expr = over->y_expr), var_names, var_values,
254  NULL, NULL, NULL, NULL, NULL, 0, ctx)))
255  goto fail;
256  over->y = res;
257  /* x may depend on y */
258  if ((ret = av_expr_parse_and_eval(&res, (expr = over->x_expr), var_names, var_values,
259  NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
260  goto fail;
261  over->x = res;
262 
263  over->overlay_is_packed_rgb =
264  ff_fill_rgba_map(over->overlay_rgba_map, inlink->format) >= 0;
266 
267  av_log(ctx, AV_LOG_VERBOSE,
268  "main w:%d h:%d fmt:%s overlay x:%d y:%d w:%d h:%d fmt:%s\n",
269  ctx->inputs[MAIN]->w, ctx->inputs[MAIN]->h,
271  over->x, over->y,
272  ctx->inputs[OVERLAY]->w, ctx->inputs[OVERLAY]->h,
274 
275  if (over->x < 0 || over->y < 0 ||
276  over->x + var_values[VAR_OVERLAY_W] > var_values[VAR_MAIN_W] ||
277  over->y + var_values[VAR_OVERLAY_H] > var_values[VAR_MAIN_H]) {
278  av_log(ctx, AV_LOG_WARNING,
279  "Overlay area with coordinates x1:%d y1:%d x2:%d y2:%d "
280  "is not completely contained within the output with size %dx%d\n",
281  over->x, over->y,
282  (int)(over->x + var_values[VAR_OVERLAY_W]),
283  (int)(over->y + var_values[VAR_OVERLAY_H]),
284  (int)var_values[VAR_MAIN_W], (int)var_values[VAR_MAIN_H]);
285  }
286  return 0;
287 
288 fail:
290  "Error when evaluating the expression '%s'\n", expr);
291  return ret;
292 }
293 
294 static int config_output(AVFilterLink *outlink)
295 {
296  AVFilterContext *ctx = outlink->src;
297 
298  outlink->w = ctx->inputs[MAIN]->w;
299  outlink->h = ctx->inputs[MAIN]->h;
300  outlink->time_base = ctx->inputs[MAIN]->time_base;
301 
302  return 0;
303 }
304 
305 // divide by 255 and round to nearest
306 // apply a fast variant: (X+127)/255 = ((X+127)*257+257)>>16 = ((X+128)*257)>>16
307 #define FAST_DIV255(x) ((((x) + 128) * 257) >> 16)
308 
309 // calculate the unpremultiplied alpha, applying the general equation:
310 // alpha = alpha_overlay / ( (alpha_main + alpha_overlay) - (alpha_main * alpha_overlay) )
311 // (((x) << 16) - ((x) << 9) + (x)) is a faster version of: 255 * 255 * x
312 // ((((x) + (y)) << 8) - ((x) + (y)) - (y) * (x)) is a faster version of: 255 * (x + y)
313 #define UNPREMULTIPLY_ALPHA(x, y) ((((x) << 16) - ((x) << 9) + (x)) / ((((x) + (y)) << 8) - ((x) + (y)) - (y) * (x)))
314 
315 /**
316  * Blend image in src to destination buffer dst at position (x, y).
317  */
318 static void blend_image(AVFilterContext *ctx,
320  int x, int y)
321 {
322  OverlayContext *over = ctx->priv;
323  int i, imax, j, jmax, k, kmax;
324  const int src_w = src->video->w;
325  const int src_h = src->video->h;
326  const int dst_w = dst->video->w;
327  const int dst_h = dst->video->h;
328 
329  if (x >= dst_w || x+dst_w < 0 ||
330  y >= dst_h || y+dst_h < 0)
331  return; /* no intersection */
332 
333  if (over->main_is_packed_rgb) {
334  uint8_t alpha; ///< the amount of overlay to blend on to main
335  const int dr = over->main_rgba_map[R];
336  const int dg = over->main_rgba_map[G];
337  const int db = over->main_rgba_map[B];
338  const int da = over->main_rgba_map[A];
339  const int dstep = over->main_pix_step[0];
340  const int sr = over->overlay_rgba_map[R];
341  const int sg = over->overlay_rgba_map[G];
342  const int sb = over->overlay_rgba_map[B];
343  const int sa = over->overlay_rgba_map[A];
344  const int sstep = over->overlay_pix_step[0];
345  const int main_has_alpha = over->main_has_alpha;
346  uint8_t *s, *sp, *d, *dp;
347 
348  i = FFMAX(-y, 0);
349  sp = src->data[0] + i * src->linesize[0];
350  dp = dst->data[0] + (y+i) * dst->linesize[0];
351 
352  for (imax = FFMIN(-y + dst_h, src_h); i < imax; i++) {
353  j = FFMAX(-x, 0);
354  s = sp + j * sstep;
355  d = dp + (x+j) * dstep;
356 
357  for (jmax = FFMIN(-x + dst_w, src_w); j < jmax; j++) {
358  alpha = s[sa];
359 
360  // if the main channel has an alpha channel, alpha has to be calculated
361  // to create an un-premultiplied (straight) alpha value
362  if (main_has_alpha && alpha != 0 && alpha != 255) {
363  uint8_t alpha_d = d[da];
364  alpha = UNPREMULTIPLY_ALPHA(alpha, alpha_d);
365  }
366 
367  switch (alpha) {
368  case 0:
369  break;
370  case 255:
371  d[dr] = s[sr];
372  d[dg] = s[sg];
373  d[db] = s[sb];
374  break;
375  default:
376  // main_value = main_value * (1 - alpha) + overlay_value * alpha
377  // since alpha is in the range 0-255, the result must divided by 255
378  d[dr] = FAST_DIV255(d[dr] * (255 - alpha) + s[sr] * alpha);
379  d[dg] = FAST_DIV255(d[dg] * (255 - alpha) + s[sg] * alpha);
380  d[db] = FAST_DIV255(d[db] * (255 - alpha) + s[sb] * alpha);
381  }
382  if (main_has_alpha) {
383  switch (alpha) {
384  case 0:
385  break;
386  case 255:
387  d[da] = s[sa];
388  break;
389  default:
390  // apply alpha compositing: main_alpha += (1-main_alpha) * overlay_alpha
391  d[da] += FAST_DIV255((255 - d[da]) * s[sa]);
392  }
393  }
394  d += dstep;
395  s += sstep;
396  }
397  dp += dst->linesize[0];
398  sp += src->linesize[0];
399  }
400  } else {
401  const int main_has_alpha = over->main_has_alpha;
402  if (main_has_alpha) {
403  uint8_t alpha; ///< the amount of overlay to blend on to main
404  uint8_t *s, *sa, *d, *da;
405 
406  i = FFMAX(-y, 0);
407  sa = src->data[3] + i * src->linesize[3];
408  da = dst->data[3] + (y+i) * dst->linesize[3];
409 
410  for (imax = FFMIN(-y + dst_h, src_h); i < imax; i++) {
411  j = FFMAX(-x, 0);
412  s = sa + j;
413  d = da + x+j;
414 
415  for (jmax = FFMIN(-x + dst_w, src_w); j < jmax; j++) {
416  alpha = *s;
417  if (alpha != 0 && alpha != 255) {
418  uint8_t alpha_d = *d;
419  alpha = UNPREMULTIPLY_ALPHA(alpha, alpha_d);
420  }
421  switch (alpha) {
422  case 0:
423  break;
424  case 255:
425  *d = *s;
426  break;
427  default:
428  // apply alpha compositing: main_alpha += (1-main_alpha) * overlay_alpha
429  *d += FAST_DIV255((255 - *d) * *s);
430  }
431  d += 1;
432  s += 1;
433  }
434  da += dst->linesize[3];
435  sa += src->linesize[3];
436  }
437  }
438  for (i = 0; i < 3; i++) {
439  int hsub = i ? over->hsub : 0;
440  int vsub = i ? over->vsub : 0;
441  int src_wp = FFALIGN(src_w, 1<<hsub) >> hsub;
442  int src_hp = FFALIGN(src_h, 1<<vsub) >> vsub;
443  int dst_wp = FFALIGN(dst_w, 1<<hsub) >> hsub;
444  int dst_hp = FFALIGN(dst_h, 1<<vsub) >> vsub;
445  int yp = y>>vsub;
446  int xp = x>>hsub;
447  uint8_t *s, *sp, *d, *dp, *a, *ap;
448 
449  j = FFMAX(-yp, 0);
450  sp = src->data[i] + j * src->linesize[i];
451  dp = dst->data[i] + (yp+j) * dst->linesize[i];
452  ap = src->data[3] + (j<<vsub) * src->linesize[3];
453 
454  for (jmax = FFMIN(-yp + dst_hp, src_hp); j < jmax; j++) {
455  k = FFMAX(-xp, 0);
456  d = dp + xp+k;
457  s = sp + k;
458  a = ap + (k<<hsub);
459 
460  for (kmax = FFMIN(-xp + dst_wp, src_wp); k < kmax; k++) {
461  int alpha_v, alpha_h, alpha;
462 
463  // average alpha for color components, improve quality
464  if (hsub && vsub && j+1 < src_hp && k+1 < src_wp) {
465  alpha = (a[0] + a[src->linesize[3]] +
466  a[1] + a[src->linesize[3]+1]) >> 2;
467  } else if (hsub || vsub) {
468  alpha_h = hsub && k+1 < src_wp ?
469  (a[0] + a[1]) >> 1 : a[0];
470  alpha_v = vsub && j+1 < src_hp ?
471  (a[0] + a[src->linesize[3]]) >> 1 : a[0];
472  alpha = (alpha_v + alpha_h) >> 1;
473  } else
474  alpha = a[0];
475  // if the main channel has an alpha channel, alpha has to be calculated
476  // to create an un-premultiplied (straight) alpha value
477  if (main_has_alpha && alpha != 0 && alpha != 255) {
478  // average alpha for color components, improve quality
479  uint8_t alpha_d;
480  if (hsub && vsub && j+1 < src_hp && k+1 < src_wp) {
481  alpha_d = (d[0] + d[src->linesize[3]] +
482  d[1] + d[src->linesize[3]+1]) >> 2;
483  } else if (hsub || vsub) {
484  alpha_h = hsub && k+1 < src_wp ?
485  (d[0] + d[1]) >> 1 : d[0];
486  alpha_v = vsub && j+1 < src_hp ?
487  (d[0] + d[src->linesize[3]]) >> 1 : d[0];
488  alpha_d = (alpha_v + alpha_h) >> 1;
489  } else
490  alpha_d = d[0];
491  alpha = UNPREMULTIPLY_ALPHA(alpha, alpha_d);
492  }
493  *d = FAST_DIV255(*d * (255 - alpha) + *s * alpha);
494  s++;
495  d++;
496  a += 1 << hsub;
497  }
498  dp += dst->linesize[i];
499  sp += src->linesize[i];
500  ap += (1 << vsub) * src->linesize[3];
501  }
502  }
503  }
504 }
505 
507 {
508  OverlayContext *over = ctx->priv;
509  AVFilterLink *outlink = ctx->outputs[0];
510  AVFilterBufferRef *next_overpic;
511  int ret;
512 
513  /* Discard obsolete overlay frames: if there is a next overlay frame with pts
514  * before the main frame, we can drop the current overlay. */
515  while (1) {
516  next_overpic = ff_bufqueue_peek(&over->queue_over, 0);
517  if (!next_overpic || av_compare_ts(next_overpic->pts, ctx->inputs[OVERLAY]->time_base,
518  mainpic->pts , ctx->inputs[MAIN]->time_base) > 0)
519  break;
520  ff_bufqueue_get(&over->queue_over);
522  over->overpicref = next_overpic;
523  }
524 
525  /* If there is no next frame and no EOF and the overlay frame is before
526  * the main frame, we can not know yet if it will be superseded. */
527  if (!over->queue_over.available && !over->overlay_eof &&
528  (!over->overpicref || av_compare_ts(over->overpicref->pts, ctx->inputs[OVERLAY]->time_base,
529  mainpic->pts , ctx->inputs[MAIN]->time_base) < 0))
530  return AVERROR(EAGAIN);
531 
532  /* At this point, we know that the current overlay frame extends to the
533  * time of the main frame. */
534  av_dlog(ctx, "main_pts:%s main_pts_time:%s",
535  av_ts2str(mainpic->pts), av_ts2timestr(mainpic->pts, &outlink->time_base));
536  if (over->overpicref)
537  av_dlog(ctx, " over_pts:%s over_pts_time:%s",
538  av_ts2str(over->overpicref->pts), av_ts2timestr(over->overpicref->pts, &outlink->time_base));
539  av_dlog(ctx, "\n");
540 
541  if (over->overpicref)
542  blend_image(ctx, mainpic, over->overpicref, over->x, over->y);
543  ret = ff_filter_frame(ctx->outputs[0], mainpic);
544  av_assert1(ret != AVERROR(EAGAIN));
545  over->frame_requested = 0;
546  return ret;
547 }
548 
550 {
551  OverlayContext *over = ctx->priv;
552  AVFilterBufferRef *next_mainpic = ff_bufqueue_peek(&over->queue_main, 0);
553  int ret;
554 
555  if (!next_mainpic)
556  return AVERROR(EAGAIN);
557  if ((ret = try_filter_frame(ctx, next_mainpic)) == AVERROR(EAGAIN))
558  return ret;
559  ff_bufqueue_get(&over->queue_main);
560  return ret;
561 }
562 
564 {
565  int ret;
566 
567  while (!(ret = try_filter_next_frame(ctx)));
568  return ret == AVERROR(EAGAIN) ? 0 : ret;
569 }
570 
571 static int filter_frame_main(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
572 {
573  AVFilterContext *ctx = inlink->dst;
574  OverlayContext *over = ctx->priv;
575  int ret;
576 
577  if ((ret = flush_frames(ctx)) < 0)
578  return ret;
579  if ((ret = try_filter_frame(ctx, inpicref)) < 0) {
580  if (ret != AVERROR(EAGAIN))
581  return ret;
582  ff_bufqueue_add(ctx, &over->queue_main, inpicref);
583  }
584 
585  if (!over->overpicref)
586  return 0;
587  flush_frames(ctx);
588 
589  return 0;
590 }
591 
592 static int filter_frame_over(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
593 {
594  AVFilterContext *ctx = inlink->dst;
595  OverlayContext *over = ctx->priv;
596  int ret;
597 
598  if ((ret = flush_frames(ctx)) < 0)
599  return ret;
600  ff_bufqueue_add(ctx, &over->queue_over, inpicref);
601  ret = try_filter_next_frame(ctx);
602  return ret == AVERROR(EAGAIN) ? 0 : ret;
603 }
604 
605 static int request_frame(AVFilterLink *outlink)
606 {
607  AVFilterContext *ctx = outlink->src;
608  OverlayContext *over = ctx->priv;
609  int input, ret;
610 
611  if (!try_filter_next_frame(ctx))
612  return 0;
613  over->frame_requested = 1;
614  while (over->frame_requested) {
615  /* TODO if we had a frame duration, we could guess more accurately */
616  input = !over->overlay_eof && (over->queue_main.available ||
617  over->queue_over.available < 2) ?
618  OVERLAY : MAIN;
619  ret = ff_request_frame(ctx->inputs[input]);
620  /* EOF on main is reported immediately */
621  if (ret == AVERROR_EOF && input == OVERLAY) {
622  over->overlay_eof = 1;
623  if (over->shortest)
624  return ret;
625  if ((ret = try_filter_next_frame(ctx)) != AVERROR(EAGAIN))
626  return ret;
627  ret = 0; /* continue requesting frames on main */
628  }
629  if (ret < 0)
630  return ret;
631  }
632  return 0;
633 }
634 
636  {
637  .name = "main",
638  .type = AVMEDIA_TYPE_VIDEO,
639  .get_video_buffer = ff_null_get_video_buffer,
640  .config_props = config_input_main,
641  .filter_frame = filter_frame_main,
643  },
644  {
645  .name = "overlay",
646  .type = AVMEDIA_TYPE_VIDEO,
647  .config_props = config_input_overlay,
648  .filter_frame = filter_frame_over,
649  .min_perms = AV_PERM_READ | AV_PERM_PRESERVE,
650  },
651  { NULL }
652 };
653 
655  {
656  .name = "default",
657  .type = AVMEDIA_TYPE_VIDEO,
658  .rej_perms = AV_PERM_WRITE,
659  .config_props = config_output,
660  .request_frame = request_frame,
661  },
662  { NULL }
663 };
664 
666  .name = "overlay",
667  .description = NULL_IF_CONFIG_SMALL("Overlay a video source on top of the input."),
668 
669  .init = init,
670  .uninit = uninit,
671 
672  .priv_size = sizeof(OverlayContext),
673 
675 
676  .inputs = avfilter_vf_overlay_inputs,
677  .outputs = avfilter_vf_overlay_outputs,
678  .priv_class = &overlay_class,
679 };