Go to the documentation of this file.
21 #include "config_components.h"
45 int jobnr,
int nb_jobs);
49 float similarity,
float iblend,
int max,
double scale)
51 double dr, dg, db,
diff;
53 dr =
r *
scale - colorkey_rgba[0];
54 dg =
g *
scale - colorkey_rgba[1];
55 db =
b *
scale - colorkey_rgba[2];
57 diff = sqrt((dr * dr + dg * dg + db * db) / (255.0 * 255.0 * 3.0));
59 if (iblend < 10000.0) {
62 return (
diff > similarity) ?
max : 0;
66 #define COLORKEY_SLICE(name, type) \
67 static int do_colorkey_slice##name(AVFilterContext *avctx, \
69 int jobnr, int nb_jobs) \
71 AVFrame *frame = arg; \
72 const int slice_start = (frame->height * jobnr) / nb_jobs; \
73 const int slice_end = (frame->height * (jobnr + 1)) / nb_jobs; \
74 ColorkeyContext *ctx = avctx->priv; \
75 const float similarity = ctx->similarity; \
76 const float iblend = 1.f / ctx->blend; \
77 const uint8_t *colorkey_rgba = ctx->colorkey_rgba; \
78 const uint8_t *co = ctx->co; \
79 const double scale = ctx->scale; \
80 const int max = ctx->max; \
82 for (int y = slice_start; y < slice_end; y++) { \
83 type *dst = (type *)(frame->data[0] + y * frame->linesize[0]);\
85 for (int x = 0; x < frame->width; x++) { \
86 const int o = x * 4; \
88 dst[o + co[3]] = do_colorkey_pixel(colorkey_rgba, \
92 similarity, iblend, max, scale); \
102 #define COLORHOLD_SLICE(name, type, htype) \
103 static int do_colorhold_slice##name(AVFilterContext *avctx, void *arg, \
104 int jobnr, int nb_jobs) \
106 AVFrame *frame = arg; \
107 const int slice_start = (frame->height * jobnr) / nb_jobs; \
108 const int slice_end = (frame->height * (jobnr + 1)) / nb_jobs; \
109 ColorkeyContext *ctx = avctx->priv; \
110 const int depth = ctx->depth; \
111 const int max = ctx->max; \
112 const int half = max / 2; \
113 const uint8_t *co = ctx->co; \
114 const uint8_t *colorkey_rgba = ctx->colorkey_rgba; \
115 const float similarity = ctx->similarity; \
116 const float iblend = 1.f / ctx->blend; \
117 const double scale = ctx->scale; \
119 for (int y = slice_start; y < slice_end; ++y) { \
120 type *dst = (type *)(frame->data[0] + y * frame->linesize[0]); \
122 for (int x = 0; x < frame->width; ++x) { \
126 r = dst[o + co[0]]; \
127 g = dst[o + co[1]]; \
128 b = dst[o + co[2]]; \
130 t = do_colorkey_pixel(colorkey_rgba, r, g, b, \
131 similarity, iblend, max, scale); \
134 htype a = (r + g + b) / 3; \
135 htype rt = max - t; \
137 dst[o + co[0]] = (a * t + r * rt + half) >> depth; \
138 dst[o + co[1]] = (a * t + g * rt + half) >> depth; \
139 dst[o + co[2]] = (a * t + b * rt + half) >> depth; \
169 ctx->depth =
desc->comp[0].depth;
170 ctx->max = (1 <<
ctx->depth) - 1;
171 ctx->scale = 255.0 /
ctx->max;
177 if (!strcmp(avctx->
filter->
name,
"colorkey")) {
178 ctx->do_slice =
ctx->max == 255 ? do_colorkey_slice8 : do_colorkey_slice16;
180 ctx->do_slice =
ctx->max == 255 ? do_colorhold_slice8 : do_colorhold_slice16;
213 #define OFFSET(x) offsetof(ColorkeyContext, x)
214 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
216 #if CONFIG_COLORKEY_FILTER
218 static const AVOption colorkey_options[] = {
229 .description =
NULL_IF_CONFIG_SMALL(
"Turns a certain color into transparency. Operates on RGB colors."),
231 .priv_class = &colorkey_class,
240 #if CONFIG_COLORHOLD_FILTER
242 static const AVOption colorhold_options[] = {
253 .description =
NULL_IF_CONFIG_SMALL(
"Turns a certain color range into gray. Operates on RGB colors."),
255 .priv_class = &colorhold_class,
AVPixelFormat
Pixel format.
static const AVFilterPad colorkey_outputs[]
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
const AVFilter ff_vf_colorhold
#define FILTER_PIXFMTS_ARRAY(array)
This structure describes decoded (raw) audio or video data.
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
const char * name
Filter name.
#define COLORKEY_SLICE(name, type)
A link between two filters.
#define COLORHOLD_SLICE(name, type, htype)
void * priv
private data for use by the filter
static av_always_inline float scale(float x, float s)
A filter pad used for either input or output.
int(* do_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_frame(AVFilterLink *link, AVFrame *frame)
#define FILTER_INPUTS(array)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame 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 they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
#define AV_PIX_FMT_RGBA64
Describe the class of an AVClass context structure.
AVFilterLink ** inputs
array of pointers to input links
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int format
agreed upon media format
AVFilterContext * src
source filter
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
static const AVFilterPad colorkey_inputs[]
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
#define AVFILTER_DEFINE_CLASS(fname)
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
#define AV_PIX_FMT_BGRA64
int w
agreed upon image width
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
const char * name
Pad name.
static enum AVPixelFormat pixel_fmts[]
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 the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
int h
agreed upon image height
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static av_always_inline int diff(const uint32_t a, const uint32_t b)
#define FILTER_OUTPUTS(array)
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
const AVFilter * filter
the AVFilter of which this is an instance
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
static int do_colorkey_pixel(const uint8_t *colorkey_rgba, int r, int g, int b, float similarity, float iblend, int max, double scale)
static av_cold int config_output(AVFilterLink *outlink)
const AVFilter ff_vf_colorkey
AVFilterLink ** outputs
array of pointers to output links
#define AVFILTERPAD_FLAG_NEEDS_WRITABLE
The filter expects writable frames from its input link, duplicating data buffers if needed.