FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
vf_overlay.c File Reference
#include "avfilter.h"
#include "formats.h"
#include "libavutil/common.h"
#include "libavutil/eval.h"
#include "libavutil/avstring.h"
#include "libavutil/pixdesc.h"
#include "libavutil/imgutils.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "libavutil/timestamp.h"
#include "filters.h"
#include "drawutils.h"
#include "framesync.h"
#include "video.h"
#include "vf_overlay.h"

Go to the source code of this file.

Data Structures

struct  ThreadData
 Used for passing data between threads. More...
 

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 PTR_ADD(TYPE, ptr, byte_addend)   ((TYPE*)((uint8_t*)ptr + (byte_addend)))
 
#define CPTR_ADD(TYPE, ptr, byte_addend)   ((const TYPE*)((const uint8_t*)ptr + (byte_addend)))
 
#define DEFINE_BLEND_PLANE(depth, T, nbits)
 
#define DEFINE_ALPHA_COMPOSITE(depth, T, nbits)
 
#define DEFINE_BLEND_SLICE_YUV(depth, nbits)
 
#define DEFINE_BLEND_SLICE_PLANAR_FMT_(format_, blend_slice_fn_suffix_, hsub_, vsub_, main_straight_, overlay_straight_)
 
#define DEFINE_BLEND_SLICE_PLANAR_FMT(format_, blend_slice_fn_suffix_, hsub_, vsub_)
 
#define DEFINE_BLEND_SLICE_PACKED_FMT(format_, blend_slice_fn_suffix_, main_has_alpha_, main_straight_, overlay_straight_)
 
#define ASSIGN_BLEND_SLICE(format_)
 
#define OFFSET(x)   offsetof(OverlayContext, x)
 
#define FLAGS   AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 
#define TFLAGS   AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
 

Enumerations

enum  EvalMode {
  EVAL_MODE_ONCE, EVAL_MODE_FRAME, EVAL_MODE_NB, EVAL_MODE_INIT,
  EVAL_MODE_FRAME, EVAL_MODE_NB, EVAL_MODE_INIT, EVAL_MODE_FRAME,
  EVAL_MODE_NB, EVAL_MODE_INIT, EVAL_MODE_FRAME, EVAL_MODE_NB,
  EVAL_MODE_INIT, EVAL_MODE_FRAME, EVAL_MODE_NB, EVAL_MODE_INIT,
  EVAL_MODE_FRAME, EVAL_MODE_NB, EVAL_MODE_INIT, EVAL_MODE_FRAME,
  EVAL_MODE_NB, EVAL_MODE_INIT, EVAL_MODE_FRAME, EVAL_MODE_NB,
  EVAL_MODE_INIT, EVAL_MODE_FRAME, EVAL_MODE_NB, EVAL_MODE_INIT,
  EVAL_MODE_FRAME, EVAL_MODE_NB
}
 

Functions

static av_cold void uninit (AVFilterContext *ctx)
 
static int normalize_xy (double d, int chroma_sub)
 
static void eval_expr (AVFilterContext *ctx)
 
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 (const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
 
static int config_input_overlay (AVFilterLink *inlink)
 
static int config_output (AVFilterLink *outlink)
 
static av_always_inline void blend_slice_packed_rgb (AVFilterContext *ctx, AVFrame *dst, const AVFrame *src, int main_has_alpha, int x, int y, int overlay_straight, int main_straight, int jobnr, int nb_jobs)
 Blend image in src to destination buffer dst at position (x, y). More...
 
static av_always_inline void blend_slice_planar_rgb (AVFilterContext *ctx, AVFrame *dst, const AVFrame *src, int hsub, int vsub, int main_straight, int x, int y, int overlay_straight, int jobnr, int nb_jobs)
 
static int config_input_main (AVFilterLink *inlink)
 
static int init_slice_fn (AVFilterContext *ctx)
 
static int do_blend (FFFrameSync *fs)
 
static av_cold int init (AVFilterContext *ctx)
 
static int activate (AVFilterContext *ctx)
 
 FRAMESYNC_DEFINE_CLASS (overlay, OverlayContext, fs)
 

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 []
 
const FFFilter ff_vf_overlay
 

Detailed Description

overlay one video on top of another

Definition in file vf_overlay.c.

Macro Definition Documentation

◆ MAIN

#define MAIN   0

Definition at line 62 of file vf_overlay.c.

◆ OVERLAY

#define OVERLAY   1

Definition at line 63 of file vf_overlay.c.

◆ R

#define R   0

Definition at line 65 of file vf_overlay.c.

◆ G

#define G   1

Definition at line 66 of file vf_overlay.c.

◆ B

#define B   2

Definition at line 67 of file vf_overlay.c.

◆ A

#define A   3

Definition at line 68 of file vf_overlay.c.

◆ Y

#define Y   0

Definition at line 70 of file vf_overlay.c.

◆ U

#define U   1

Definition at line 71 of file vf_overlay.c.

◆ V

#define V   2

Definition at line 72 of file vf_overlay.c.

◆ FAST_DIV255

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

Definition at line 355 of file vf_overlay.c.

◆ UNPREMULTIPLY_ALPHA

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

Definition at line 362 of file vf_overlay.c.

◆ PTR_ADD

#define PTR_ADD (   TYPE,
  ptr,
  byte_addend 
)    ((TYPE*)((uint8_t*)ptr + (byte_addend)))

