vf_overlay.c File Reference

overlay one video on top of another More...

#include "avfilter.h"
#include "formats.h"
#include "libavutil/common.h"
#include "libavutil/eval.h"
#include "libavutil/avstring.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/imgutils.h"
#include "libavutil/mathematics.h"
#include "libavutil/timestamp.h"
#include "internal.h"
#include "bufferqueue.h"
#include "drawutils.h"
#include "video.h"
Include dependency graph for vf_overlay.c:

Go to the source code of this file.

Data Structures

struct  OverlayContext
 

Macros

#define MAIN   0
 
#define OVERLAY   1
 
#define R   0
 
#define G   1
 
#define B   2
 
#define A   3
 
#define Y   0
 
#define U   1
 
#define V   2
 
#define FAST_DIV255(x)   ((((x) + 128) * 257) >> 16)
 
#define UNPREMULTIPLY_ALPHA(x, y)   ((((x) << 16) - ((x) << 9) + (x)) / ((((x) + (y)) << 8) - ((x) + (y)) - (y) * (x)))
 
#define OFFSET(x)   offsetof(OverlayContext, x)
 
#define FLAGS   AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 

Enumerations

enum  var_name {
  VAR_B1, VAR_B2, VAR_S1, VAR_S2,
  VAR_T1, VAR_T2, VAR_NB, VAR_N,
  VAR_T, VAR_S, VAR_VARS_NB, VAR_TB,
  VAR_PTS, VAR_START_PTS, VAR_PREV_PTS, VAR_PREV_SELECTED_PTS,
  VAR_T, VAR_START_T, VAR_PREV_T, VAR_PREV_SELECTED_T,
  VAR_PICT_TYPE, VAR_PICT_TYPE_I, VAR_PICT_TYPE_P, VAR_PICT_TYPE_B,
  VAR_PICT_TYPE_S, VAR_PICT_TYPE_SI, VAR_PICT_TYPE_SP, VAR_PICT_TYPE_BI,
  VAR_INTERLACE_TYPE, VAR_INTERLACE_TYPE_P, VAR_INTERLACE_TYPE_T, VAR_INTERLACE_TYPE_B,
  VAR_CONSUMED_SAMPLES_N, VAR_SAMPLES_N, VAR_SAMPLE_RATE, VAR_N,
  VAR_SELECTED_N, VAR_PREV_SELECTED_N, VAR_KEY, VAR_POS,
  VAR_SCENE, VAR_VARS_NB, VAR_FRAME_RATE, VAR_INTERLACED,
  VAR_N, VAR_NB_CONSUMED_SAMPLES, VAR_NB_SAMPLES, VAR_POS,
  VAR_PREV_INPTS, VAR_PREV_INT, VAR_PREV_OUTPTS, VAR_PREV_OUTT,
  VAR_PTS, VAR_SAMPLE_RATE, VAR_STARTPTS, VAR_STARTT,
  VAR_T, VAR_TB, VAR_RTCTIME, VAR_RTCSTART,
  VAR_VARS_NB, VAR_AVTB, VAR_INTB, VAR_SR,
  VAR_VARS_NB, VAR_W, VAR_H, VAR_CW,
  VAR_CH, VAR_HSUB, VAR_VSUB, VARS_NB,
  VAR_IN_W, VAR_IW, VAR_IN_H, VAR_IH,
  VAR_OUT_W, VAR_OW, VAR_OUT_H, VAR_OH,
  VAR_A, VAR_SAR, VAR_DAR, VAR_HSUB,
  VAR_VSUB, VAR_X, VAR_Y, VAR_N,
  VAR_POS, VAR_T, VAR_VARS_NB, VAR_DAR,
  VAR_HSUB, VAR_VSUB, VAR_LINE_H, VAR_LH,
  VAR_MAIN_H, VAR_h, VAR_H, VAR_MAIN_W,
  VAR_w, VAR_W, VAR_MAX_GLYPH_A, VAR_ASCENT,
  VAR_MAX_GLYPH_D, VAR_DESCENT, VAR_MAX_GLYPH_H, VAR_MAX_GLYPH_W,
  VAR_N, VAR_SAR, VAR_T, VAR_TEXT_H,
  VAR_TH, VAR_TEXT_W, VAR_TW, VAR_X,
  VAR_Y, VAR_VARS_NB, VAR_N, VAR_PTS,
  VAR_R, VAR_T, VAR_TB, VAR_NB,
  VAR_W, VAR_H, VAR_VAL, VAR_MAXVAL,
  VAR_MINVAL, VAR_NEGVAL, VAR_CLIPVAL, VAR_VARS_NB,
  VAR_MAIN_W, VAR_MW, VAR_MAIN_H, VAR_MH,
  VAR_OVERLAY_W, VAR_OW, VAR_OVERLAY_H, VAR_OH,
  VAR_HSUB, VAR_VSUB, VAR_X, VAR_Y,
  VAR_N, VAR_POS, VAR_T, VAR_VARS_NB,
  VAR_IN_W, VAR_IW, VAR_IN_H, VAR_IH,
  VAR_OUT_W, VAR_OW, VAR_OUT_H, VAR_OH,
  VAR_X, VAR_Y, VAR_A, VAR_SAR,
  VAR_DAR, VAR_HSUB, VAR_VSUB, VARS_NB,
  VAR_IN_W, VAR_IW, VAR_IN_H, VAR_IH,
  VAR_OUT_W, VAR_OW, VAR_OUT_H, VAR_OH,
  VAR_A, VAR_SAR, VAR_DAR, VAR_HSUB,
  VAR_VSUB, VARS_NB, VAR_X, VAR_Y,
  VAR_W, VAR_H, VAR_TIME, VAR_SPEED,
  VAR_TEMPO, VAR_ORDER, VAR_PATTERN, VAR_ROW,
  VAR_VARS_NB
}
 
