Go to the documentation of this file.
44 int jobnr,
int nb_jobs);
51 const int slice_start = (
frame->height * jobnr) / nb_jobs;
53 const int min_diff = (255 + 255 + 255) *
s->similarity;
54 const float blend =
s->blend;
55 const int hsub =
s->hsub_log2;
56 const int vsub =
s->vsub_log2;
60 const uint8_t *srcy =
frame->data[0] +
frame->linesize[0] * y;
61 const uint8_t *srcu =
frame->data[1] +
frame->linesize[1] * (y >> vsub);
62 const uint8_t *srcv =
frame->data[2] +
frame->linesize[2] * (y >> vsub);
63 const uint8_t *bsrcy =
s->background->data[0] +
s->background->linesize[0] * y;
64 const uint8_t *bsrcu =
s->background->data[1] +
s->background->linesize[1] * (y >> vsub);
65 const uint8_t *bsrcv =
s->background->data[2] +
s->background->linesize[2] * (y >> vsub);
66 uint8_t *dst =
frame->data[3] +
frame->linesize[3] * y;
67 for (
int x = 0; x <
frame->width; x++) {
68 const int xx = x >>
hsub;
69 const int diff =
FFABS(srcy[x] - bsrcy[x]) +
70 FFABS(srcu[xx] - bsrcu[xx]) +
71 FFABS(srcv[xx] - bsrcv[xx]);
78 A = (
diff > min_diff) ? 255 : 0;
94 const int slice_start = (
frame->height * jobnr) / nb_jobs;
96 const int hsub =
s->hsub_log2;
97 const int vsub =
s->vsub_log2;
98 const int max =
s->max;
99 const int min_diff =
s->similarity * (
s->max +
s->max +
s->max);
100 const float blend =
s->blend;
103 for (
int y = slice_start; y <
slice_end; y++) {
104 const uint16_t *srcy = (
const uint16_t *)(
frame->data[0] +
frame->linesize[0] * y);
105 const uint16_t *srcu = (
const uint16_t *)(
frame->data[1] +
frame->linesize[1] * (y >> vsub));
106 const uint16_t *srcv = (
const uint16_t *)(
frame->data[2] +
frame->linesize[2] * (y >> vsub));
107 const uint16_t *bsrcy = (
const uint16_t *)(
s->background->data[0] +
s->background->linesize[0] * y);
108 const uint16_t *bsrcu = (
const uint16_t *)(
s->background->data[1] +
s->background->linesize[1] * (y >> vsub));
109 const uint16_t *bsrcv = (
const uint16_t *)(
s->background->data[2] +
s->background->linesize[2] * (y >> vsub));
110 uint16_t *dst = (uint16_t *)(
frame->data[3] +
frame->linesize[3] * y);
111 for (
int x = 0; x <
frame->width; x++) {
112 const int xx = x >>
hsub;
113 const int diff =
FFABS(srcy[x] - bsrcy[x] ) +
114 FFABS(srcu[xx] - bsrcu[xx]) +
115 FFABS(srcv[xx] - bsrcv[xx]);
129 s->sums[jobnr] = sum;
141 if (!
s->background) {
143 if (!
s->background) {
156 for (
int n = 0; n <
s->nb_threads; n++)
158 if (
s->max_sum *
s->threshold < sum) {
179 depth =
desc->comp[0].depth;
181 s->max = (1 << depth) - 1;
182 s->hsub_log2 =
desc->log2_chroma_w;
183 s->vsub_log2 =
desc->log2_chroma_h;
185 s->max_sum += 2LL * (
inlink->w >>
s->hsub_log2) * (
inlink->h >>
s->vsub_log2) *
s->max;
219 #define OFFSET(x) offsetof(BackgroundkeyContext, x)
220 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
245 .
name =
"backgroundkey",
248 .priv_class = &backgroundkey_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_GBRAP16
AVPixelFormat
Pixel format.
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 enum AVPixelFormat backgroundkey_fmts[]
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)
#define FILTER_PIXFMTS_ARRAY(array)
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define AV_PIX_FMT_YUVA422P9
This structure describes decoded (raw) audio or video data.
#define AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P10
const char * name
Filter name.
static const AVOption backgroundkey_options[]
A link between two filters.
#define AV_PIX_FMT_YUVA422P10
static av_cold void uninit(AVFilterContext *ctx)
#define AV_PIX_FMT_YUVA420P9
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
void * priv
private data for use by the filter
#define AV_PIX_FMT_YUVA444P16
static int filter_frame(AVFilterLink *link, AVFrame *frame)
A filter pad used for either input or output.
static int do_backgroundkey16_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
#define AV_PIX_FMT_GBRAP10
static const AVFilterPad backgroundkey_outputs[]
static const AVFilterPad backgroundkey_inputs[]
#define AV_PIX_FMT_GBRAP12
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
#define AV_PIX_FMT_YUVA444P12
AVFILTER_DEFINE_CLASS(backgroundkey)
#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
static int do_backgroundkey_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Describe the class of an AVClass context structure.
AVFilterLink ** inputs
array of pointers to input links
const AVFilter ff_vf_backgroundkey
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
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 av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
#define AV_PIX_FMT_YUVA444P10
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
static av_cold int config_output(AVFilterLink *outlink)
const char * name
Pad name.
void * av_calloc(size_t nmemb, size_t size)
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
#define AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA422P12
#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...
#define FILTER_OUTPUTS(array)
int(* do_slice)(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
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.