Crop Video in FFmpeg with Custom Dimensions
This guide explains how to use the FFmpeg crop video
filter to trim the width and height of a video to your exact
specifications. You will learn the basic command syntax, how the
coordinate system works, and see practical examples for cropping videos
from specific positions or centering the crop area.
To crop a video in FFmpeg, you use the video filter flag
(-vf) followed by the crop filter. The basic
syntax is:
ffmpeg -i input.mp4 -vf "crop=w:h:x:y" output.mp4Understanding the Parameters
The crop filter accepts four primary arguments separated
by colons:
w(width): The width of the output (cropped) video.h(height): The height of the output (cropped) video.x(X-coordinate): The horizontal position of the left edge of the crop area, relative to the top-left corner of the input video. The default is the center of the input frame.y(Y-coordinate): The vertical position of the top edge of the crop area, relative to the top-left corner of the input video. The default is the center of the input frame.
Practical Examples
1. Crop to Specific Dimensions from a Custom Position
To crop a video to a width of 800 pixels and a height of 600 pixels,
starting 100 pixels from the left edge (x=100) and 150
pixels from the top edge (y=150):
ffmpeg -i input.mp4 -vf "crop=800:600:100:150" -c:a copy output.mp4(Note: -c:a copy is added to copy the audio stream
without re-encoding, which saves processing time.)
2. Crop to the Center of the Video
If you want to crop a video to a specific size (e.g., 640x480) but
want it perfectly centered, you can omit the x and
y parameters. FFmpeg automatically centers the crop area by
default:
ffmpeg -i input.mp4 -vf "crop=640:480" -c:a copy output.mp4Alternatively, you can write this out explicitly using FFmpeg’s
built-in variables in_w (input width) and in_h
(input height):
ffmpeg -i input.mp4 -vf "crop=640:480:(in_w-640)/2:(in_h-480)/2" -c:a copy output.mp43. Crop a Video in Half (Left Side Only)
To keep only the left half of a video, you can use the input dimension variables directly in your values:
ffmpeg -i input.mp4 -vf "crop=in_w/2:in_h:0:0" -c:a copy output.mp4This sets the output width to half of the input width
(in_w/2), keeps the full height (in_h), and
starts the crop from the top-left corner (0:0).