Last updated: February 5, 2025

<span aria-hidden="true" id="how-to-crop-images-and-videos-with-ffmpeg"></span>

# How to crop images and videos with FFmpeg

![Kevin van Zonneveld](/assets/images/teammates/avatar-kvz-4.jpg?dpl=dpl_B2d4XACVUtA1h8m6kRxZhWsda77Q)

#### Kevin van Zonneveld

Co-founder · Amsterdam, The Netherlands · Show bio

[](https://x.com/kvz)[](https://github.com/kvz)

FFmpeg is a robust command-line utility that makes cropping images and videos both simple and efficient. In this guide, we demonstrate practical techniques to crop media files directly from the terminal—streamlining your development workflow.

<span aria-hidden="true" id="introduction-to-ffmpeg-for-image-and-video-cropping"></span>

## Introduction to FFmpeg for image and video cropping

FFmpeg is a versatile tool used to process audio, video, and image files. In addition to converting formats and encoding streams, FFmpeg can crop media precisely. This capability is especially useful when you need to focus on a particular region of an image or video, whether for web applications, content editing, or automation tasks.

<span aria-hidden="true" id="installing-ffmpeg-on-your-system"></span>

## Installing FFmpeg on your system

Before diving into cropping, ensure FFmpeg is installed on your system.

<span aria-hidden="true" id="installing-on-macos"></span>

### Installing on macOS

Install FFmpeg using [Homebrew⁠](https://brew.sh/):

```bash
brew install ffmpeg

```

<span aria-hidden="true" id="installing-on-linux"></span>

### Installing on Linux

For Debian-based systems:

```bash
sudo apt update
sudo apt install ffmpeg

```

For Red Hat-based systems:

```bash
sudo dnf install ffmpeg

```

<span aria-hidden="true" id="installing-on-windows"></span>

### Installing on Windows

Download the latest build from the [official FFmpeg website⁠](https://ffmpeg.org/download.html). Extract the binaries and add the FFmpeg `bin` directory to your system’s PATH environment variable.

<span aria-hidden="true" id="basic-concepts-of-cropping-in-ffmpeg"></span>

## Basic concepts of cropping in FFmpeg

Cropping is achieved using FFmpeg’s `crop` filter, which requires four parameters:

* `width` (`out_w`): The width of the output media.
* `height` (`out_h`): The height of the output media.
* `x`: The x-coordinate of the top-left corner where cropping begins.
* `y`: The y-coordinate of the top-left corner where cropping begins.

The general syntax is:

```bash
ffmpeg -i input -vf "crop=out_w:out_h:x:y" output

```

<span aria-hidden="true" id="cropping-images-with-ffmpeg"></span>

## Cropping images with FFmpeg

Although FFmpeg is widely known for video processing, it handles images with equal proficiency. Here is an example to crop an image.

<span aria-hidden="true" id="example-cropping-an-image"></span>

### Example: cropping an image

To crop a 200x200 pixel region starting from coordinates (50,50) in `input.jpg`:

```bash
ffmpeg -i input.jpg -vf "crop=200:200:50:50" output.jpg

```

<span aria-hidden="true" id="explanation"></span>

### Explanation

* `-i input.jpg` specifies the input file.
* `-vf "crop=200:200:50:50"` applies the crop filter with the defined dimensions and offsets.
* `output.jpg` is the resulting cropped image.

<span aria-hidden="true" id="cropping-videos-with-ffmpeg"></span>

## Cropping videos with FFmpeg

Cropping videos operates similarly to images, applying the crop filter to every frame in the video.

<span aria-hidden="true" id="example-cropping-a-video"></span>

### Example: cropping a video

To crop a 1280x720 region starting from the top-left corner of `input.mp4`:

```bash
ffmpeg -i input.mp4 -vf "crop=1280:720:0:0" output.mp4

```

<span aria-hidden="true" id="explanation-1"></span>

### Explanation

* `-i input.mp4` specifies the input video.
* `-vf "crop=1280:720:0:0"` crops the video to 1280x720 pixels from the top-left corner.
* `output.mp4` is the output file.

<span aria-hidden="true" id="dynamic-cropping-based-on-input-dimensions"></span>

### Dynamic cropping based on input dimensions

For more flexibility, you can use expressions to automatically crop relative to the input video dimensions. For instance, to crop the central square of a video:

```bash
ffmpeg -i input.mp4 -vf "crop='min(in_w\,in_h)':'min(in_w\,in_h)':(in_w-min(in_w\,in_h))/2:(in_h-min(in_w\,in_h))/2" output.mp4

```

* `in_w` and `in_h` represent the input width and height.
* The function `min(in_w\,in_h)` selects the smaller dimension, ensuring a square crop.
* The expressions center the crop horizontally and vertically.

<span aria-hidden="true" id="command-line-options-for-cropping-in-ffmpeg"></span>

## Command line options for cropping in FFmpeg

The essential cropping command is:

```bash
ffmpeg -i input -vf "crop=out_w:out_h:x:y" output

```

You can also specify named parameters for clarity:

```bash
ffmpeg -i input.mp4 -vf "crop=w=1280:h=720:x=0:y=0" output.mp4

```

Both approaches yield the same result.

<span aria-hidden="true" id="automating-cropping-tasks-with-scripts"></span>

## Automating cropping tasks with scripts

Automating repetitive cropping tasks can save valuable time. You can write shell scripts or batch files to apply consistent crop settings to multiple files.

<span aria-hidden="true" id="batch-cropping-images-with-a-bash-script"></span>

### Batch cropping images with a bash script

The following script processes all `.jpg` files in a directory:

```bash
#!/bin/bash
for img in *.jpg; do
  ffmpeg -i "$img" -vf "crop=200:200:50:50" "cropped_$img"
done

```

<span aria-hidden="true" id="batch-cropping-images-with-a-batch-script-windows"></span>

### Batch cropping images with a batch script (Windows)

```batch
for %%i in (*.jpg) do ffmpeg -i "%%i" -vf "crop=200:200:50:50" "cropped_%%i"

```

<span aria-hidden="true" id="using-python-to-automate-cropping"></span>

### Using Python to automate cropping

You can also call FFmpeg from Python:

```python
import subprocess
import glob

for img in glob.glob("*.jpg"):
    subprocess.call([
        "ffmpeg",
        "-i", img,
        "-vf", "crop=200:200:50:50",
        f"cropped_{img}"
    ])

```

<span aria-hidden="true" id="why-use-ffmpeg-for-cropping"></span>

## Why use FFmpeg for cropping?

FFmpeg is a reliable choice for media cropping due to several reasons:

* Automation: Easily scriptable for batch processing.
* Versatility: Supports a wide range of input and output formats.
* Efficiency: Processes media quickly and integrates smoothly into automated workflows.
* Headless Operation: Ideal for server environments without a graphical interface.

<span aria-hidden="true" id="conclusion-and-further-resources"></span>

## Conclusion and further resources

Cropping images and videos with FFmpeg is straightforward once you understand the parameters and syntax. Whether you are tackling a one-time project or automating recurring tasks, FFmpeg provides robust tools to enhance your media processing pipeline.

For more detailed information, visit the[FFmpeg documentation⁠](https://ffmpeg.org/ffmpeg-filters.html#crop).

If you are looking for a scalable solution to automate media processing tasks, including image and video cropping, consider exploring the [Transloadit API](/index.md).

\#image-cropping#ffmpeg-image-cropping#ffmpeg-crop-image#ffmpeg-crop-video#command-line-image-cropping#automate-image-cropping#media-processing#image-processing-service#video-encoding-service

### 👩‍💻 Join 20k+ developers

Sign up for our [monthly newsletter](/newsletters.md) to receive direct links to 3 exclusive tech — and 2 product updates. No less, no more.

Your email:

Get access

## File uploading and encoding. Made simple.

Transloadit streamlines file handling for developers, trusted by brands like Coursera and The New York Times. We’re known for a reliable API, top-notch support, and a strong commitment to open source, with projects like [Uppy⁠](https://uppy.io) and [Tus⁠](https://tus.io) setting standards in file processing.

[Sign up](/c/)[Book a Demo](https://survey.typeform.com/to/kRg47Xi5)

No credit card needed · 5 GB included in the free plan

Cancel anytime
