FFmpeg Crop Video Commands That Actually Work

August 31, 2026 · RenderIO

You've got a landscape recording, a vertical delivery target, and a batch of clips that refuse to share the same dimensions. The first command works on the sample file, then fails on a downloaded video with an odd frame size, clips the speaker on another source, or produces a frame that's technically vertical but visually unusable.

Reliable FFmpeg crop video work depends on more than remembering crop=w:h:x:y. You need a decision rule for crop versus pad, expressions that respect the input geometry, validation before encoding, and a preview step that catches bad coordinates before a batch job processes every file. The examples below cover the core filter, square and vertical reframing, defensive formulas, verification, and a practical route from a terminal command to an automated RenderIO pipeline.

Table of Contents

Where Cropping Fits in Your FFmpeg Workflow

Cropping is usually one operation inside a larger video filter chain. A common job starts with a 1920x1080 source and ends with a tighter square frame, a portrait composition, or a version with empty edges removed. The crop filter removes pixels. It doesn't resize the remaining image, rotate the frame, or repair an aspect-ratio mismatch by itself.

That distinction determines filter order. If you crop first and scale afterward, FFmpeg discards unwanted pixels before enlarging the retained composition. If you scale first, your crop coordinates refer to the scaled frame, which can be useful in some workflows but makes geometry harder to reason about. Filters in -vf and -filter_complex run in the order you write them, so crop,scale and scale,crop aren't interchangeable.

Crop, scale, pad, and rotate

Use crop when losing part of the frame is acceptable and the subject benefits from a tighter composition. Use pad when the entire original frame must remain visible inside a new canvas. Use scale to establish delivery dimensions, and use rotate when the source orientation itself needs correction.

A portrait social output often needs a choice rather than a universal command:

  • Crop first when the subject is centered or you can select a reliable anchor, and edge content is expendable.
  • Pad after scaling when preserving the full composition matters more than filling every portrait pixel.
  • Scale and crop when you need a fixed output size but the source dimensions vary.
  • Rotate before geometry decisions when metadata or capture orientation means the visible frame isn't represented by the raw width and height you expected.

For platform planning, PostSyncer's guide to optimizing video dimensions for social is useful context because the delivery canvas should be chosen before you calculate the crop rectangle.

Cropping also belongs before an encode or transcode. A video filter changes decoded pixels, so stream copying with -c:v copy can't preserve the requested crop. Audio is separate, which means the crop pass doesn't touch it. Copy or encode the audio explicitly according to the output requirements.

If you're reviewing the broader command structure before adding filters, this FFmpeg usage guide provides a useful command-line foundation. The important operational rule is simple: decide the target canvas, decide whether pixels may be discarded, then construct the filter chain in that order.

The Core Crop Filter Syntax and Its Parameters

The canonical form is:

crop=w:h:x:y

The first two values define the retained rectangle. w is the output width and h is the output height. x and y identify the top-left corner of that rectangle inside the input frame.

For a fixed crop, the command is direct:

ffmpeg -i input.mp4 -vf "crop=1080:1080:420:0" output.mp4

This keeps a square beginning at pixel x=420 and y=0. If you omit the position, FFmpeg uses centered defaults. The official FFmpeg crop filter documentation describes the filter as a mature frame-geometry tool with width, height, and position controls, and documents centered output geometry by default.

Use input-relative expressions

Hard-coded dimensions are fine when every source is known. Production inputs rarely stay that predictable, so use iw and ih for input width and height:

ffmpeg -i input.mp4 -vf "crop=iw/2:ih:0:0" output.mp4

That command retains the left half of the source. A tighter centered frame can use:

ffmpeg -i input.mp4 -vf "crop=iw*0.8:ih*0.8:(iw-iw*0.8)/2:(ih-ih*0.8)/2" output.mp4

The expression describes both the output rectangle and its location. It adapts to the source instead of requiring you to recalculate coordinates manually.

Think of crop as two questions:

  1. How large is the output rectangle?
  2. Where does its top-left corner land in the source?

That mental model prevents a frequent mistake, treating crop as a resize filter. It isn't. The crop filter only removes pixels. Pair it with a later scale filter when the retained rectangle must reach a delivery dimension.

Codec constraints also matter. Encoders such as libx264 commonly expect dimensions compatible with macroblock and pixel-format requirements, so calculated values should be normalized rather than trusted blindly. In particular, an expression can produce an odd width or height from an odd input. Use even-number logic in the defensive patterns below instead of assuming every source dimension is clean.

Real CLI Examples for Square Vertical and Offset Crops

The fastest way to understand crop geometry is to inspect commands that solve real framing problems. These examples assume the source dimensions are known and that the requested rectangle fits inside the source. Variable geometry needs additional guards.

Square output from a landscape source

For a 1920x1080 source, this creates a centered 1080x1080 square:

ffmpeg -i input.mp4 -vf "crop=1080:1080:420:0" -c:v libx264 -c:a copy output-square.mp4

The horizontal offset is 420, because the unused width is split between the left and right sides. The crop starts at the top edge, so y=0. This is a practical Instagram-style square when the important action sits near the horizontal center.

