Skip to contents

Make the video's frames smaller by cropping them.

Usage

ffm_crop(object, width, height, x = "(in_w-out_w)/2", y = "(in_h-out_h)/2")

Arguments

object

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

width

The width of the output video, in pixels. Give a positive double or a string, such as an FFmpeg expression.

height

The height of the output video, in pixels. Give a positive double or a string, such as an FFmpeg expression.

x

The horizontal position of the left edge of the output video, in pixels of the input video. Give a double of zero or more, or a string, such as an FFmpeg expression. The default is "(in_w-out_w)/2".

y

The vertical position of the top edge of the output video, in pixels of the input video. Give a double of zero or more, or a string, such as an FFmpeg expression. The default is "(in_h-out_h)/2".

Value

object with an added instruction to crop the frames.

Details

Each size and position argument 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#crop

Examples

video <- system.file("extdata", "sample.mp4", package = "tidymedia")
# Crop to a centered 160x120 region
ffm_files(video, "output.mp4") |>
  ffm_crop(width = 160, height = 120) |>
  ffm_compile()
#> [1] "-y -i \"/home/runner/work/_temp/Library/tidymedia/extdata/sample.mp4\" -vf \"crop=w=160:h=120:x=(in_w-out_w)/2:y=(in_h-out_h)/2\" \"output.mp4\""