Go to the documentation of this file.
94 return (
int)d & ~((1 << chroma_sub) - 1);
120 "Error when evaluating the expression '%s' for %s\n",
131 char *res,
int res_len,
int flags)
136 if (!strcmp(cmd,
"x"))
138 else if (!strcmp(cmd,
"y"))
171 static const enum AVPixelFormat overlay_pix_fmts_yuv420[] = {
178 static const enum AVPixelFormat overlay_pix_fmts_yuv422[] = {
185 static const enum AVPixelFormat overlay_pix_fmts_yuv444[] = {
307 s->overlay_is_packed_rgb =
319 "main w:%d h:%d fmt:%s overlay w:%d h:%d fmt:%s\n",
345 #define FAST_DIV255(x) ((((x) + 128) * 257) >> 16)
351 #define UNPREMULTIPLY_ALPHA(x, y) ((((x) << 16) - ((x) << 9) + (x)) / ((((x) + (y)) << 8) - ((x) + (y)) - (y) * (x)))
359 int main_has_alpha,
int x,
int y,
360 int is_straight,
int jobnr,
int nb_jobs)
363 int i, imax, j, jmax;
364 const int src_w =
src->width;
365 const int src_h =
src->height;
366 const int dst_w = dst->
width;
367 const int dst_h = dst->
height;
369 const int dr =
s->main_rgba_map[
R];
370 const int dg =
s->main_rgba_map[
G];
371 const int db =
s->main_rgba_map[
B];
372 const int da =
s->main_rgba_map[
A];
373 const int dstep =
s->main_pix_step[0];
374 const int sr =
s->overlay_rgba_map[
R];
375 const int sg =
s->overlay_rgba_map[
G];
376 const int sb =
s->overlay_rgba_map[
B];
377 const int sa =
s->overlay_rgba_map[
A];
378 const int sstep =
s->overlay_pix_step[0];
383 imax =
FFMIN3(-y + dst_h,
FFMIN(src_h, dst_h), y + src_h);
385 slice_start =
i + (imax * jobnr) / nb_jobs;
388 sp =
src->data[0] + (slice_start) *
src->linesize[0];
389 dp = dst->
data[0] + (y + slice_start) * dst->
linesize[0];
394 d = dp + (x+j) * dstep;
396 for (jmax =
FFMIN(-x + dst_w, src_w); j < jmax; j++) {
401 if (main_has_alpha &&
alpha != 0 &&
alpha != 255) {
424 if (main_has_alpha) {
440 sp +=
src->linesize[0];
446 int src_w,
int src_h,
447 int dst_w,
int dst_h,
448 int i,
int hsub,
int vsub,
467 int jmax, j, k, kmax;
471 jmax =
FFMIN3(-yp + dst_hp,
FFMIN(src_hp, dst_hp), yp + src_hp);
473 slice_start = j + (jmax * jobnr) / nb_jobs;
474 slice_end = j + (jmax * (jobnr+1)) / nb_jobs;
476 sp =
src->data[
i] + (slice_start) *
src->linesize[
i];
477 dp = dst->
data[dst_plane]
478 + (yp + slice_start) * dst->
linesize[dst_plane]
480 ap =
src->data[3] + (slice_start << vsub) *
src->linesize[3];
481 dap = dst->
data[3] + ((yp + slice_start) << vsub) * dst->
linesize[3];
485 d = dp + (xp+k) * dst_step;
488 da = dap + ((xp+k) << hsub);
489 kmax =
FFMIN(-xp + dst_wp, src_wp);
491 if (((vsub && j+1 < src_hp) || !vsub) && octx->
blend_row[
i]) {
496 da += (1 << hsub) *
c;
497 a += (1 << hsub) *
c;
500 for (; k < kmax; k++) {
501 int alpha_v, alpha_h,
alpha;
504 if (hsub && vsub && j+1 < src_hp && k+1 < src_wp) {
506 a[1] +
a[
src->linesize[3]+1]) >> 2;
507 }
else if (hsub || vsub) {
508 alpha_h = hsub && k+1 < src_wp ?
509 (
a[0] +
a[1]) >> 1 :
a[0];
510 alpha_v = vsub && j+1 < src_hp ?
511 (
a[0] +
a[
src->linesize[3]]) >> 1 :
a[0];
512 alpha = (alpha_v + alpha_h) >> 1;
517 if (main_has_alpha &&
alpha != 0 &&
alpha != 255) {
520 if (hsub && vsub && j+1 < src_hp && k+1 < src_wp) {
521 alpha_d = (da[0] + da[dst->
linesize[3]] +
522 da[1] + da[dst->
linesize[3]+1]) >> 2;
523 }
else if (hsub || vsub) {
524 alpha_h = hsub && k+1 < src_wp ?
525 (da[0] + da[1]) >> 1 : da[0];
526 alpha_v = vsub && j+1 < src_hp ?
527 (da[0] + da[dst->
linesize[3]]) >> 1 : da[0];
528 alpha_d = (alpha_v + alpha_h) >> 1;
537 *d = av_clip(
FAST_DIV255((*d - 128) * (255 -
alpha)) + *
s - 128, -128, 128) + 128;
548 ap += (1 << vsub) *
src->linesize[3];
549 dap += (1 << vsub) * dst->
linesize[3];
554 int src_w,
int src_h,
555 int dst_w,
int dst_h,
557 int jobnr,
int nb_jobs)
561 int i, imax, j, jmax;
564 imax =
FFMIN(-y + dst_h, src_h);
565 slice_start = (imax * jobnr) / nb_jobs;
566 slice_end = ((imax * (jobnr+1)) / nb_jobs);
569 sa =
src->data[3] + (
i + slice_start) *
src->linesize[3];
570 da = dst->
data[3] + (y +
i + slice_start) * dst->
linesize[3];
577 for (jmax =
FFMIN(-x + dst_w, src_w); j < jmax; j++) {
597 sa +=
src->linesize[3];
607 int jobnr,
int nb_jobs)
610 const int src_w =
src->width;
611 const int src_h =
src->height;
612 const int dst_w = dst->
width;
613 const int dst_h = dst->
height;
615 blend_plane(
ctx, dst,
src, src_w, src_h, dst_w, dst_h, 0, 0, 0, x, y, main_has_alpha,
616 s->main_desc->comp[0].plane,
s->main_desc->comp[0].offset,
s->main_desc->comp[0].step, is_straight, 1,
618 blend_plane(
ctx, dst,
src, src_w, src_h, dst_w, dst_h, 1, hsub, vsub, x, y, main_has_alpha,
619 s->main_desc->comp[1].plane,
s->main_desc->comp[1].offset,
s->main_desc->comp[1].step, is_straight, 1,
621 blend_plane(
ctx, dst,
src, src_w, src_h, dst_w, dst_h, 2, hsub, vsub, x, y, main_has_alpha,
622 s->main_desc->comp[2].plane,
s->main_desc->comp[2].offset,
s->main_desc->comp[2].step, is_straight, 1,
639 const int src_w =
src->width;
640 const int src_h =
src->height;
641 const int dst_w = dst->
width;
642 const int dst_h = dst->
height;
644 blend_plane(
ctx, dst,
src, src_w, src_h, dst_w, dst_h, 0, 0, 0, x, y, main_has_alpha,
645 s->main_desc->comp[1].plane,
s->main_desc->comp[1].offset,
s->main_desc->comp[1].step, is_straight, 0,
647 blend_plane(
ctx, dst,
src, src_w, src_h, dst_w, dst_h, 1, hsub, vsub, x, y, main_has_alpha,
648 s->main_desc->comp[2].plane,
s->main_desc->comp[2].offset,
s->main_desc->comp[2].step, is_straight, 0,
650 blend_plane(
ctx, dst,
src, src_w, src_h, dst_w, dst_h, 2, hsub, vsub, x, y, main_has_alpha,
651 s->main_desc->comp[0].plane,
s->main_desc->comp[0].offset,
s->main_desc->comp[0].step, is_straight, 0,
662 blend_slice_yuv(
ctx,
td->dst,
td->src, 1, 1, 0,
s->x,
s->y, 1, jobnr, nb_jobs);
670 blend_slice_yuv(
ctx,
td->dst,
td->src, 1, 1, 1,
s->x,
s->y, 1, jobnr, nb_jobs);
678 blend_slice_yuv(
ctx,
td->dst,
td->src, 1, 0, 0,
s->x,
s->y, 1, jobnr, nb_jobs);
686 blend_slice_yuv(
ctx,
td->dst,
td->src, 1, 0, 1,
s->x,
s->y, 1, jobnr, nb_jobs);
694 blend_slice_yuv(
ctx,
td->dst,
td->src, 0, 0, 0,
s->x,
s->y, 1, jobnr, nb_jobs);
702 blend_slice_yuv(
ctx,
td->dst,
td->src, 0, 0, 1,
s->x,
s->y, 1, jobnr, nb_jobs);
710 blend_slice_planar_rgb(
ctx,
td->dst,
td->src, 0, 0, 0,
s->x,
s->y, 1, jobnr, nb_jobs);
718 blend_slice_planar_rgb(
ctx,
td->dst,
td->src, 0, 0, 1,
s->x,
s->y, 1, jobnr, nb_jobs);
726 blend_slice_yuv(
ctx,
td->dst,
td->src, 1, 1, 0,
s->x,
s->y, 0, jobnr, nb_jobs);
734 blend_slice_yuv(
ctx,
td->dst,
td->src, 1, 1, 1,
s->x,
s->y, 0, jobnr, nb_jobs);
742 blend_slice_yuv(
ctx,
td->dst,
td->src, 1, 0, 0,
s->x,
s->y, 0, jobnr, nb_jobs);
750 blend_slice_yuv(
ctx,
td->dst,
td->src, 1, 0, 1,
s->x,
s->y, 0, jobnr, nb_jobs);
758 blend_slice_yuv(
ctx,
td->dst,
td->src, 0, 0, 0,
s->x,
s->y, 0, jobnr, nb_jobs);
766 blend_slice_yuv(
ctx,
td->dst,
td->src, 0, 0, 1,
s->x,
s->y, 0, jobnr, nb_jobs);
774 blend_slice_planar_rgb(
ctx,
td->dst,
td->src, 0, 0, 0,
s->x,
s->y, 0, jobnr, nb_jobs);
782 blend_slice_planar_rgb(
ctx,
td->dst,
td->src, 0, 0, 1,
s->x,
s->y, 0, jobnr, nb_jobs);
828 s->main_desc = pix_desc;
830 s->main_is_packed_rgb =
876 if (!
s->alpha_format)
925 s->alpha_format,
s->main_has_alpha);
945 int64_t pos = mainpic->
pkt_pos;
964 if (
s->x < mainpic->
width &&
s->x + second->
width >= 0 &&
990 #define OFFSET(x) offsetof(OverlayContext, x)
991 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
996 {
"eof_action",
"Action to take when encountering EOF from secondary input ",
1005 {
"shortest",
"force termination when the shortest input terminates",
OFFSET(
fs.opt_shortest),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
FLAGS },
1048 .preinit = overlay_framesync_preinit,
1052 .priv_class = &overlay_class,
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
AVPixelFormat
Pixel format.
static av_always_inline void blend_slice_packed_rgb(AVFilterContext *ctx, AVFrame *dst, const AVFrame *src, int main_has_alpha, int x, int y, int is_straight, int jobnr, int nb_jobs)
Blend image in src to destination buffer dst at position (x, y).
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 int blend_slice_rgb(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int set_expr(AVExpr **pexpr, const char *expr, const char *option, void *log_ctx)
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
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 int blend_slice_yuv422(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static const AVFilterPad avfilter_vf_overlay_outputs[]
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
static av_cold int end(AVCodecContext *avctx)
static int blend_slice_yuva422_pm(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static int do_blend(FFFrameSync *fs)
#define AV_LOG_VERBOSE
Detailed information.
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
static int blend_slice_yuv420(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
const char * name
Filter name.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
A link between two filters.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static int blend_slice_gbrap(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
static const char *const var_names[]
static int blend_slice_gbrp_pm(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
A filter pad used for either input or output.
void ff_overlay_init_x86(OverlayContext *s, int format, int pix_format, int alpha_format, int main_has_alpha)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int config_input_main(AVFilterLink *inlink)
static int query_formats(AVFilterContext *ctx)
static int blend_slice_rgb_pm(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
#define AV_CEIL_RSHIFT(a, 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 format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
int64_t pkt_pos
reordered pos from the last AVPacket that has been input into the decoder
static av_always_inline void blend_slice_yuv(AVFilterContext *ctx, AVFrame *dst, const AVFrame *src, int hsub, int vsub, int main_has_alpha, int x, int y, int is_straight, int jobnr, int nb_jobs)
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static const AVFilterPad outputs[]
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
#define UNPREMULTIPLY_ALPHA(x, y)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static void eval_expr(AVFilterContext *ctx)
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
static int config_input_overlay(AVFilterLink *inlink)
#define fs(width, name, subs,...)
static int blend_slice_yuva444_pm(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static av_cold void uninit(AVFilterContext *ctx)
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
static int blend_slice_yuv420_pm(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
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...
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static const AVFilterPad avfilter_vf_overlay_inputs[]
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
static const AVOption overlay_options[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int ff_framesync_init_dualinput(FFFrameSync *fs, AVFilterContext *parent)
Initialize a frame sync structure for dualinput.
#define AV_NOPTS_VALUE
Undefined timestamp value.
AVFilterContext * src
source filter
static int config_output(AVFilterLink *outlink)
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
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
static int blend_slice_rgba(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int blend_slice_yuva420_pm(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
static int blend_slice_gbrap_pm(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int blend_slice_yuva444(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int blend_slice_rgba_pm(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define i(width, name, range_min, range_max)
static av_always_inline void blend_slice_planar_rgb(AVFilterContext *ctx, AVFrame *dst, const AVFrame *src, int hsub, int vsub, int main_has_alpha, int x, int y, int is_straight, int jobnr, int nb_jobs)
int w
agreed upon image width
static av_always_inline void blend_plane(AVFilterContext *ctx, AVFrame *dst, const AVFrame *src, int src_w, int src_h, int dst_w, int dst_h, int i, int hsub, int vsub, int x, int y, int main_has_alpha, int dst_plane, int dst_offset, int dst_step, int straight, int yuv, int jobnr, int nb_jobs)
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Used for passing data between threads.
const char AVS_Value args
@ AV_PIX_FMT_NV21
as above, but U and V bytes are swapped
const char * name
Pad name.
static int blend_slice_gbrp(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int normalize_xy(double d, int chroma_sub)
static int blend_slice_yuv444(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
static int blend_slice_yuva422(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int h
agreed upon image height
int(* blend_row[4])(uint8_t *d, uint8_t *da, uint8_t *s, uint8_t *a, int w, ptrdiff_t alinesize)
static int activate(AVFilterContext *ctx)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], const AVPixFmtDescriptor *pixdesc)
Compute the max pixel step for each plane of an image with a format described by pixdesc.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static int blend_slice_yuv444_pm(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
FRAMESYNC_DEFINE_CLASS(overlay, OverlayContext, fs)
static const int16_t alpha[]
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
#define flags(name, subs,...)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
int ff_framesync_dualinput_get_writable(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
Same as ff_framesync_dualinput_get(), but make sure that f0 is writable.
static enum AVPixelFormat alpha_pix_fmts[]
static void alpha_composite(const AVFrame *src, const AVFrame *dst, int src_w, int src_h, int dst_w, int dst_h, int x, int y, int jobnr, int nb_jobs)
static int blend_slice_yuva420(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
static int blend_slice_yuv422_pm(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static av_cold int init(AVFilterContext *ctx)