Portrait output for vertical platforms

If the source is tall enough to contain a 1080x1920 portrait rectangle, use an expression for horizontal centering:

ffmpeg -i input.mp4 -vf "crop=1080:1920:(in_w-1080)/2:0" -c:v libx264 -c:a copy output-vertical.mp4

The expression calculates the left offset from the actual input width. It keeps the top edge fixed, which is appropriate when the subject's vertical placement is already correct. For a wide source, this exact rectangle won't fit. That isn't a syntax problem. It's a decision problem, and the defensive section addresses it.

For more context on portrait framing, RenderIO's guide to 9:16 video is a useful reference when choosing the target canvas and deciding how much of the original frame can be sacrificed.

Removing a fixed edge area

To remove a 220-pixel strip from the left while retaining a 1700x1080 frame:

ffmpeg -i input.mp4 -vf "crop=1700:1080:220:0" -c:v libx264 -c:a copy output-clean.mp4

This works for a known source where the unwanted material occupies a predictable edge. It isn't a watermark-removal algorithm. It excludes the selected region, so verify that the crop doesn't remove a speaker, title, or other required content.

Tightening the frame proportionally

To retain 80% of the input width and height, centered:

ffmpeg -i input.mp4 -vf "crop=iw*0.8:ih*0.8:(iw-iw*0.8)/2:(ih-ih*0.8)/2" -c:v libx264 -c:a copy output-tight.mp4

This is useful for reducing dead space without committing to a platform-specific canvas. It also illustrates why expressions are valuable when source files come from different cameras or downloaders.

Use Case Source Resolution Crop Command Result
Square social frame 1920x1080 crop=1080:1080:420:0 Centered square
Portrait framing Known source with sufficient height crop=1080:1920:(in_w-1080)/2:0 Centered 1080x1920 rectangle
Remove left edge 1920x1080 crop=1700:1080:220:0 Narrower frame with left strip excluded
Tighten composition Variable crop=iw*0.8:ih*0.8:(iw-iw*0.8)/2:(ih-ih*0.8)/2 Centered proportional crop

These commands crop but don't guarantee the final delivery dimensions unless the crop already matches them. Add ,scale=1080:1920 or another target scale after a valid crop when the output canvas must be exact.

Defensive Crop Formulas That Survive Edge Cases

A static crop formula survives only when the input geometry matches its assumptions. In a batch, those assumptions fail because sources arrive with different orientations, odd dimensions, display metadata, or less available height and width than the requested rectangle requires.

The non-positive size error usually means an expression evaluated to zero or a negative value. A related “invalid too big” or “area outside picture” failure means the rectangle extends beyond the decoded frame. The FFmpeg crop edge-case discussion on Stack Overflow demonstrates why a portrait formula needs a boundary decision before FFmpeg applies it.

Normalize dimensions before encoding

For a calculated even dimension, use an expression such as:

(iw/2)*2

The integer evaluation floors the input to an even value. Apply the same idea to height:

(ih/2)*2

The exact expression depends on the geometry you're calculating, but the principle is consistent. Normalize the result before handing it to an encoder that rejects incompatible dimensions.

Clamp coordinates to the frame

If w and h are valid but the requested origin can drift beyond the available area, clamp the coordinates:

min(x,iw-w)
min(y,ih-h)

For a centered crop, a safer origin can be expressed as:

max(0,min((iw-w)/2,iw-w))

and similarly for y. The formula keeps the origin within the range where the entire crop rectangle remains inside the source.

A 9:16 crop should first decide whether the source can contain that ratio without padding. The basic source-relative rectangle is:

crop=ih*9/16:ih:(iw-ih*9/16)/2:0

That works when the calculated width is no greater than iw. A defensive implementation should gate that condition, normalize the crop width to an even value, and choose padding or a scale-and-crop path when the source is too narrow.

Crop versus pad is a geometry decision

If the source is wider than the requested portrait ratio, crop the sides. If the source is narrower, cropping would discard essential height or produce an invalid rectangle, so pad instead. A scale-and-pad chain preserves the entire frame, while scale-and-crop prioritizes a filled canvas.

Also inspect sample aspect ratio and display aspect ratio before making decisions. The FFmpeg main documentation describes -apply_cropping, which can honor crop information stored in file metadata at the decoding stage. A pipeline that ignores that metadata may calculate geometry from a frame that is already intended to display differently.

Error Message Root Cause Defensive Fix
Non-positive size Width or height expression evaluates to zero or less Guard the aspect-ratio condition and clamp calculated dimensions
Width or height not divisible by 2 Crop result produces an odd dimension for the chosen encoder Normalize with an even-number expression
Invalid too big Crop rectangle exceeds the input frame Clamp x and y, or choose pad when the source cannot contain the target
Area outside picture Coordinates or dimensions reference pixels outside the decoded image Probe geometry and account for display metadata before filtering

Previewing and Verifying Crop Output

Never commit a full encode before checking the crop on representative frames. A command can complete successfully while keeping the wrong side of the composition, cutting off a face, or producing a target geometry that disagrees with the platform specification.

A quick preview uses a seek position and a short duration:

