You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

472 lines
19KB

  1. /*
  2. * Copyright (c) 2013 Paul B Mahol
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "libavutil/imgutils.h"
  21. #include "libavutil/eval.h"
  22. #include "libavutil/opt.h"
  23. #include "libavutil/pixfmt.h"
  24. #include "avfilter.h"
  25. #include "bufferqueue.h"
  26. #include "formats.h"
  27. #include "internal.h"
  28. #include "video.h"
  29. #define TOP 0
  30. #define BOTTOM 1
  31. enum BlendMode {
  32. BLEND_UNSET = -1,
  33. BLEND_NORMAL,
  34. BLEND_ADDITION,
  35. BLEND_AND,
  36. BLEND_AVERAGE,
  37. BLEND_BURN,
  38. BLEND_DARKEN,
  39. BLEND_DIFFERENCE,
  40. BLEND_DIVIDE,
  41. BLEND_DODGE,
  42. BLEND_EXCLUSION,
  43. BLEND_HARDLIGHT,
  44. BLEND_LIGHTEN,
  45. BLEND_MULTIPLY,
  46. BLEND_NEGATION,
  47. BLEND_OR,
  48. BLEND_OVERLAY,
  49. BLEND_PHOENIX,
  50. BLEND_PINLIGHT,
  51. BLEND_REFLECT,
  52. BLEND_SCREEN,
  53. BLEND_SOFTLIGHT,
  54. BLEND_SUBTRACT,
  55. BLEND_VIVIDLIGHT,
  56. BLEND_XOR,
  57. BLEND_NB
  58. };
  59. static const char *const var_names[] = { "X", "Y", "W", "H", "SW", "SH", "T", "A", "B", "TOP", "BOTTOM", NULL };
  60. enum { VAR_X, VAR_Y, VAR_W, VAR_H, VAR_SW, VAR_SH, VAR_T, VAR_A, VAR_B, VAR_TOP, VAR_BOTTOM, VAR_VARS_NB };
  61. typedef struct FilterParams {
  62. enum BlendMode mode;
  63. double values[VAR_VARS_NB];
  64. double opacity;
  65. AVExpr *e;
  66. char *expr_str;
  67. void (*blend)(const uint8_t *top, int top_linesize,
  68. const uint8_t *bottom, int bottom_linesize,
  69. uint8_t *dst, int dst_linesize,
  70. int width, int height, struct FilterParams *param);
  71. } FilterParams;
  72. typedef struct {
  73. const AVClass *class;
  74. struct FFBufQueue queue_top;
  75. struct FFBufQueue queue_bottom;
  76. int hsub, vsub; ///< chroma subsampling values
  77. int frame_requested;
  78. char *all_expr;
  79. enum BlendMode all_mode;
  80. double all_opacity;
  81. FilterParams params[4];
  82. } BlendContext;
  83. #define OFFSET(x) offsetof(BlendContext, x)
  84. #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
  85. static const AVOption blend_options[] = {
  86. { "c0_mode", "set component #0 blend mode", OFFSET(params[0].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode"},
  87. { "c1_mode", "set component #1 blend mode", OFFSET(params[1].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode"},
  88. { "c2_mode", "set component #2 blend mode", OFFSET(params[2].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode"},
  89. { "c3_mode", "set component #3 blend mode", OFFSET(params[3].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, "mode"},
  90. { "all_mode", "set blend mode for all components", OFFSET(all_mode), AV_OPT_TYPE_INT, {.i64=-1},-1, BLEND_NB-1, FLAGS, "mode"},
  91. { "addition", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_ADDITION}, 0, 0, FLAGS, "mode" },
  92. { "and", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_AND}, 0, 0, FLAGS, "mode" },
  93. { "average", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_AVERAGE}, 0, 0, FLAGS, "mode" },
  94. { "burn", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_BURN}, 0, 0, FLAGS, "mode" },
  95. { "darken", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DARKEN}, 0, 0, FLAGS, "mode" },
  96. { "difference", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DIFFERENCE}, 0, 0, FLAGS, "mode" },
  97. { "divide", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DIVIDE}, 0, 0, FLAGS, "mode" },
  98. { "dodge", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DODGE}, 0, 0, FLAGS, "mode" },
  99. { "exclusion", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_EXCLUSION}, 0, 0, FLAGS, "mode" },
  100. { "hardlight", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_HARDLIGHT}, 0, 0, FLAGS, "mode" },
  101. { "lighten", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_LIGHTEN}, 0, 0, FLAGS, "mode" },
  102. { "multiply", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_MULTIPLY}, 0, 0, FLAGS, "mode" },
  103. { "negation", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_NEGATION}, 0, 0, FLAGS, "mode" },
  104. { "normal", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_NORMAL}, 0, 0, FLAGS, "mode" },
  105. { "or", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_OR}, 0, 0, FLAGS, "mode" },
  106. { "overlay", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_OVERLAY}, 0, 0, FLAGS, "mode" },
  107. { "phoenix", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_PHOENIX}, 0, 0, FLAGS, "mode" },
  108. { "pinlight", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_PINLIGHT}, 0, 0, FLAGS, "mode" },
  109. { "reflect", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_REFLECT}, 0, 0, FLAGS, "mode" },
  110. { "screen", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SCREEN}, 0, 0, FLAGS, "mode" },
  111. { "softlight", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SOFTLIGHT}, 0, 0, FLAGS, "mode" },
  112. { "subtract", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SUBTRACT}, 0, 0, FLAGS, "mode" },
  113. { "vividlight", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_VIVIDLIGHT}, 0, 0, FLAGS, "mode" },
  114. { "xor", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_XOR}, 0, 0, FLAGS, "mode" },
  115. { "c0_expr", "set color component #0 expression", OFFSET(params[0].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
  116. { "c1_expr", "set color component #1 expression", OFFSET(params[1].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
  117. { "c2_expr", "set color component #2 expression", OFFSET(params[2].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
  118. { "c3_expr", "set color component #3 expression", OFFSET(params[3].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
  119. { "all_expr", "set expression for all color components", OFFSET(all_expr), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS },
  120. { "c0_opacity", "set color component #0 opacity", OFFSET(params[0].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
  121. { "c1_opacity", "set color component #1 opacity", OFFSET(params[1].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
  122. { "c2_opacity", "set color component #2 opacity", OFFSET(params[2].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
  123. { "c3_opacity", "set color component #3 opacity", OFFSET(params[3].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
  124. { "all_opacity", "set opacity for all color components", OFFSET(all_opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
  125. { NULL },
  126. };
  127. AVFILTER_DEFINE_CLASS(blend);
  128. static void blend_normal(const uint8_t *top, int top_linesize,
  129. const uint8_t *bottom, int bottom_linesize,
  130. uint8_t *dst, int dst_linesize,
  131. int width, int height, FilterParams *param)
  132. {
  133. av_image_copy_plane(dst, dst_linesize, top, top_linesize, width, height);
  134. }
  135. #define DEFINE_BLEND(name, expr) \
  136. static void blend_## name(const uint8_t *top, int top_linesize, \
  137. const uint8_t *bottom, int bottom_linesize, \
  138. uint8_t *dst, int dst_linesize, \
  139. int width, int height, FilterParams *param) \
  140. { \
  141. double opacity = param->opacity; \
  142. int i, j; \
  143. \
  144. for (i = 0; i < height; i++) { \
  145. for (j = 0; j < width; j++) { \
  146. dst[j] = top[j] + ((expr) - top[j]) * opacity; \
  147. } \
  148. dst += dst_linesize; \
  149. top += top_linesize; \
  150. bottom += bottom_linesize; \
  151. } \
  152. }
  153. #define A top[j]
  154. #define B bottom[j]
  155. #define MULTIPLY(x, a, b) (x * ((a * b) / 255))
  156. #define SCREEN(x, a, b) (255 - x * ((255 - a) * (255 - b) / 255))
  157. #define BURN(a, b) ((a == 0) ? a : FFMAX(0, 255 - ((255 - b) << 8) / a))
  158. #define DODGE(a, b) ((a == 255) ? a : FFMIN(255, ((b << 8) / (255 - a))))
  159. DEFINE_BLEND(addition, FFMIN(255, A + B))
  160. DEFINE_BLEND(average, (A + B) / 2)
  161. DEFINE_BLEND(subtract, FFMAX(0, A - B))
  162. DEFINE_BLEND(multiply, MULTIPLY(1, A, B))
  163. DEFINE_BLEND(negation, 255 - FFABS(255 - A - B))
  164. DEFINE_BLEND(difference, FFABS(A - B))
  165. DEFINE_BLEND(screen, SCREEN(1, A, B))
  166. DEFINE_BLEND(overlay, (A < 128) ? MULTIPLY(2, A, B) : SCREEN(2, A, B))
  167. DEFINE_BLEND(hardlight, (B < 128) ? MULTIPLY(2, B, A) : SCREEN(2, B, A))
  168. DEFINE_BLEND(darken, FFMIN(A, B))
  169. DEFINE_BLEND(lighten, FFMAX(A, B))
  170. DEFINE_BLEND(divide, ((float)A / ((float)B) * 255))
  171. DEFINE_BLEND(dodge, DODGE(A, B))
  172. DEFINE_BLEND(burn, BURN(A, B))
  173. DEFINE_BLEND(softlight, (A > 127) ? B + (255 - B) * (A - 127.5) / 127.5 * (0.5 - FFABS(B - 127.5) / 255): B - B * ((127.5 - A) / 127.5) * (0.5 - FFABS(B - 127.5)/255))
  174. DEFINE_BLEND(exclusion, A + B - 2 * A * B / 255)
  175. DEFINE_BLEND(pinlight, (B < 128) ? FFMIN(A, 2 * B) : FFMAX(A, 2 * (B - 128)))
  176. DEFINE_BLEND(phoenix, FFMIN(A, B) - FFMAX(A, B) + 255)
  177. DEFINE_BLEND(reflect, (B == 255) ? B : FFMIN(255, (A * A / (255 - B))))
  178. DEFINE_BLEND(and, A & B)
  179. DEFINE_BLEND(or, A | B)
  180. DEFINE_BLEND(xor, A ^ B)
  181. DEFINE_BLEND(vividlight, (B < 128) ? BURN(A, 2 * B) : DODGE(A, 2 * (B - 128)))
  182. static void blend_expr(const uint8_t *top, int top_linesize,
  183. const uint8_t *bottom, int bottom_linesize,
  184. uint8_t *dst, int dst_linesize,
  185. int width, int height,
  186. FilterParams *param)
  187. {
  188. AVExpr *e = param->e;
  189. double *values = param->values;
  190. int y, x;
  191. for (y = 0; y < height; y++) {
  192. values[VAR_Y] = y;
  193. for (x = 0; x < width; x++) {
  194. values[VAR_X] = x;
  195. values[VAR_TOP] = values[VAR_A] = top[x];
  196. values[VAR_BOTTOM] = values[VAR_B] = bottom[x];
  197. dst[x] = av_expr_eval(e, values, NULL);
  198. }
  199. dst += dst_linesize;
  200. top += top_linesize;
  201. bottom += bottom_linesize;
  202. }
  203. }
  204. static av_cold int init(AVFilterContext *ctx, const char *args)
  205. {
  206. BlendContext *b = ctx->priv;
  207. int ret, plane;
  208. b->class = &blend_class;
  209. av_opt_set_defaults(b);
  210. if ((ret = av_set_options_string(b, args, "=", ":")) < 0)
  211. return ret;
  212. for (plane = 0; plane < FF_ARRAY_ELEMS(b->params); plane++) {
  213. FilterParams *param = &b->params[plane];
  214. if (b->all_mode >= 0)
  215. param->mode = b->all_mode;
  216. if (b->all_opacity < 1)
  217. param->opacity = b->all_opacity;
  218. switch (param->mode) {
  219. case BLEND_ADDITION: param->blend = blend_addition; break;
  220. case BLEND_AND: param->blend = blend_and; break;
  221. case BLEND_AVERAGE: param->blend = blend_average; break;
  222. case BLEND_BURN: param->blend = blend_burn; break;
  223. case BLEND_DARKEN: param->blend = blend_darken; break;
  224. case BLEND_DIFFERENCE: param->blend = blend_difference; break;
  225. case BLEND_DIVIDE: param->blend = blend_divide; break;
  226. case BLEND_DODGE: param->blend = blend_dodge; break;
  227. case BLEND_EXCLUSION: param->blend = blend_exclusion; break;
  228. case BLEND_HARDLIGHT: param->blend = blend_hardlight; break;
  229. case BLEND_LIGHTEN: param->blend = blend_lighten; break;
  230. case BLEND_MULTIPLY: param->blend = blend_multiply; break;
  231. case BLEND_NEGATION: param->blend = blend_negation; break;
  232. case BLEND_NORMAL: param->blend = blend_normal; break;
  233. case BLEND_OR: param->blend = blend_or; break;
  234. case BLEND_OVERLAY: param->blend = blend_overlay; break;
  235. case BLEND_PHOENIX: param->blend = blend_phoenix; break;
  236. case BLEND_PINLIGHT: param->blend = blend_pinlight; break;
  237. case BLEND_REFLECT: param->blend = blend_reflect; break;
  238. case BLEND_SCREEN: param->blend = blend_screen; break;
  239. case BLEND_SOFTLIGHT: param->blend = blend_softlight; break;
  240. case BLEND_SUBTRACT: param->blend = blend_subtract; break;
  241. case BLEND_VIVIDLIGHT: param->blend = blend_vividlight; break;
  242. case BLEND_XOR: param->blend = blend_xor; break;
  243. }
  244. if (b->all_expr && !param->expr_str) {
  245. param->expr_str = av_strdup(b->all_expr);
  246. if (!param->expr_str)
  247. return AVERROR(ENOMEM);
  248. }
  249. if (param->expr_str) {
  250. ret = av_expr_parse(&param->e, param->expr_str, var_names,
  251. NULL, NULL, NULL, NULL, 0, ctx);
  252. if (ret < 0)
  253. return ret;
  254. param->blend = blend_expr;
  255. }
  256. }
  257. return 0;
  258. }
  259. static int query_formats(AVFilterContext *ctx)
  260. {
  261. static const enum AVPixelFormat pix_fmts[] = {
  262. AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
  263. AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
  264. AV_PIX_FMT_GBRP, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE
  265. };
  266. ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
  267. return 0;
  268. }
  269. static int config_output(AVFilterLink *outlink)
  270. {
  271. AVFilterContext *ctx = outlink->src;
  272. AVFilterLink *toplink = ctx->inputs[TOP];
  273. AVFilterLink *bottomlink = ctx->inputs[BOTTOM];
  274. if (toplink->format != bottomlink->format) {
  275. av_log(ctx, AV_LOG_ERROR, "inputs must be of same pixel format\n");
  276. return AVERROR(EINVAL);
  277. }
  278. if (toplink->w != bottomlink->w ||
  279. toplink->h != bottomlink->h ||
  280. toplink->sample_aspect_ratio.num != bottomlink->sample_aspect_ratio.num ||
  281. toplink->sample_aspect_ratio.den != bottomlink->sample_aspect_ratio.den) {
  282. av_log(ctx, AV_LOG_ERROR, "First input link %s parameters "
  283. "(size %dx%d, SAR %d:%d) do not match the corresponding "
  284. "second input link %s parameters (%dx%d, SAR %d:%d)\n",
  285. ctx->input_pads[TOP].name, toplink->w, toplink->h,
  286. toplink->sample_aspect_ratio.num,
  287. toplink->sample_aspect_ratio.den,
  288. ctx->input_pads[BOTTOM].name, bottomlink->w, bottomlink->h,
  289. bottomlink->sample_aspect_ratio.num,
  290. bottomlink->sample_aspect_ratio.den);
  291. return AVERROR(EINVAL);
  292. }
  293. outlink->w = toplink->w;
  294. outlink->h = bottomlink->h;
  295. outlink->time_base = toplink->time_base;
  296. outlink->sample_aspect_ratio = toplink->sample_aspect_ratio;
  297. outlink->frame_rate = toplink->frame_rate;
  298. return 0;
  299. }
  300. static int config_input_top(AVFilterLink *inlink)
  301. {
  302. BlendContext *b = inlink->dst->priv;
  303. const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);
  304. b->hsub = pix_desc->log2_chroma_w;
  305. b->vsub = pix_desc->log2_chroma_h;
  306. return 0;
  307. }
  308. static av_cold void uninit(AVFilterContext *ctx)
  309. {
  310. BlendContext *b = ctx->priv;
  311. int i;
  312. av_opt_free(b);
  313. ff_bufqueue_discard_all(&b->queue_top);
  314. ff_bufqueue_discard_all(&b->queue_bottom);
  315. for (i = 0; i < FF_ARRAY_ELEMS(b->params); i++)
  316. av_expr_free(b->params[i].e);
  317. }
  318. static int request_frame(AVFilterLink *outlink)
  319. {
  320. AVFilterContext *ctx = outlink->src;
  321. BlendContext *b = ctx->priv;
  322. int in, ret;
  323. b->frame_requested = 1;
  324. while (b->frame_requested) {
  325. in = ff_bufqueue_peek(&b->queue_top, TOP) ? BOTTOM : TOP;
  326. ret = ff_request_frame(ctx->inputs[in]);
  327. if (ret < 0)
  328. return ret;
  329. }
  330. return 0;
  331. }
  332. static void blend_frame(AVFilterContext *ctx,
  333. AVFrame *top_buf,
  334. AVFrame *bottom_buf,
  335. AVFrame *dst_buf)
  336. {
  337. BlendContext *b = ctx->priv;
  338. AVFilterLink *inlink = ctx->inputs[0];
  339. FilterParams *param;
  340. int plane;
  341. for (plane = 0; dst_buf->data[plane]; plane++) {
  342. int hsub = plane == 1 || plane == 2 ? b->hsub : 0;
  343. int vsub = plane == 1 || plane == 2 ? b->vsub : 0;
  344. int outw = dst_buf->width >> hsub;
  345. int outh = dst_buf->height >> vsub;
  346. uint8_t *dst = dst_buf->data[plane];
  347. uint8_t *top = top_buf->data[plane];
  348. uint8_t *bottom = bottom_buf->data[plane];
  349. param = &b->params[plane];
  350. param->values[VAR_T] = dst_buf->pts == AV_NOPTS_VALUE ? NAN : dst_buf->pts * av_q2d(inlink->time_base);
  351. param->values[VAR_W] = outw;
  352. param->values[VAR_H] = outh;
  353. param->values[VAR_SW] = outw / dst_buf->width;
  354. param->values[VAR_SH] = outh / dst_buf->height;
  355. param->blend(top, top_buf->linesize[plane],
  356. bottom, bottom_buf->linesize[plane],
  357. dst, dst_buf->linesize[plane], outw, outh, param);
  358. }
  359. }
  360. static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
  361. {
  362. AVFilterContext *ctx = inlink->dst;
  363. AVFilterLink *outlink = ctx->outputs[0];
  364. BlendContext *b = ctx->priv;
  365. int ret = 0;
  366. int is_bottom = (inlink == ctx->inputs[BOTTOM]);
  367. struct FFBufQueue *queue =
  368. (is_bottom ? &b->queue_bottom : &b->queue_top);
  369. ff_bufqueue_add(ctx, queue, buf);
  370. while (1) {
  371. AVFrame *top_buf, *bottom_buf, *out_buf;
  372. if (!ff_bufqueue_peek(&b->queue_top, TOP) ||
  373. !ff_bufqueue_peek(&b->queue_bottom, BOTTOM)) break;
  374. top_buf = ff_bufqueue_get(&b->queue_top);
  375. bottom_buf = ff_bufqueue_get(&b->queue_bottom);
  376. out_buf = ff_get_video_buffer(outlink, outlink->w, outlink->h);
  377. if (!out_buf) {
  378. return AVERROR(ENOMEM);
  379. }
  380. av_frame_copy_props(out_buf, top_buf);
  381. b->frame_requested = 0;
  382. blend_frame(ctx, top_buf, bottom_buf, out_buf);
  383. ret = ff_filter_frame(ctx->outputs[0], out_buf);
  384. av_frame_free(&top_buf);
  385. av_frame_free(&bottom_buf);
  386. }
  387. return ret;
  388. }
  389. static const AVFilterPad blend_inputs[] = {
  390. {
  391. .name = "top",
  392. .type = AVMEDIA_TYPE_VIDEO,
  393. .config_props = config_input_top,
  394. .filter_frame = filter_frame,
  395. },{
  396. .name = "bottom",
  397. .type = AVMEDIA_TYPE_VIDEO,
  398. .filter_frame = filter_frame,
  399. },
  400. { NULL }
  401. };
  402. static const AVFilterPad blend_outputs[] = {
  403. {
  404. .name = "default",
  405. .type = AVMEDIA_TYPE_VIDEO,
  406. .config_props = config_output,
  407. .request_frame = request_frame,
  408. },
  409. { NULL }
  410. };
  411. AVFilter avfilter_vf_blend = {
  412. .name = "blend",
  413. .description = NULL_IF_CONFIG_SMALL("Blend two video frames into each other."),
  414. .init = init,
  415. .uninit = uninit,
  416. .priv_size = sizeof(BlendContext),
  417. .query_formats = query_formats,
  418. .inputs = blend_inputs,
  419. .outputs = blend_outputs,
  420. .priv_class = &blend_class,
  421. };