Definition at line 364 of file vf_overlay.c.

◆ CPTR_ADD

#define CPTR_ADD (   TYPE,
  ptr,
  byte_addend 
)    ((const TYPE*)((const uint8_t*)ptr + (byte_addend)))

Definition at line 365 of file vf_overlay.c.

◆ DEFINE_BLEND_PLANE

#define DEFINE_BLEND_PLANE (   depth,
  T,
  nbits 
)

Definition at line 459 of file vf_overlay.c.

◆ DEFINE_ALPHA_COMPOSITE

#define DEFINE_ALPHA_COMPOSITE (   depth,
  T,
  nbits 
)

Definition at line 585 of file vf_overlay.c.

◆ DEFINE_BLEND_SLICE_YUV

#define DEFINE_BLEND_SLICE_YUV (   depth,
  nbits 
)
Value:
static av_always_inline void blend_slice_yuv_##depth##_##nbits##bits(AVFilterContext *ctx, \
AVFrame *dst, const AVFrame *src, \
int hsub, int vsub, \
int main_straight, \
int x, int y, \
int overlay_straight, \
int jobnr, int nb_jobs) \
{ \
OverlayContext *s = ctx->priv; \
const int src_w = src->width; \
const int src_h = src->height; \
const int dst_w = dst->width; \
const int dst_h = dst->height; \
\
blend_plane_##depth##_##nbits##bits(ctx, dst, src, src_w, src_h, dst_w, dst_h, 0, 0, 0, \
x, y, main_straight, s->main_desc->comp[0].plane, s->main_desc->comp[0].offset, \
s->main_desc->comp[0].step, overlay_straight, 1, jobnr, nb_jobs); \
blend_plane_##depth##_##nbits##bits(ctx, dst, src, src_w, src_h, dst_w, dst_h, 1, hsub, vsub, \
x, y, main_straight, s->main_desc->comp[1].plane, s->main_desc->comp[1].offset, \
s->main_desc->comp[1].step, overlay_straight, 1, jobnr, nb_jobs); \
blend_plane_##depth##_##nbits##bits(ctx, dst, src, src_w, src_h, dst_w, dst_h, 2, hsub, vsub, \
x, y, main_straight, s->main_desc->comp[2].plane, s->main_desc->comp[2].offset, \
s->main_desc->comp[2].step, overlay_straight, 1, jobnr, nb_jobs); \
if (s->main_has_alpha) \
alpha_composite_##depth##_##nbits##bits(src, dst, src_w, src_h, dst_w, dst_h, x, y, main_straight, \
jobnr, nb_jobs); \
}

Definition at line 632 of file vf_overlay.c.

◆ DEFINE_BLEND_SLICE_PLANAR_FMT_

#define DEFINE_BLEND_SLICE_PLANAR_FMT_ (   format_,
  blend_slice_fn_suffix_,
  hsub_,
  vsub_,
  main_straight_,
  overlay_straight_ 
)
Value:
static int blend_slice_##format_(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \
{ \
OverlayContext *s = ctx->priv; \
ThreadData *td = arg; \
blend_slice_##blend_slice_fn_suffix_(ctx, td->dst, td->src, \
hsub_, vsub_, main_straight_, \
s->x, s->y, overlay_straight_, \
jobnr, nb_jobs); \
return 0; \
}

Definition at line 693 of file vf_overlay.c.

◆ DEFINE_BLEND_SLICE_PLANAR_FMT