enum  EvalTarget { EVAL_XY, EVAL_ENABLE, EVAL_ALL }
 

Functions

static av_cold int init (AVFilterContext *ctx)
 
static av_cold void uninit (AVFilterContext *ctx)
 
static int normalize_xy (double d, int chroma_sub)
 
static void eval_expr (AVFilterContext *ctx, enum EvalTarget eval_tgt)
 
static int set_expr (AVExpr **pexpr, const char *expr, const char *option, void *log_ctx)
 
static int process_command (AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
 
static int query_formats (AVFilterContext *ctx)
 
static int config_input_main (AVFilterLink *inlink)
 
static int config_input_overlay (AVFilterLink *inlink)
 
static int config_output (AVFilterLink *outlink)
 
static void blend_image (AVFilterContext *ctx, AVFrame *dst, AVFrame *src, int x, int y)
 Blend image in src to destination buffer dst at position (x, y). More...
 
static int try_filter_frame (AVFilterContext *ctx, AVFrame *mainpic)
 
static int try_filter_next_frame (AVFilterContext *ctx)
 
static int flush_frames (AVFilterContext *ctx)
 
static int filter_frame_main (AVFilterLink *inlink, AVFrame *inpicref)
 
static int filter_frame_over (AVFilterLink *inlink, AVFrame *inpicref)
 
static int request_frame (AVFilterLink *outlink)
 
 AVFILTER_DEFINE_CLASS (overlay)
 

Variables

static const char *const var_names []
 
static enum AVPixelFormat alpha_pix_fmts []
 
static const AVOption overlay_options []
 
static const AVFilterPad avfilter_vf_overlay_inputs []
 
static const AVFilterPad avfilter_vf_overlay_outputs []
 
AVFilter avfilter_vf_overlay
 

Detailed Description

overlay one video on top of another

Definition in file vf_overlay.c.

Macro Definition Documentation

#define A   3

Definition at line 82 of file vf_overlay.c.

Referenced by blend_image().

#define B   2

Definition at line 81 of file vf_overlay.c.

Referenced by blend_image().

#define FAST_DIV255 (   x)    ((((x) + 128) * 257) >> 16)

Definition at line 361 of file vf_overlay.c.

Referenced by blend_image().

Definition at line 712 of file vf_overlay.c.

#define G   1

Definition at line 80 of file vf_overlay.c.

Referenced by blend_image().

#define MAIN   0
#define OFFSET (   x)    offsetof(OverlayContext, x)

Definition at line 711 of file vf_overlay.c.

#define OVERLAY   1
#define R   0

Definition at line 79 of file vf_overlay.c.

Referenced by blend_image().

#define U   1

Definition at line 85 of file vf_overlay.c.

#define UNPREMULTIPLY_ALPHA (   x,
  y 
)    ((((x) << 16) - ((x) << 9) + (x)) / ((((x) + (y)) << 8) - ((x) + (y)) - (y) * (x)))

Definition at line 367 of file vf_overlay.c.

Referenced by blend_image().

#define V   2

Definition at line 86 of file vf_overlay.c.

#define Y   0

Definition at line 84 of file vf_overlay.c.

Enumeration Type Documentation

enum EvalTarget
Enumerator
EVAL_XY 
EVAL_ENABLE 
EVAL_ALL 

Definition at line 152 of file vf_overlay.c.

