Go to the documentation of this file.
39 int jobnr,
int nb_jobs);
44 int dr = (
int)
r -
ctx->colorkey_rgba[0];
45 int dg = (
int)
g -
ctx->colorkey_rgba[1];
46 int db = (
int)
b -
ctx->colorkey_rgba[2];
48 double diff = sqrt((dr * dr + dg * dg + db * db) / (255.0 * 255.0));
50 if (
ctx->blend > 0.0001) {
51 return av_clipd((
diff -
ctx->similarity) /
ctx->blend, 0.0, 1.0) * 255.0;
53 return (
diff >
ctx->similarity) ? 255 : 0;
61 const int slice_start = (
frame->height * jobnr) / nb_jobs;
68 for (y = slice_start; y <
slice_end; ++y) {
69 for (x = 0; x <
frame->width; ++x) {
70 o =
frame->linesize[0] * y + x * 4;
87 const int slice_start = (
frame->height * jobnr) / nb_jobs;
94 for (y = slice_start; y <
slice_end; ++y) {
95 for (x = 0; x <
frame->width; ++x) {
98 o =
frame->linesize[0] * y + x * 4;
106 int a = (
r +
g +
b) / 3;
109 frame->data[0][o +
ctx->co[0]] = (
a * t +
r * rt + 127) >> 8;
110 frame->data[0][o +
ctx->co[1]] = (
a * t +
g * rt + 127) >> 8;
111 frame->data[0][o +
ctx->co[2]] = (
a * t +
b * rt + 127) >> 8;
123 if (!strcmp(avctx->
filter->
name,
"colorkey")) {
158 for (
i = 0;
i < 4; ++
i)
201 #define OFFSET(x) offsetof(ColorkeyContext, x)
202 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
204 #if CONFIG_COLORKEY_FILTER
206 static const AVOption colorkey_options[] = {
217 .description =
NULL_IF_CONFIG_SMALL(
"Turns a certain color into transparency. Operates on RGB colors."),
219 .priv_class = &colorkey_class,
228 #if CONFIG_COLORHOLD_FILTER
230 static const AVOption colorhold_options[] = {
241 .description =
NULL_IF_CONFIG_SMALL(
"Turns a certain color range into gray. Operates on RGB colors."),
243 .priv_class = &colorhold_class,
static av_cold int init_filter(AVFilterContext *avctx)
AVPixelFormat
Pixel format.
static av_cold int init(AVCodecContext *avctx)
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 all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
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)
static av_cold int query_formats(AVFilterContext *avctx)
This structure describes decoded (raw) audio or video data.
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
const char * name
Filter name.
A link between two filters.
void * priv
private data for use by the filter
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)
static int do_colorkey_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
static const AVFilterPad outputs[]
static uint8_t do_colorkey_pixel(ColorkeyContext *ctx, uint8_t r, uint8_t g, uint8_t b)
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...
Describe the class of an AVClass context structure.
AVFilterLink ** inputs
array of pointers to input links
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
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
static int do_colorhold_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
#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
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
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 i(width, name, range_min, range_max)
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.
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
avfilter_execute_func * execute
int h
agreed upon image height
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
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 flags(name, subs,...)
const AVFilter * filter
the AVFilter of which this is an instance
static av_cold int config_output(AVFilterLink *outlink)
AVFilterLink ** outputs
array of pointers to output links