#define DEFINE_BLEND_SLICE_PLANAR_FMT (   format_,
  blend_slice_fn_suffix_,
  hsub_,
  vsub_ 
)
Value:
DEFINE_BLEND_SLICE_PLANAR_FMT_(format_ ## _ss, blend_slice_fn_suffix_, hsub_, vsub_, 1, 1) \
DEFINE_BLEND_SLICE_PLANAR_FMT_(format_ ## _sp, blend_slice_fn_suffix_, hsub_, vsub_, 1, 0) \
DEFINE_BLEND_SLICE_PLANAR_FMT_(format_ ## _ps, blend_slice_fn_suffix_, hsub_, vsub_, 0, 1) \
DEFINE_BLEND_SLICE_PLANAR_FMT_(format_ ## _pp, blend_slice_fn_suffix_, hsub_, vsub_, 0, 0)

Definition at line 705 of file vf_overlay.c.

◆ DEFINE_BLEND_SLICE_PACKED_FMT

#define DEFINE_BLEND_SLICE_PACKED_FMT (   format_,
  blend_slice_fn_suffix_,
  main_has_alpha_,
  main_straight_,
  overlay_straight_ 
)
Value:
static int blend_slice_##format_(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \
{ \
OverlayContext *s = ctx->priv; \
ThreadData *td = arg; \
blend_slice_packed_##blend_slice_fn_suffix_(ctx, td->dst, td->src, \
main_has_alpha_, \
s->x, s->y, \
overlay_straight_, \
main_straight_, \
jobnr, nb_jobs); \
return 0; \
}

Definition at line 720 of file vf_overlay.c.

◆ ASSIGN_BLEND_SLICE

#define ASSIGN_BLEND_SLICE (   format_)
Value:
do { \
s->blend_slice = main_straight ? (overlay_straight ? format_##_ss : format_##_sp) \
: (overlay_straight ? format_##_ps : format_##_pp); \
} while (0)

◆ OFFSET

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

Definition at line 906 of file vf_overlay.c.

◆ FLAGS

Definition at line 907 of file vf_overlay.c.

◆ TFLAGS

Definition at line 908 of file vf_overlay.c.

Enumeration Type Documentation

◆ EvalMode

enum EvalMode
Enumerator
EVAL_MODE_ONCE 
EVAL_MODE_FRAME 
EVAL_MODE_NB 
EVAL_MODE_INIT 
EVAL_MODE_FRAME 
EVAL_MODE_NB 
EVAL_MODE_INIT 
EVAL_MODE_FRAME 
EVAL_MODE_NB 
EVAL_MODE_INIT 
EVAL_MODE_FRAME 
EVAL_MODE_NB 
EVAL_MODE_INIT 
EVAL_MODE_FRAME 
EVAL_MODE_NB 
EVAL_MODE_INIT 
EVAL_MODE_FRAME 
EVAL_MODE_NB 
EVAL_MODE_INIT 
EVAL_MODE_FRAME 
EVAL_MODE_NB 
EVAL_MODE_INIT 
EVAL_MODE_FRAME 
EVAL_MODE_NB 
EVAL_MODE_INIT 
EVAL_MODE_FRAME 
EVAL_MODE_NB 
EVAL_MODE_INIT 
EVAL_MODE_FRAME 
EVAL_MODE_NB 

Definition at line 74 of file vf_overlay.c.

Function Documentation

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 80 of file vf_overlay.c.

◆ normalize_xy()

static int normalize_xy ( double  d,
int  chroma_sub 
)
inlinestatic

Definition at line 89 of file vf_overlay.c.

Referenced by eval_expr().

◆ eval_expr()

static void eval_expr ( AVFilterContext ctx)
static

Definition at line 96 of file vf_overlay.c.

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

◆ set_expr()

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

Definition at line 108 of file vf_overlay.c.

Referenced by config_input_overlay(), and process_command().

◆ process_command()

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

Definition at line 129 of file vf_overlay.c.

◆ query_formats()

static int query_formats ( const AVFilterContext ctx,
AVFilterFormatsConfig **  cfg_in,
AVFilterFormatsConfig **  cfg_out 
)
static

Definition at line 161 of file vf_overlay.c.

◆ config_input_overlay()

static int config_input_overlay ( AVFilterLink inlink)
static

Definition at line 291 of file vf_overlay.c.

◆ config_output()

static int config_output ( AVFilterLink outlink)
static

Definition at line 337 of file vf_overlay.c.

◆ blend_slice_packed_rgb()

static av_always_inline void blend_slice_packed_rgb ( AVFilterContext ctx,
AVFrame dst,
const AVFrame src,
int  main_has_alpha,
int  x,
int  y,
int  overlay_straight,
int  main_straight,
int  jobnr,
int  nb_jobs 
)
static

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

< the amount of overlay to blend on to main

Definition at line 371 of file vf_overlay.c.

◆ blend_slice_planar_rgb()

static av_always_inline void blend_slice_planar_rgb ( AVFilterContext ctx,
AVFrame dst,
const AVFrame src,
int  hsub,
int  vsub,
int  main_straight,
int  x,
int  y,
int  overlay_straight,
int  jobnr,
int  nb_jobs 
)
static

Definition at line 664 of file vf_overlay.c.

◆ config_input_main()

static int config_input_main ( AVFilterLink inlink)
static

Definition at line 742 of file vf_overlay.c.

◆ init_slice_fn()

static int init_slice_fn ( AVFilterContext ctx)
static

Definition at line 760 of file vf_overlay.c.

Referenced by do_blend().

◆ do_blend()

static int do_blend ( FFFrameSync fs)
static

Definition at line 845 of file vf_overlay.c.

Referenced by init().

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 892 of file vf_overlay.c.

◆ activate()

static int activate ( AVFilterContext ctx)
static

Definition at line 900 of file vf_overlay.c.

◆ FRAMESYNC_DEFINE_CLASS()

FRAMESYNC_DEFINE_CLASS ( overlay  ,
OverlayContext  ,
fs   
)

Variable Documentation

◆ var_names

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",
"t",
}

Definition at line 48 of file vf_overlay.c.

Referenced by set_expr().

◆ alpha_pix_fmts

enum AVPixelFormat alpha_pix_fmts[]
static

◆ overlay_options

const AVOption overlay_options[]
static

Definition at line 910 of file vf_overlay.c.

◆ avfilter_vf_overlay_inputs

const AVFilterPad avfilter_vf_overlay_inputs[]
static
Initial value:
= {
{
.name = "main",
.config_props = config_input_main,
},
{
.name = "overlay",
.config_props = config_input_overlay,
},
}

Definition at line 944 of file vf_overlay.c.

◆ avfilter_vf_overlay_outputs

const AVFilterPad avfilter_vf_overlay_outputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_output,
},
}

Definition at line 957 of file vf_overlay.c.

◆ ff_vf_overlay

const FFFilter ff_vf_overlay
Initial value:
= {
.p.name = "overlay",
.p.description = NULL_IF_CONFIG_SMALL("Overlay a video source on top of the input."),
.p.priv_class = &overlay_class,
.preinit = overlay_framesync_preinit,
.init = init,
.uninit = uninit,
.priv_size = sizeof(OverlayContext),
}

Definition at line 965 of file vf_overlay.c.

avfilter_vf_overlay_outputs
static const AVFilterPad avfilter_vf_overlay_outputs[]
Definition: vf_overlay.c:957
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:263
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:590
query_formats
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: vf_overlay.c:161
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:102
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:591
hsub
static void hsub(htype *dst, const htype *src, int bins)
Definition: vf_median.c:74
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:212
DEFINE_BLEND_SLICE_PLANAR_FMT_
#define DEFINE_BLEND_SLICE_PLANAR_FMT_(format_, blend_slice_fn_suffix_, hsub_, vsub_, main_straight_, overlay_straight_)
Definition: vf_overlay.c:693
config_input_main
static int config_input_main(AVFilterLink *inlink)
Definition: vf_overlay.c:742
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:108
bits
uint8_t bits
Definition: vp3data.h:128
ctx
AVFormatContext * ctx
Definition: movenc.c:49
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:264
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:100
arg
const char * arg
Definition: jacosubdec.c:67
if
if(ret)
Definition: filter_design.txt:179
config_input_overlay
static int config_input_overlay(AVFilterLink *inlink)
Definition: vf_overlay.c:291
NULL
#define NULL
Definition: coverity.c:32
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_overlay.c:80
OverlayContext
Definition: vf_overlay.h:54
AV_PIX_FMT_ABGR
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:101
avfilter_vf_overlay_inputs
static const AVFilterPad avfilter_vf_overlay_inputs[]
Definition: vf_overlay.c:944
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_overlay.c:337
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:174
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:592
AV_PIX_FMT_ARGB
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:99
FILTER_QUERY_FUNC2
#define FILTER_QUERY_FUNC2(func)
Definition: filters.h:240
av_always_inline
#define av_always_inline
Definition: attributes.h:49
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_overlay.c:129
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
activate
static int activate(AVFilterContext *ctx)
Definition: vf_overlay.c:900
AVFilterContext
An instance of a filter.
Definition: avfilter.h:274
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:167
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
_
#define _
AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
Definition: avfilter.h:205
src
#define src
Definition: vp8dsp.c:248
AV_PIX_FMT_YUVA422P
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:173
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_overlay.c:892