FFmpeg
Data Structures | Macros | Functions | Variables
vf_chromakey.c File Reference
#include "libavutil/opt.h"
#include "libavutil/imgutils.h"
#include "libavutil/intreadwrite.h"
#include "avfilter.h"
#include "formats.h"
#include "internal.h"
#include "video.h"

Go to the source code of this file.

Data Structures

struct  ChromakeyContext
 

Macros

#define FIXNUM(x)   lrint((x) * (1 << 10))
 
#define RGB_TO_U(rgb)   (((- FIXNUM(0.16874) * rgb[0] - FIXNUM(0.33126) * rgb[1] + FIXNUM(0.50000) * rgb[2] + (1 << 9) - 1) >> 10) + 128)
 
#define RGB_TO_V(rgb)   ((( FIXNUM(0.50000) * rgb[0] - FIXNUM(0.41869) * rgb[1] - FIXNUM(0.08131) * rgb[2] + (1 << 9) - 1) >> 10) + 128)
 
#define OFFSET(x)   offsetof(ChromakeyContext, x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
 

Functions

static uint8_t do_chromakey_pixel (ChromakeyContext *ctx, uint8_t u[9], uint8_t v[9])
 
static uint16_t do_chromakey_pixel16 (ChromakeyContext *ctx, uint16_t u[9], uint16_t v[9])
 
static av_always_inline void get_pixel_uv (AVFrame *frame, int hsub_log2, int vsub_log2, int x, int y, uint8_t *u, uint8_t *v)
 
static av_always_inline void get_pixel16_uv (AVFrame *frame, int hsub_log2, int vsub_log2, int x, int y, uint16_t *u, uint16_t *v)
 
