How to Crop Video with a Bouncing Box in FFmpeg

This article explains how to use the FFmpeg crop filter to create a dynamic, bouncing crop box that moves across your video screen. You will learn the exact command-line syntax, how the mathematical expressions control the movement, and how to customize the speed and size of the cropping area.

To create a bouncing crop box in FFmpeg, you must utilize the crop filter with dynamic expressions for the x (horizontal) and y (vertical) coordinates. By using time-based trigonometric functions, you can keep the crop box within the video boundaries while animating it continuously.

The FFmpeg Command

Run the following command in your terminal to apply a bouncing 640x360 crop box to an input video:

ffmpeg -i input.mp4 -vf "crop=640:360:'(in_w-out_w)*(1+sin(1.5*t))/2':'(in_h-out_h)*(1+sin(2.3*t))/2'" -c:a copy output.mp4

How the Command Works

The crop filter uses the syntax crop=w:h:x:y. Here is the breakdown of how the motion is calculated:

When multiplied by the range of movement, the coordinates smoothly oscillate between 0 (the top/left edge) and the maximum safe boundary (the bottom/right edge).

Customizing the Animation

You can easily adjust the parameters to change the behavior of the crop box: