Skip to contents

Add a video filter that draws a colored rectangle on the input video.

Usage

ffm_drawbox(
  object,
  x = 0,
  y = 0,
  width = "in_w",
  height = "in_h",
  color = "black",
  thickness = "fill"
)

Arguments

object

An FFmpeg pipeline (ffm) object created by ffm_files().

x

The horizontal position of the left edge of the box, in pixels of the input video. Give a double of zero or more, or a string, such as an FFmpeg expression. The default is 0.

y

The vertical position of the top edge of the box, in pixels of the input video. Give a double of zero or more, or a string, such as an FFmpeg expression. The default is 0.

width

The width of the box, in pixels. Give a positive double or a string, such as an FFmpeg expression. The default is "in_w".

height

The height of the box, in pixels. Give a positive double or a string, such as an FFmpeg expression. The default is "in_h".

color

A string with the color of the box, in FFmpeg color syntax. The reference link below explains that syntax. With the special value "invert", the box has the color of the video with inverted luma. The default is "black".

thickness

The thickness of the box edge, in pixels. Give a positive double or a string. The value "fill" draws a filled box. The default is "fill".

Value

object with an added instruction to apply the drawbox filter.

Details

Each size and position argument, thickness included, takes one double (an R number such as 160) or one string. An integer such as 160L is refused, and so is NA. Any other string is not checked, and it goes into the FFmpeg command as written, so it can hold an FFmpeg expression.

References

https://ffmpeg.org/ffmpeg-filters.html#drawbox

https://ffmpeg.org/ffmpeg-utils.html#color-syntax

Examples

video <- system.file("extdata", "sample.mp4", package = "tidymedia")
# Draw a filled red box covering the top-left quarter of the frame
ffm_files(video, "output.mp4") |>
  ffm_drawbox(width = "in_w/2", height = "in_h/2", color = "red") |>
  ffm_compile()
#> [1] "-y -i \"/home/runner/work/_temp/Library/tidymedia/extdata/sample.mp4\" -vf \"drawbox=x=0:y=0:w=in_w/2:h=in_h/2:c=red:t=fill\" \"output.mp4\""