68 int max_plane_step[4];
71 char x_expr[256], y_expr[256];
85 sscanf(args,
"%255[^:]:%255[^:]", over->
x_expr, over->
y_expr);
137 var_values[
VAR_PI ] = M_PI;
159 "main w:%d h:%d fmt:%s overlay x:%d y:%d w:%d h:%d fmt:%s\n",
166 if (over->
x < 0 || over->
y < 0 ||
170 "Overlay area (%d,%d)<->(%d,%d) not within the main area (0,0)<->(%d,%d) or zero-sized\n",
174 (
int)var_values[
VAR_MAIN_W], (
int)var_values[VAR_MAIN_H]);
181 "Error when evaluating the expression '%s'\n", expr);
203 int overlay_end_y = y + src->
video->
h;
208 start_y =
FFMAX(y, 0);
209 height = end_y - start_y;
218 for (i = 0; i <
height; i++) {
220 for (j = 0; j <
width; j++) {
221 d[
r] = (d[
r] * (0xff - s[3]) + s[0] * s[3] + 128) >> 8;
222 d[1] = (d[1] * (0xff - s[3]) + s[1] * s[3] + 128) >> 8;
223 d[
b] = (d[
b] * (0xff - s[3]) + s[2] * s[3] + 128) >> 8;
231 for (i = 0; i < 3; i++) {
232 int hsub = i ? over->
hsub : 0;
233 int vsub = i ? over->
vsub : 0;
235 (start_y >> vsub) * dst->
linesize[i];
238 int wp =
FFALIGN(width, 1<<hsub) >> hsub;
239 int hp =
FFALIGN(height, 1<<vsub) >> vsub;
241 sp += ((-y) >> vsub) * src->
linesize[i];
244 for (j = 0; j < hp; j++) {
246 for (k = 0; k < wp; k++) {
248 int alpha_v, alpha_h, alpha;
249 if (hsub && vsub && j+1 < hp && k+1 < wp) {
250 alpha = (a[0] + a[src->
linesize[3]] +
252 }
else if (hsub || vsub) {
253 alpha_h = hsub && k+1 < wp ?
254 (a[0] + a[1]) >> 1 : a[0];
255 alpha_v = vsub && j+1 < hp ?
256 (a[0] + a[src->
linesize[3]]) >> 1 : a[0];
257 alpha = (alpha_v + alpha_h) >> 1;
260 *d = (*d * (0xff - alpha) + *s++ * alpha + 128) >> 8;
266 ap += (1 << vsub) * src->
linesize[3];
404 .
inputs = avfilter_vf_overlay_inputs,
405 .
outputs = avfilter_vf_overlay_outputs,
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
static int request_frame(AVFilterLink *outlink)
AVFilterBufferRefVideoProps * video
video buffer specific properties
int linesize[8]
number of bytes per line
static int filter_frame_main(AVFilterLink *inlink, AVFilterBufferRef *frame)
static const AVFilterPad outputs[]
packed RGB 8:8:8, 24bpp, RGBRGB...
int h
agreed upon image height
int ff_filter_frame(AVFilterLink *link, AVFilterBufferRef *frame)
Send a frame of data to the next filter.
static int handle_overlay_eof(AVFilterContext *ctx)
static const AVFilterPad avfilter_vf_overlay_inputs[]
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
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.
#define AV_PERM_READ
can read from the buffer
const char * name
Pad name.
AVFilterLink ** inputs
array of pointers to input links
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define FFSWAP(type, a, b)
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
static const char *const var_names[]
AVFilterBufferRef * over_prev
void avfilter_unref_bufferp(AVFilterBufferRef **ref)
Remove a reference to a buffer and set the pointer to NULL.
int64_t pts
presentation timestamp.
A filter pad used for either input or output.
A link between two filters.
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
static int config_input_overlay(AVFilterLink *inlink)
simple assert() macros that are a bit more flexible than ISO C assert().
void av_log(void *avcl, int level, const char *fmt,...)
AVFilterFormats * in_formats
Lists of formats supported by the input and output filters respectively.
AVFilterBufferRef * over_next
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare 2 timestamps each in its own timebases.
int w
agreed upon image width
static int output_frame(AVFilterContext *ctx)
AVFilter avfilter_vf_overlay
static const AVFilterPad avfilter_vf_overlay_outputs[]
static av_cold int init(AVFilterContext *ctx, const char *args)
packed RGB 8:8:8, 24bpp, BGRBGR...
AVFilterContext * src
source filter
int format
agreed upon media format
A reference to an AVFilterBuffer.
static av_cold void uninit(AVFilterContext *ctx)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
int max_plane_step[4]
steps per pixel for each plane
int y
position of overlayed picture
static const AVFilterPad inputs[]
rational number numerator/denominator
const char * name
filter name
static int query_formats(AVFilterContext *ctx)
AVFilterLink ** outputs
array of pointers to output links
#define AV_PERM_PRESERVE
nobody else can overwrite the buffer
static int config_input_main(AVFilterLink *inlink)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal and external API header
int vsub
chroma subsampling values
#define AV_PERM_REUSE2
can output the buffer multiple times, modified each time
static void blend_frame(AVFilterContext *ctx, AVFilterBufferRef *dst, AVFilterBufferRef *src, int x, int y)
AVFilterContext * dst
dest filter
static int config_output(AVFilterLink *outlink)
uint8_t * data[8]
picture/audio data for each plane
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
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 filter_frame_overlay(AVFilterLink *inlink, AVFilterBufferRef *frame)
AVPixelFormat
Pixel format.
AVFilterFormats * out_formats
simple arithmetic expression evaluator