Go to the documentation of this file.
43 int jobnr,
int nb_jobs);
50 const int slice_start = (
frame->
height * jobnr) / nb_jobs;
52 const int min_diff = (255 + 255 + 255) *
s->similarity;
53 const float blend =
s->blend;
54 const int hsub =
s->hsub_log2;
55 const int vsub =
s->vsub_log2;
62 const uint8_t *bsrcy =
s->background->data[0] +
s->background->linesize[0] * y;
63 const uint8_t *bsrcu =
s->background->data[1] +
s->background->linesize[1] * (y >> vsub);
64 const uint8_t *bsrcv =
s->background->data[2] +
s->background->linesize[2] * (y >> vsub);
67 const int xx = x >>
hsub;
68 const int diff =
FFABS(srcy[x] - bsrcy[x]) +
69 FFABS(srcu[xx] - bsrcu[xx]) +
70 FFABS(srcv[xx] - bsrcv[xx]);
77 A = (
diff > min_diff) ? 255 : 0;
93 const int slice_start = (
frame->
height * jobnr) / nb_jobs;
95 const int hsub =
s->hsub_log2;
96 const int vsub =
s->vsub_log2;
97 const int max =
s->max;
98 const int min_diff =
s->similarity * (
s->max +
s->max +
s->max);
99 const float blend =
s->blend;
102 for (
int y = slice_start; y <
slice_end; y++) {
106 const uint16_t *bsrcy = (
const uint16_t *)(
s->background->data[0] +
s->background->linesize[0] * y);
107 const uint16_t *bsrcu = (
const uint16_t *)(
s->background->data[1] +
s->background->linesize[1] * (y >> vsub));
108 const uint16_t *bsrcv = (
const uint16_t *)(
s->background->data[2] +
s->background->linesize[2] * (y >> vsub));
111 const int xx = x >>
hsub;
112 const int diff =
FFABS(srcy[x] - bsrcy[x] ) +
113 FFABS(srcu[xx] - bsrcu[xx]) +
114 FFABS(srcv[xx] - bsrcv[xx]);
128 s->sums[jobnr] = sum;
140 if (!
s->background) {
142 if (!
s->background) {
155 for (
int n = 0; n <
s->nb_threads; n++)
157 if (
s->max_sum *
s->threshold < sum) {
178 depth =
desc->comp[0].depth;
180 s->max = (1 << depth) - 1;
181 s->hsub_log2 =
desc->log2_chroma_w;
182 s->vsub_log2 =
desc->log2_chroma_h;
184 s->max_sum += 2LL * (
inlink->w >>
s->hsub_log2) * (
inlink->h >>
s->vsub_log2) *
s->max;
218 #define OFFSET(x) offsetof(BackgroundkeyContext, x)
219 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
244 .
name =
"backgroundkey",
247 .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
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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)
#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)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
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.