enum var_name
Enumerator
VAR_B1 
VAR_B2 
VAR_S1 
VAR_S2 
VAR_T1 
VAR_T2 
VAR_NB 
VAR_N 
VAR_T 
VAR_S 
VAR_VARS_NB 
VAR_TB 
VAR_PTS 
VAR_START_PTS 
VAR_PREV_PTS 
VAR_PREV_SELECTED_PTS 
VAR_T 
VAR_START_T 
VAR_PREV_T 
VAR_PREV_SELECTED_T 
VAR_PICT_TYPE 
VAR_PICT_TYPE_I 
VAR_PICT_TYPE_P 
VAR_PICT_TYPE_B 
VAR_PICT_TYPE_S 
VAR_PICT_TYPE_SI 
VAR_PICT_TYPE_SP 
VA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AR_TB 
VAR_NB 
VAR_W 
VAR_H 
VAR_VAL 
VAR_MAXVAL 
VAR_MINVAL 
VAR_NEGVAL 
VAR_CLIPVAL 
VAR_VARS_NB 
VAR_MAIN_W 
VAR_MW 
VAR_MAIN_H 
VAR_MH 
VAR_OVERLAY_W 
VAR_OW 
VAR_OVERLAY_H 
VAR_OH 
VAR_HSUB 
VAR_VSUB 
VAR_X 
VAR_Y 
VAR_N 
VAR_POS 
VAR_T 
VAR_VARS_NB 
VAR_IN_W 
VAR_IW 
VAR_IN_H 
VAR_IH 
VAR_OUT_W 
VAR_OW 
VAR_OUT_H 
VAR_OH 
VAR_X 
VAR_Y 
VAR_A 
VAR_SAR 
VAR_DAR 
VAR_HSUB 
VAR_VSUB 
VARS_NB 
VAR_IN_W 
VAR_IW 
VAR_IN_H 
VAR_IH 
VAR_OUT_W 
VAR_OW 
VAR_OUT_H 
VAR_OH 
VAR_A 
VAR_SAR 
VAR_DAR 
VAR_HSUB 
VAR_VSUB 
VARS_NB 
VAR_X 
VAR_Y 
VAR_W 
VAR_H 
VAR_TIME 
VAR_SPEED 
VAR_TEMPO 
VAR_ORDER 
VAR_PATTERN 
VAR_ROW 
VAR_VARS_NB 

Definition at line 61 of file vf_overlay.c.

Function Documentation

AVFILTER_DEFINE_CLASS ( overlay  )
static void blend_image ( AVFilterContext ctx,
AVFrame dst,
AVFrame src,
int  x,
int  y 
)
static

Blend image in src to destination buffer dst at position (x, y).

< the amount of overlay to blend on to main

< the amount of overlay to blend on to main

Definition at line 372 of file vf_overlay.c.

Referenced by try_filter_frame().

static int config_input_main ( AVFilterLink inlink)
static

Definition at line 283 of file vf_overlay.c.

static int config_input_overlay ( AVFilterLink inlink)
static

Definition at line 299 of file vf_overlay.c.

static int config_output ( AVFilterLink outlink)
static

Definition at line 348 of file vf_overlay.c.

static void eval_expr ( AVFilterContext ctx,
enum EvalTarget  eval_tgt 
)
static

Definition at line 154 of file vf_overlay.c.

Referenced by config_input_overlay(), process_command(), and try_filter_frame().

static int filter_frame_main ( AVFilterLink inlink,
AVFrame inpicref 
)
static

Definition at line 647 of file vf_overlay.c.

static int filter_frame_over ( AVFilterLink inlink,
AVFrame inpicref 
)
static

Definition at line 668 of file vf_overlay.c.

static int flush_frames ( AVFilterContext ctx)
static

Definition at line 639 of file vf_overlay.c.

Referenced by filter_frame_main(), and filter_frame_over().

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 121 of file vf_overlay.c.

static int normalize_xy ( double  d,
int  chroma_sub 
)
inlinestatic

Definition at line 145 of file vf_overlay.c.

Referenced by eval_expr().

static int process_command ( AVFilterContext ctx,
const char *  cmd,
const char *  args,
char *  res,
int  res_len,
int  flags 
)
static

Definition at line 191 of file vf_overlay.c.

static int query_formats ( AVFilterContext ctx)
static

Definition at line 219 of file vf_overlay.c.

static int request_frame ( AVFilterLink outlink)
static

Definition at line 681 of file vf_overlay.c.

static int set_expr ( AVExpr **  pexpr,
const char *  expr,
const char *  option,
void log_ctx 
)
static

Definition at line 170 of file vf_overlay.c.

Referenced by config_input_overlay(), and process_command().

static int try_filter_frame ( AVFilterContext ctx,
AVFrame mainpic 
)
static

Definition at line 560 of file vf_overlay.c.

Referenced by filter_frame_main(), and try_filter_next_frame().

static int try_filter_next_frame ( AVFilterContext ctx)
static

Definition at line 625 of file vf_overlay.c.

Referenced by filter_frame_over(), flush_frames(), and request_frame().

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 133 of file vf_overlay.c.

