FFmpeg Crop Video to Bottom Right Corner
This article provides a straightforward guide on how to crop a video
to its bottom-right corner using FFmpeg’s built-in crop
filter and variable names. You will learn the exact command syntax, how
the coordinate variables work, and how to apply this to any video
resolution.
To crop a video in FFmpeg, you use the crop filter,
which follows this basic syntax:
crop=out_w:out_h:x:y
out_w: The width of the output (cropped) video.out_h: The height of the output (cropped) video.x: The horizontal position of the left edge of the crop area.y: The vertical position of the top edge of the crop area.
Using Variables for the Bottom-Right Corner
FFmpeg provides shorthand variable names that allow you to calculate the bottom-right position dynamically, without needing to know the input video’s exact dimensions beforehand:
iw(orin_w): Input width.ih(orin_h): Input height.ow(orout_w): Output width.oh(orout_h): Output height.
To target the bottom-right corner, your starting coordinates
(x and y) must shift all the way to the right
and bottom edges. You calculate this by subtracting the output
dimensions from the input dimensions:
xcoordinate:iw - ow(Input Width minus Output Width)ycoordinate:ih - oh(Input Height minus Output Height)
The FFmpeg Command
To crop a video to a specific size (for example, a width of
640 pixels and a height of 480 pixels) at the
bottom-right corner, run the following command:
ffmpeg -i input.mp4 -vf "crop=640:480:iw-ow:ih-oh" output.mp4How It Works
640:480: Defines the size of your cropped output window. This setsowto 640 andohto 480.iw-ow: Calculates the starting horizontal coordinate. By subtracting 640 from the total input width, the crop box is pushed to the far right edge.ih-oh: Calculates the starting vertical coordinate. By subtracting 480 from the total input height, the crop box is pushed to the very bottom edge.
This formula dynamically scales to any input video resolution, ensuring the cropped area always aligns perfectly with the bottom-right corner of your source file.