惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
雷峰网
雷峰网
U
Unit 42
Y
Y Combinator Blog
I
InfoQ
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
量子位
Microsoft Security Blog
Microsoft Security Blog
B
Blog
The Cloudflare Blog
F
Fortinet All Blogs
Google DeepMind News
Google DeepMind News
MyScale Blog
MyScale Blog
C
Check Point Blog
S
SegmentFault 最新的问题
爱范儿
爱范儿
博客园 - 叶小钗
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hugging Face - Blog
Hugging Face - Blog
罗磊的独立博客
T
Tailwind CSS Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How to Crop and Resize Video with FFmpeg
Javid Jamae · 2026-05-06 · via DEV Community

Javid Jamae

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

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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.