static int do_chromakey_slice (AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
 
static int do_chromakey16_slice (AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
 
static int do_chromahold_slice (AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
 
static int do_chromahold16_slice (AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
 
static int filter_frame (AVFilterLink *link, AVFrame *frame)
 
static av_cold int config_output (AVFilterLink *outlink)
 
static av_cold int config_input (AVFilterLink *inlink)
 
static int process_command (AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
 
 AVFILTER_DEFINE_CLASS (chromakey)
 
 AVFILTER_DEFINE_CLASS (chromahold)
 

Variables

static const AVFilterPad chromakey_inputs []
 
static const AVFilterPad chromakey_outputs []
 
static const AVOption chromakey_options []
 
static enum AVPixelFormat chromakey_fmts []
 
const AVFilter ff_vf_chromakey
 
static const AVOption chromahold_options []
 
static const AVFilterPad chromahold_inputs []
 
static const AVFilterPad chromahold_outputs []
 
static enum AVPixelFormat hold_pixel_fmts []
 
const AVFilter ff_vf_chromahold
 

Macro Definition Documentation

◆ FIXNUM

#define FIXNUM (   x)    lrint((x) * (1 << 10))

Definition at line 270 of file vf_chromakey.c.

◆ RGB_TO_U

#define RGB_TO_U (   rgb)    (((- FIXNUM(0.16874) * rgb[0] - FIXNUM(0.33126) * rgb[1] + FIXNUM(0.50000) * rgb[2] + (1 << 9) - 1) >> 10) + 128)

Definition at line 271 of file vf_chromakey.c.

◆ RGB_TO_V

#define RGB_TO_V (   rgb)    ((( FIXNUM(0.50000) * rgb[0] - FIXNUM(0.41869) * rgb[1] - FIXNUM(0.08131) * rgb[2] + (1 << 9) - 1) >> 10) + 128)

Definition at line 272 of file vf_chromakey.c.

◆ OFFSET

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

Definition at line 346 of file vf_chromakey.c.

◆ FLAGS

Definition at line 347 of file vf_chromakey.c.

Function Documentation

◆ do_chromakey_pixel()

static uint8_t do_chromakey_pixel ( ChromakeyContext ctx,
uint8_t  u[9],
uint8_t  v[9] 
)
static

Definition at line 50 of file vf_chromakey.c.

Referenced by do_chromakey_slice().

◆ do_chromakey_pixel16()

static uint16_t do_chromakey_pixel16 ( ChromakeyContext ctx,
uint16_t  u[9],
uint16_t  v[9] 
)
static

Definition at line 71 of file vf_chromakey.c.

Referenced by do_chromakey16_slice().

◆ get_pixel_uv()

static av_always_inline void get_pixel_uv ( AVFrame frame,
int  hsub_log2,
int  vsub_log2,
int  x,
int  y,
uint8_t *  u,
uint8_t *  v 
)
static

Definition at line 93 of file vf_chromakey.c.

Referenced by do_chromakey_slice().

◆ get_pixel16_uv()

static av_always_inline void get_pixel16_uv ( AVFrame frame,
int  hsub_log2,
int  vsub_log2,
int  x,
int  y,
uint16_t *  u,
uint16_t *  v 
)
static

Definition at line 105 of file vf_chromakey.c.

Referenced by do_chromakey16_slice().

◆ do_chromakey_slice()

static int do_chromakey_slice ( AVFilterContext avctx,
void *  arg,
int  jobnr,
int  nb_jobs 
)
static

Definition at line 117 of file vf_chromakey.c.

Referenced by config_output().

◆ do_chromakey16_slice()

static int do_chromakey16_slice ( AVFilterContext avctx,
void *  arg,
int  jobnr,
int  nb_jobs 
)
static

Definition at line 147 of file vf_chromakey.c.

Referenced by config_output().

◆ do_chromahold_slice()

static int do_chromahold_slice ( AVFilterContext avctx,
void *  arg,
int  jobnr,
int  nb_jobs 
)
static

Definition at line 181 of file vf_chromakey.c.

Referenced by config_output().

◆ do_chromahold16_slice()

static int do_chromahold16_slice ( AVFilterContext avctx,
void *  arg,
int  jobnr,
int  nb_jobs 
)
static

Definition at line 218 of file vf_chromakey.c.

Referenced by config_output().

◆ filter_frame()

static int filter_frame ( AVFilterLink link,
AVFrame frame 
)
static

Definition at line 257 of file vf_chromakey.c.

◆ config_output()

static av_cold int config_output ( AVFilterLink outlink)
static

Definition at line 274 of file vf_chromakey.c.

Referenced by process_command().

◆ config_input()

static av_cold int config_input ( AVFilterLink inlink)
static

Definition at line 304 of file vf_chromakey.c.

◆ 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 316 of file vf_chromakey.c.

◆ AVFILTER_DEFINE_CLASS() [1/2]

AVFILTER_DEFINE_CLASS ( chromakey  )

◆ AVFILTER_DEFINE_CLASS() [2/2]

AVFILTER_DEFINE_CLASS ( chromahold  )

Variable Documentation

◆ chromakey_inputs

const AVFilterPad chromakey_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = filter_frame,
.config_props = config_input,
},
}

Definition at line 328 of file vf_chromakey.c.

◆ chromakey_outputs

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

Definition at line 338 of file vf_chromakey.c.

◆ chromakey_options

const AVOption chromakey_options[]
static
Initial value:
= {
{ "color", "set the chromakey key color", OFFSET(chromakey_rgba), AV_OPT_TYPE_COLOR, { .str = "black" }, 0, 0, FLAGS },
{ "similarity", "set the chromakey similarity value", OFFSET(similarity), AV_OPT_TYPE_FLOAT, { .dbl = 0.01 }, 0.01, 1.0, FLAGS },
{ "blend", "set the chromakey key blend value", OFFSET(blend), AV_OPT_TYPE_FLOAT, { .dbl = 0.0 }, 0.0, 1.0, FLAGS },
{ "yuv", "color parameter is in yuv instead of rgb", OFFSET(is_yuv), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
{ NULL }
}

Definition at line 349 of file vf_chromakey.c.

◆ chromakey_fmts

enum AVPixelFormat chromakey_fmts[]
static

◆ ff_vf_chromakey

const AVFilter ff_vf_chromakey
Initial value:
= {
.name = "chromakey",
.description = NULL_IF_CONFIG_SMALL("Turns a certain color into transparency. Operates on YUV colors."),
.priv_size = sizeof(ChromakeyContext),
.priv_class = &chromakey_class,
.process_command = process_command,
}

Definition at line 370 of file vf_chromakey.c.

◆ chromahold_options

const AVOption chromahold_options[]
static
Initial value:
= {
{ "color", "set the chromahold key color", OFFSET(chromakey_rgba), AV_OPT_TYPE_COLOR, { .str = "black" }, 0, 0, FLAGS },
{ "similarity", "set the chromahold similarity value", OFFSET(similarity), AV_OPT_TYPE_FLOAT, { .dbl = 0.01 }, 0.01, 1.0, FLAGS },
{ "blend", "set the chromahold blend value", OFFSET(blend), AV_OPT_TYPE_FLOAT, { .dbl = 0.0 }, 0.0, 1.0, FLAGS },
{ "yuv", "color parameter is in yuv instead of rgb", OFFSET(is_yuv), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
{ NULL }
}

Definition at line 382 of file vf_chromakey.c.

◆ chromahold_inputs

const AVFilterPad chromahold_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = filter_frame,
.config_props = config_input,
},
}

Definition at line 390 of file vf_chromakey.c.

◆ chromahold_outputs

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

Definition at line 400 of file vf_chromakey.c.

◆ hold_pixel_fmts

enum AVPixelFormat hold_pixel_fmts[]
static

◆ ff_vf_chromahold

const AVFilter ff_vf_chromahold
Initial value:
= {
.name = "chromahold",
.description = NULL_IF_CONFIG_SMALL("Turns a certain color range into gray."),
.priv_size = sizeof(ChromakeyContext),
.priv_class = &chromahold_class,
.process_command = process_command,
}

Definition at line 429 of file vf_chromakey.c.

AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:474
config_input
static av_cold int config_input(AVFilterLink *inlink)
Definition: vf_chromakey.c:304
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: internal.h:170
chromakey_outputs
static const AVFilterPad chromakey_outputs[]
Definition: vf_chromakey.c:338
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:466
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:473
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:468
chromahold_inputs
static const AVFilterPad chromahold_inputs[]
Definition: vf_chromakey.c:390
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:431
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:469
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:465
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:475
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:429
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:434
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:443
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:101
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:444
ChromakeyContext
Definition: vf_chromakey.c:29
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:472
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:428
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:442
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:190
NULL
#define NULL
Definition: coverity.c:32
AV_OPT_TYPE_COLOR
@ AV_OPT_TYPE_COLOR
Definition: opt.h:240
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_chromakey.c:316
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:432
chromahold_outputs
static const AVFilterPad chromahold_outputs[]
Definition: vf_chromakey.c:400
filter_frame
static int filter_frame(AVFilterLink *link, AVFrame *frame)
Definition: vf_chromakey.c:257
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:115
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:436
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:438
chromakey_inputs
static const AVFilterPad chromakey_inputs[]
Definition: vf_chromakey.c:328
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:167
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:470
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:152
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:430
hold_pixel_fmts
static enum AVPixelFormat hold_pixel_fmts[]
Definition: vf_chromakey.c:408
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:467
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:435
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:440
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUVA422P12
Definition: pixfmt.h:471
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
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:127
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
OFFSET
#define OFFSET(x)
Definition: vf_chromakey.c:346
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
FLAGS
#define FLAGS
Definition: vf_chromakey.c:347
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:191
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:441
chromakey_fmts
static enum AVPixelFormat chromakey_fmts[]
Definition: vf_chromakey.c:357
config_output
static av_cold int config_output(AVFilterLink *outlink)
Definition: vf_chromakey.c:274
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:166
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:439
AVFILTERPAD_FLAG_NEEDS_WRITABLE
#define AVFILTERPAD_FLAG_NEEDS_WRITABLE
The filter expects writable frames from its input link, duplicating data buffers if needed.
Definition: internal.h:68