overlay

Overlay one video on top of another.

It takes two inputs and has one output. The first input is the "main" video on which the second input is overlaid.

It accepts the following parameters:

A description of the accepted options follows.

x
y

Set the expression for the x and y coordinates of the overlaid video on the main video. Default value is "0" for both expressions. In case the expression is invalid, it is set to a huge value (meaning that the overlay will not be displayed within the output visible area).

eof_action

See framesync.

eval

Set when the expressions for x, and y are evaluated.

It accepts the following values:

init

only evaluate expressions once during the filter initialization or when a command is processed

frame

evaluate expressions for each incoming frame

Default value is ‘frame’.

shortest

See framesync.

format

Set the format for the output video.

It accepts the following values:

yuv420

force YUV 4:2:0 8-bit planar output

yuv420p10

force YUV 4:2:0 10-bit planar output

yuv422

force YUV 4:2:2 8-bit planar output

yuv422p10

force YUV 4:2:2 10-bit planar output

yuv444

force YUV 4:4:4 8-bit planar output

yuv444p10

force YUV 4:4:4 10-bit planar output

rgb

force RGB 8-bit packed output

gbrp

force RGB 8-bit planar output

auto

automatically pick format

Default value is ‘yuv420’.

repeatlast

See framesync.

alpha

Set format of alpha of the overlaid video, it can be straight or premultiplied. Default is straight.

The x, and y expressions can contain the following parameters.

main_w, W
main_h, H

The main input width and height.

overlay_w, w
overlay_h, h

The overlay input width and height.

x
y

The computed values for x and y. They are evaluated for each new frame.

hsub
vsub

horizontal and vertical chroma subsample values of the output format. For example for the pixel format "yuv422p" hsub is 2 and vsub is 1.

n

the number of input frame, starting from 0

pos

the position in the file of the input frame, NAN if unknown; deprecated, do not use

t

The timestamp, expressed in seconds. It’s NAN if the input timestamp is unknown.

This filter also supports the framesync options.

Note that the n, t variables are available only when evaluation is done per frame, and will evaluate to NAN when eval is set to ‘init’.

Be aware that frames are taken from each input video in timestamp order, hence, if their initial timestamps differ, it is a good idea to pass the two inputs through a setpts=PTS-STARTPTS filter to have them begin in the same zero timestamp, as the example for the movie filter does.

You can chain together more overlays but you should test the efficiency of such approach.