ffmpeg -ss 00:00:05 -i input.mp4 -t 00:00:05 -vf "crop=1080:1080:(iw-1080)/2:(ih-1080)/2" -c:v libx264 -an preview.mp4

The -an option removes audio from the temporary preview. For interactive inspection, send the filtered stream to ffplay:

ffplay -i input.mp4 -vf "crop=1080:1080:(iw-1080)/2:(ih-1080)/2"

That lets you scrub through the composition before paying for a complete transcode.

Probe the result, not just the command

After rendering, inspect width, height, sample aspect ratio, and display aspect ratio:

ffprobe -v error -select_streams v:0 -show_entries stream=width,height,sample_aspect_ratio,display_aspect_ratio -of default=noprint_wrappers=1 output.mp4

You want three signals:

  • The pixel dimensions match the intended crop or post-crop scale.
  • The aspect metadata is sensible, rather than introducing an unexpected display shape.
  • The subject remains inside the rectangle throughout the preview, not only on the opening frame.

Some MP4 and MOV sources carry crop metadata. FFmpeg's -apply_cropping input option supports explicit modes for honoring that metadata, including none, all, codec, and container, with all as the documented default. You can disable metadata-based cropping when you need to inspect the raw decoded frame:

ffmpeg -apply_cropping none -i input.mp4 -vf "crop=..." output.mp4

Use this deliberately. Applying metadata cropping and then adding a manual crop can produce a result that is smaller than expected because two geometry operations are taking effect. For a convenient browser-based check, RenderIO's video crop tool can help validate a selected area before you formalize the filter in a batch command.

Running Crop Commands in a RenderIO Pipeline

A terminal command is a good place to settle the geometry. Production work needs the same filter to accept mixed inputs, preserve the intended audio behavior, expose stderr when a source fails, and continue processing the rest of a queue.

RenderIO accepts FFmpeg commands through a REST workflow, so the filter expression can remain recognizable rather than being rewritten into a proprietary crop language. A minimal payload can look like this:

{ "input": "https://example.com/input.mp4", "output": "vertical.mp4", "video_filter": "crop=ih*9/16:ih:(iw-ih*9/16)/2:0,scale=1080:1920", "audio": "copy" }

The important part is the filter string. iw and ih are evaluated from the decoded source inside the filter graph, allowing the same expression to adapt to each clip. In a real job, the API request should also apply the defensive aspect-ratio gate described earlier, because a raw 9:16 crop still fails when the source is too narrow.

A batch can then send mixed-orientation files through a validation step, choose crop or pad, and queue the resulting filter chain. Downstream operations can include scaling, padding, codec selection, and container output. RenderIO's product description states that failed jobs return FFmpeg stderr and that the service supports retries and webhook or polling-based progress, which are practical controls when one malformed source shouldn't halt an entire batch.

The production pattern is straightforward: probe each input, select a geometry path, submit the command, and record the output metadata. Don't treat one successful sample as proof that a static formula is safe for every file.

Crop Command Checklist and Common Pitfalls

Keep this checklist beside the terminal. Reliable FFmpeg crop video automation comes from explicit decisions, not from compressing every possibility into a clever one-liner.

  • Choose crop or pad first. Crop when edge content can disappear. Pad when the full frame must remain visible. This prevents a portrait conversion from cutting off required context.
  • Derive geometry from iw and ih. Source-relative expressions adapt to changing resolutions. This prevents hard-coded coordinates from landing outside a smaller input.
  • Force compatible dimensions. Normalize calculated widths and heights to even values before encoding. This avoids “not divisible by 2” failures from codec constraints.
  • Guard the requested ratio. Check whether the source can contain the target rectangle. If it can't, switch to scale and pad instead of allowing “non-positive size” or “invalid too big” errors.
  • Clamp the origin. Keep x between 0 and iw-w, and y between 0 and ih-h. This prevents “area outside picture” failures.
  • Preview a short window. Use -ss, -t, or ffplay before a full encode. This catches a technically valid crop that removes the speaker or leaves the wrong border.
  • Probe the output. Confirm width, height, SAR, and DAR with ffprobe. A completed command can still produce an unexpected display shape.
  • Inspect metadata cropping. For MP4 and MOV files, decide whether -apply_cropping should honor stored crop metadata. Avoid unintentionally applying metadata and manual cropping together.
  • Handle audio explicitly. The crop filter changes video only. Copy or re-encode audio according to the output container and synchronization requirements.
  • Use crop detection as a starting point. cropdetect can help identify static borders, but review its output before hardcoding values. Letterboxing can change during a clip, and automated detection doesn't understand subject importance.

A checklist infographic outlining five essential steps for cropping and formatting video files using command-line tools.

The durable rule is to validate before filtering. A crop command that works on a clean reference file may fail on odd dimensions, incompatible geometry, or metadata-heavy sources. Build the decision into the pipeline, then use the simple formula only after its assumptions have been checked.


RenderIO lets you submit FFmpeg processing jobs through an API, including crop, scale, pad, transcode, and batch operations, without managing your own render workers. Visit RenderIO to turn a verified crop command into a repeatable workflow for mixed-source video files.