Variable Documentation

enum AVPixelFormat alpha_pix_fmts[]
static
Initial value:
= {
}
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:105
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:98
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:99
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:96
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:97
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:218

Definition at line 277 of file vf_overlay.c.

Referenced by config_input_main(), and config_input_overlay().

AVFilter avfilter_vf_overlay
Initial value:
= {
.name = "overlay",
.description = NULL_IF_CONFIG_SMALL("Overlay a video source on top of the input."),
.init = init,
.uninit = uninit,
.priv_size = sizeof(OverlayContext),
.priv_class = &overlay_class,
}
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:117
static const AVFilterPad avfilter_vf_overlay_inputs[]
Definition: vf_overlay.c:733
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static const AVFilterPad avfilter_vf_overlay_outputs[]
Definition: vf_overlay.c:751
static av_cold int init(AVFilterContext *ctx)
Definition: vf_overlay.c:121
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_overlay.c:133
static int query_formats(AVFilterContext *ctx)
Definition: vf_overlay.c:219
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_overlay.c:191
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs

Definition at line 761 of file vf_overlay.c.

const AVFilterPad avfilter_vf_overlay_inputs[]
static
Initial value:
= {
{
.name = "main",
.get_video_buffer = ff_null_get_video_buffer,
.config_props = config_input_main,
.filter_frame = filter_frame_main,
.needs_writable = 1,
},
{
.name = "overlay",
.config_props = config_input_overlay,
.filter_frame = filter_frame_over,
},
{ NULL }
}
AVFrame * ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
Definition: video.c:35
static int filter_frame_over(AVFilterLink *inlink, AVFrame *inpicref)
Definition: vf_overlay.c:668
static int config_input_overlay(AVFilterLink *inlink)
Definition: vf_overlay.c:299
NULL
Definition: eval.c:55
static int config_input_main(AVFilterLink *inlink)
Definition: vf_overlay.c:283
static int filter_frame_main(AVFilterLink *inlink, AVFrame *inpicref)
Definition: vf_overlay.c:647

Definition at line 733 of file vf_overlay.c.

const AVFilterPad avfilter_vf_overlay_outputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_output,
.request_frame = request_frame,
},
{ NULL }
}
static int request_frame(AVFilterLink *outlink)
Definition: vf_overlay.c:681
NULL
Definition: eval.c:55
static int config_output(AVFilterLink *outlink)
Definition: vf_overlay.c:348

Definition at line 751 of file vf_overlay.c.

const AVOption overlay_options[]
static
Initial value:
= {
{ "x", "set the x expression", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str = "0"}, CHAR_MIN, CHAR_MAX, FLAGS },
{ "y", "set the y expression", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str = "0"}, CHAR_MIN, CHAR_MAX, FLAGS },
{ "enable", "set expression which enables overlay", OFFSET(enable_expr), AV_OPT_TYPE_STRING, {.str = "1"}, .flags = FLAGS },
{ "eval", "specify when to evaluate expressions", OFFSET(eval_mode), AV_OPT_TYPE_INT, {.i64 = EVAL_MODE_FRAME}, 0, EVAL_MODE_NB-1, FLAGS, "eval" },
{ "init", "eval expressions once during initialization", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_INIT}, .flags = FLAGS, .unit = "eval" },
{ "frame", "eval expressions per-frame", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_FRAME}, .flags = FLAGS, .unit = "eval" },
{ "rgb", "force packed RGB in input and output (deprecated)", OFFSET(allow_packed_rgb), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS },
{ "shortest", "force termination when the shortest input terminates", OFFSET(shortest), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
{ "format", "set output format", OFFSET(format), AV_OPT_TYPE_INT, {.i64=OVERLAY_FORMAT_YUV420}, 0, OVERLAY_FORMAT_NB-1, FLAGS, "format" },
{ "yuv420", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_YUV420}, .flags = FLAGS, .unit = "format" },
{ "yuv444", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_YUV444}, .flags = FLAGS, .unit = "format" },
{ "rgb", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_RGB}, .flags = FLAGS, .unit = "format" },
{ "repeatlast", "repeat overlay of the last overlay frame", OFFSET(repeatlast), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS },
{ NULL }
}
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate.The lists are not just lists
NULL
Definition: eval.c:55
#define OFFSET(x)
Definition: vf_overlay.c:711
#define FLAGS
Definition: vf_overlay.c:712

Definition at line 714 of file vf_overlay.c.

const char* const var_names[]
static
Initial value:
= {
"main_w", "W",
"main_h", "H",
"overlay_w", "w",
"overlay_h", "h",
"hsub",
"vsub",
"x",
"y",
"n",
"pos",
"t",
}
NULL
Definition: eval.c:55

Definition at line 46 of file vf_overlay.c.

Referenced by set_expr().