Lesson 3 of 7

Resize and Crop

Scale videos to any resolution, crop specific regions, maintain aspect ratios, and prepare content for different social media platforms.

Why Resize and Crop?

Videos rarely arrive in the exact dimensions you need. A 4K camera recording needs to become a 1080p web upload. A landscape video needs to become a portrait reel. A wide-angle shot has dead space on the edges that should be cropped out.

FFmpeg handles all of this through its filter system. The two filters you will use most are scale (for resizing) and crop (for trimming edges).

The Video Filter Flag: -vf

All video filters in FFmpeg are applied using the -vf flag (short for -filter:v). You pass a filter name and its parameters:

ffmpeg -i input.mp4 -vf "scale=1280:720" output.mp4

You can chain multiple filters together with commas:

ffmpeg -i input.mp4 -vf "crop=1080:1080,scale=720:720" output.mp4

Filters are applied left to right, so this crops first, then scales the cropped result.

Scaling (Resizing) Videos

Basic scale: set exact dimensions

ffmpeg -i input.mp4 -vf "scale=1280:720" -c:a copy output.mp4

This forces the output to exactly 1280x720 pixels, regardless of the input size. If the aspect ratio does not match, the video will be distorted (stretched or squished).

Scale by width, preserve aspect ratio

ffmpeg -i input.mp4 -vf "scale=1280:-1" -c:a copy output.mp4

Setting one dimension to -1 tells FFmpeg to calculate it automatically from the other dimension while preserving the aspect ratio. A 1920x1080 input becomes 1280x720. A 1920x800 input becomes 1280x533.

Gotcha: Some codecs require even dimensions. If -1 produces an odd height, encoding will fail. Use -2 instead to round to the nearest even number:

ffmpeg -i input.mp4 -vf "scale=1280:-2" -c:a copy output.mp4

Scale by height, preserve aspect ratio

ffmpeg -i input.mp4 -vf "scale=-2:720" -c:a copy output.mp4

Same idea, but anchoring on height. Useful when you need a specific vertical resolution (e.g. 720p) regardless of the aspect ratio.

Scale down only (never upscale)

Upscaling a 720p video to 1080p adds pixels but no detail — the result looks blurry. You can prevent upscaling with a conditional expression:

ffmpeg -i input.mp4 -vf "scale='min(1280,iw)':'min(720,ih)'" -c:a copy output.mp4

iw and ih are built-in variables for the input width and height. This caps the output at 1280x720 but leaves smaller videos untouched.

Cropping Videos

The crop filter cuts a rectangular region from the frame. Its syntax is:

crop=width:height:x:y

Where x and y are the top-left corner of the crop region. If omitted, the crop is centered.

Center crop to 1:1 (square)

ffmpeg -i input.mp4 -vf "crop=ih:ih" -c:a copy output.mp4

This takes the input height as both the width and height, creating a centered square crop. For a 1920x1080 video, this produces a 1080x1080 square from the center.

Crop to 9:16 (vertical / portrait)

ffmpeg -i input.mp4 -vf "crop=ih*9/16:ih" -c:a copy output.mp4

This calculates the 9:16 width from the input height, producing a centered vertical crop. Perfect for converting landscape footage into portrait format for Instagram Reels or TikTok.

Crop from a specific position

ffmpeg -i input.mp4 -vf "crop=640:480:100:50" -c:a copy output.mp4

Extracts a 640x480 rectangle starting at pixel position (100, 50) from the top-left corner. Useful when you need to isolate a specific region of the frame.

Remove black bars (letterbox / pillarbox)

FFmpeg can automatically detect and remove black bars using the cropdetect filter. First, detect the crop values:

ffmpeg -i input.mp4 -vf "cropdetect=24:16:0" -f null -

Look at the output for lines like crop=1920:800:0:140, then use those values:

ffmpeg -i input.mp4 -vf "crop=1920:800:0:140" -c:a copy output.mp4

Social Media Presets

Different platforms have different size requirements. Here are ready-to-use commands for the most common targets:

YouTube (1080p landscape)

ffmpeg -i input.mp4 -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2" output.mp4

Scales to fit within 1920x1080 and adds letterbox padding if needed.

Instagram Reels / TikTok (1080x1920 portrait)

ffmpeg -i input.mp4 -vf "crop=ih*9/16:ih,scale=1080:1920" output.mp4

Center-crops to 9:16, then scales to 1080x1920.

Twitter / X (1280x720 landscape)

ffmpeg -i input.mp4 -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2" output.mp4

Instagram Feed (1080x1080 square)

ffmpeg -i input.mp4 -vf "crop=ih:ih,scale=1080:1080" output.mp4

Combining Scale and Crop with Padding

Sometimes you want to fit a video into a specific frame size without cropping any content. The pad filter adds colored bars (default black) to fill the space:

ffmpeg -i input.mp4 -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2:color=black" output.mp4

This is a three-step chain: first it scales the video to fit within 1920x1080 while preserving aspect ratio, then it pads the result to exactly 1920x1080 by centering it on a black background. The expression (ow-iw)/2 calculates the offset needed to center horizontally.

You can change the padding color to white, a brand color, or any hex value:

# White padding pad=1920:1080:(ow-iw)/2:(oh-ih)/2:color=white # Custom hex color pad=1920:1080:(ow-iw)/2:(oh-ih)/2:color=0x1a1a2e

Performance Tips

  • Scale before crop when downscaling and cropping — the crop operates on fewer pixels.
  • Crop before scale when upscaling — scale only the region you need.
  • Use -c:a copy to pass through audio untouched when you are only modifying the video.
  • Always use -2 instead of -1 for automatic dimensions to avoid odd-number errors.

Key Takeaways

  • Use -vf "scale=W:H" to resize — set one dimension to -2 to auto-calculate the other
  • Use -vf "crop=W:H:X:Y" to extract a region — omit X and Y for center crop
  • Chain filters with commas: "crop=...,scale=..."
  • Use pad to add bars instead of cropping content
  • Always test with a short clip before processing an entire library

Try This With FFmpeg Micro

Instead of running FFmpeg locally, you can use FFmpeg Micro's API to process videos in the cloud. No installation required.