Video resizing comes up constantly in real projects: generating thumbnails, delivering 720p versions for bandwidth savings, or normalizing uploads to a consistent aspect ratio. Let’s show some practical, production-ready FFmpeg commands you can copy, along with tips to preserve quality and handle odd edge cases.
Hi folks,
I have a bunch of clips in different sizes and orientations, and I need to batch downscale them for web delivery. I’m comfortable with the command line but want to avoid stretching, keep aspect ratio, and control quality. What is the simplest, reliable approach for how to resize video using FFmpeg? Also, how do I handle letterboxing or exact 16:9 outputs without distortion, and what are some safe defaults for codecs and bitrate/CRF?
FFmpeg’s scale filter is the backbone of video resizing. The key is to choose a target dimension strategy, then pair it with the right encoder settings for quality and compatibility.
ffmpeg -i input.mp4 -vf "scale=1280:-2" -c:v libx264 -crf 22 -preset medium -c:a copy -movflags +faststart output_1280w.mp4
scale=1280:-2sets width to 1280 and picks an even height automatically to preserve aspect ratio.-c:v libx264is a widely supported encoder.-crf 18to24is a good quality range. Lower is better quality.-c:a copykeeps the original audio without re-encoding.-movflags +faststarthelps web playback by movingmoovatoms to the start.
Use force_original_aspect_ratio to scale down while keeping the aspect ratio intact.
ffmpeg -i input.mp4 -vf "scale=w=1280:h=720:force_original_aspect_ratio=decrease" -c:v libx264 -crf 22 -preset medium -c:a copy output_fit_1280x720.mp4
If you need exactly 1280×720 output every time, scale down, then pad the rest.
ffmpeg -i input.mp4 -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1" \
-c:v libx264 -crf 22 -preset medium -c:a copy output_1280x720_letterboxed.mp4
padadds black bars if needed, centered using(ow-iw)/2and(oh-ih)/2.setsar=1ensures square pixels to avoid display quirks.
If letterboxing is not acceptable, crop instead of pad.
ffmpeg -i input.mp4 -vf "crop=w=min(iw\,ih*16/9):h=min(ih\,iw*9/16),scale=1280:720,setsar=1" \
-c:v libx264 -crf 21 -preset medium -c:a copy output_16x9_cropped.mp4
This first crops to the largest 16:9 region that fits the input, then scales to 1280×720.
- For the web, output
yuv420pfor broad playback support: add-pix_fmt yuv420p. - Control bitrate with CRF and preset. CRF manages quality targets, preset trades CPU for compression efficiency.
- Consider content type when picking resolution and bitrate. See video encoding best practices for planning.
for f in *.mp4; do
ffmpeg -i "$f" -vf "scale=1280:-2" -c:v libx264 -crf 22 -preset medium -c:a copy -pix_fmt yuv420p "resized_${f}"
doneCode language: JavaScript (javascript)
H.264 is still the safest default for compatibility. H.265 can save bitrate at the cost of encoding time and limited legacy support. If you are deciding between x264 and x265, this overview helps: x264 vs x265 guide.
If you prefer not to manage compute or pipelines yourself, you can upload once and request resized renditions via URL or SDKs. For example, a URL-based transform that scales and letterboxes to 1280×720 could look like:
https://res.cloudinary.com/demo/video/upload/w_1280,h_720,c_pad,b_black,ar_16:9,q_auto,f_mp4/sample
You can automate this in build systems and UIs, and pair it with format selection and quality tuning.
- Forgetting
-pix_fmt yuv420pcan break playback in some players. - Using odd dimensions. Many codecs prefer even dimensions; -2 in scale helps enforce this.
- Over-sharpening or repeatedly re-encoding. Work from the highest quality source available.
- Use
-vf "scale=WIDTH:-2"to resize while preserving aspect ratio. - Use
force_original_aspect_ratio=decreaseplus pad for an exact frame without distortion. - Use H.264 with
-crfaround 18 to 24 and-presetmedium for dependable results. - Set
-pix_fmt yuv420pand-movflags +faststartfor web compatibility. - If you need managed pipelines and on-the-fly transforms, consider URL-based resizing with a media platform like Cloudinary.
Ready to streamline video transforms and delivery in your apps? Create your free Cloudinary account and start optimizing today.