FFmpeg
Loading...
Searching...
No Matches
vf_chromakey.c File Reference
#include "libavutil/opt.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "filters.h"

Go to the source code of this file.

Data Structures

struct  ChromakeyContext
 

Macros

#define FIXNUM(x)
 
#define RGB_TO_U(rgb)
 
#define RGB_TO_V(rgb)
 
#define OFFSET(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 inputs []
 
static const AVFilterPad outputs []
 
static const AVOption chromakey_options []
 
static enum AVPixelFormat chromakey_fmts []
 
const FFFilter ff_vf_chromakey
 
static const AVOption chromahold_options []
 
static enum AVPixelFormat hold_pixel_fmts []
 
const FFFilter ff_vf_chromahold
 

Macro Definition Documentation

◆ FIXNUM

#define FIXNUM ( x)
Value:
lrint((x) * (1 << 10))
#define lrint
Definition tablegen.h:53

Definition at line 270 of file vf_chromakey.c.

◆ RGB_TO_U

#define RGB_TO_U ( rgb)
Value:
(((- FIXNUM(0.16874) * rgb[0] - FIXNUM(0.33126) * rgb[1] + FIXNUM(0.50000) * rgb[2] + (1 << 9) - 1) >> 10) + 128)
Definition rpzaenc.c:60
#define FIXNUM(x)

Definition at line 271 of file vf_chromakey.c.

Referenced by config_output().

◆ RGB_TO_V

#define RGB_TO_V ( rgb)
Value:
((( 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.

Referenced by config_output().

◆ OFFSET

#define OFFSET ( x)
Value:

Definition at line 347 of file vf_chromakey.c.

◆ FLAGS

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 48 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 69 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 91 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 103 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 115 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 145 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 179 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 216 of file vf_chromakey.c.

Referenced by config_output().

◆ filter_frame()

static int filter_frame ( AVFilterLink * link,
AVFrame * frame )
static

Definition at line 255 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 305 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 317 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

◆ inputs

const AVFilterPad inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = filter_frame,
.config_props = config_input,
},
}
static int config_input(AVFilterLink *inlink)
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define AVFILTERPAD_FLAG_NEEDS_WRITABLE
The filter expects writable frames from its input link, duplicating data buffers if needed.
Definition filters.h:59

Definition at line 329 of file vf_chromakey.c.

◆ outputs

const AVFilterPad outputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_output,
},
}
static int config_output(AVBitStreamFilterLink *outlink)

Definition at line 339 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.00001, 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 }
}
#define FLAGS
Definition cmdutils.c:598
#define NULL
Definition coverity.c:32
#define OFFSET(x)
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition opt.h:270
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
@ AV_OPT_TYPE_COLOR
Underlying C type is uint8_t[4].
Definition opt.h:322

Definition at line 350 of file vf_chromakey.c.

◆ chromakey_fmts

enum AVPixelFormat chromakey_fmts[]
static
Initial value:
= {
}
#define AV_PIX_FMT_YUVA444P10
Definition pixfmt.h:598
#define AV_PIX_FMT_YUVA420P16
Definition pixfmt.h:601
#define AV_PIX_FMT_YUVA420P10
Definition pixfmt.h:596
#define AV_PIX_FMT_YUVA422P9
Definition pixfmt.h:594
#define AV_PIX_FMT_YUVA420P9
Definition pixfmt.h:593
#define AV_PIX_FMT_YUVA422P10
Definition pixfmt.h:597
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition pixfmt.h:108
@ 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_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition pixfmt.h:173
#define AV_PIX_FMT_YUVA422P12
Definition pixfmt.h:599
#define AV_PIX_FMT_YUVA444P16
Definition pixfmt.h:603
#define AV_PIX_FMT_YUVA422P16
Definition pixfmt.h:602
#define AV_PIX_FMT_YUVA444P9
Definition pixfmt.h:595
#define AV_PIX_FMT_YUVA444P12
Definition pixfmt.h:600

Definition at line 358 of file vf_chromakey.c.

◆ ff_vf_chromakey

const FFFilter ff_vf_chromakey
Initial value:
= {
.p.name = "chromakey",
.p.description = NULL_IF_CONFIG_SMALL("Turns a certain color into transparency. Operates on YUV colors."),
.p.priv_class = &chromakey_class,
.priv_size = sizeof(ChromakeyContext),
.process_command = process_command,
}
static const AVFilterPad inputs[]
Definition af_aap.c:299
static const AVFilterPad outputs[]
Definition af_aap.c:310
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
#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:196
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition avfilter.h:166
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define FILTER_PIXFMTS_ARRAY(array)
Definition filters.h:244
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
static enum AVPixelFormat chromakey_fmts[]

Definition at line 371 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.00001, 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 383 of file vf_chromakey.c.

◆ hold_pixel_fmts

enum AVPixelFormat hold_pixel_fmts[]
static
Initial value:
= {
}
#define AV_PIX_FMT_YUV420P16
Definition pixfmt.h:556
#define AV_PIX_FMT_YUV444P12
Definition pixfmt.h:552
#define AV_PIX_FMT_YUV444P9
Definition pixfmt.h:544
#define AV_PIX_FMT_YUV420P10
Definition pixfmt.h:545
#define AV_PIX_FMT_YUV422P9
Definition pixfmt.h:543
#define AV_PIX_FMT_YUV420P12
Definition pixfmt.h:549
#define AV_PIX_FMT_YUV422P12
Definition pixfmt.h:550
#define AV_PIX_FMT_YUV422P10
Definition pixfmt.h:546
#define AV_PIX_FMT_YUV420P9
Definition pixfmt.h:542
#define AV_PIX_FMT_YUV420P14
Definition pixfmt.h:553
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition pixfmt.h:77
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
#define AV_PIX_FMT_YUV422P14
Definition pixfmt.h:554
#define AV_PIX_FMT_YUV422P16
Definition pixfmt.h:557
#define AV_PIX_FMT_YUV444P14
Definition pixfmt.h:555
#define AV_PIX_FMT_YUV444P16
Definition pixfmt.h:558
#define AV_PIX_FMT_YUV444P10
Definition pixfmt.h:548

Definition at line 391 of file vf_chromakey.c.

◆ ff_vf_chromahold

const FFFilter ff_vf_chromahold
Initial value:
= {
.p.name = "chromahold",
.p.description = NULL_IF_CONFIG_SMALL("Turns a certain color range into gray."),
.p.priv_class = &chromahold_class,
.priv_size = sizeof(ChromakeyContext),
.process_command = process_command,
}
static enum AVPixelFormat hold_pixel_fmts[]

Definition at line 412 of file vf_chromakey.c.