| ffm_overlay | R Documentation |
Draw the second input (the overlay) on top of the first input (the main
video) at position x and y. Like ffm_hstack, this
is a pipeline function for several inputs. It forces the
-filter_complex path and manages its own stream labels internally. It
needs exactly two inputs. The first is the background, and the second is
drawn over it. The glossary in vignette("tidymedia") explains media
terms such as stream.
ffm_overlay(object, x = 0, y = 0, shortest = FALSE, scale = NULL)
object |
An FFmpeg pipeline ( |
x |
The horizontal position of the overlay's left edge, as a number of
pixels or an FFmpeg expression. The default is |
y |
The vertical position of the overlay's top edge, as a number of
pixels or an FFmpeg expression. The default is |
shortest |
A logical that says whether to end the output when the
shorter input ends. The default is |
scale |
An optional fraction ( |
x and y accept plain numbers or FFmpeg overlay expressions. A
plain number counts pixels from the top-left of the main video. In an
expression, main_w and main_h are the main video's dimensions.
overlay_w and overlay_h are the overlay's dimensions. For
example, x = "main_w-overlay_w-16" puts the overlay 16 pixels from the
right edge.
When scale is set, the overlay is first resized to a fraction of the
main video's width, and its aspect ratio is kept. The task function
picture_in_picture uses this resize. Otherwise, to resize the
overlay yourself, filter it in a separate pipeline first.
object with an added instruction to draw the second input on
the first.
picture_in_picture(), the task function built on this function.
Other pipeline functions:
ffm_batch(),
ffm_codec(),
ffm_compile(),
ffm_concat(),
ffm_copy(),
ffm_crop(),
ffm_drawbox(),
ffm_drop(),
ffm_files(),
ffm_fps(),
ffm_hstack(),
ffm_jobs(),
ffm_loudnorm(),
ffm_map(),
ffm_output_options(),
ffm_pixel_format(),
ffm_run(),
ffm_scale(),
ffm_seek(),
ffm_trim(),
ffm_vstack(),
print.tidymedia_ffm()
video <- system.file("extdata", "sample.mp4", package = "tidymedia")
# Draw the second input over the first, 16px in from the top-right corner
ffm_files(c(video, video), "output.mp4") |>
ffm_overlay(x = "main_w-overlay_w-16", y = 16) |>
ffm_compile()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.