Originally published at ffmpeg-micro.com
You need to resize a video to 720p. Or crop a landscape clip to vertical for TikTok. FFmpeg handles both, but the syntax trips up even experienced developers, especially around aspect ratios and pixel dimension requirements.
This guide covers the three filters you actually need: scale, crop, and pad.
How to Resize Video with the FFmpeg Scale Filter
The scale filter sets the output width and height in pixels.
ffmpeg -i input.mp4 -vf "scale=1280:720" -c:v libx264 -crf 23 output.mp4
This forces the video to exactly 1280x720. If your source has a different aspect ratio, the output gets stretched. To preserve the aspect ratio, use -2 for the dimension you want FFmpeg to calculate automatically:
ffmpeg -i input.mp4 -vf "scale=1280:-2" -c:v libx264 -crf 23 output.mp4
Why -2 instead of -1? H.264 and H.265 encoders require even pixel dimensions. Using -1 can produce an odd height like 719, which crashes the encode. The -2 flag rounds to the nearest even number.
How to Crop Video with FFmpeg
The crop filter cuts a rectangular area from your video. The syntax is crop=width:height:x:y, where x and y define the top-left corner.
To crop a centered 1080x1080 square from a 1920x1080 video:
ffmpeg -i input.mp4 -vf "crop=1080:1080:(iw-1080)/2:(ih-1080)/2" -c:v libx264 -crf 23 output.mp4
The expressions iw and ih refer to the input width and height. This formula centers the crop regardless of the source resolution.
Converting Horizontal Video to Vertical for TikTok and Reels
You have a 16:9 landscape video and need 9:16 for TikTok, Instagram Reels, or YouTube Shorts.
Center crop (keeps the middle, loses the edges):
ffmpeg -i input.mp4 -vf "crop=ih*9/16:ih,scale=1080:1920" -c:v libx264 -crf 23 vertical.mp4
Scale and pad (keeps everything, adds black bars):
ffmpeg -i input.mp4 -vf "scale=1080:-2,pad=1080:1920:0:(oh-ih)/2:black" -c:v libx264 -crf 23 vertical.mp4
Common Pitfalls
Odd pixel dimensions break H.264 encoding. Always use -2 for auto-calculated dimensions.
Filter order matters. crop then scale gives different results than scale then crop.
Upscaling degrades quality. If you must upscale, use flags=lanczos for sharper results.
Skip the Server Setup
If you are building crop and resize into an app, FFmpeg Micro handles the infrastructure. One API call, any filter combination, results in minutes.
Read the full post for API examples and platform-specific presets.
Top comments (0)