The ffmpeg equivalent of CSS "object-fit: cover": scale the source until it covers 640×480 on both axes, keeping its aspect ratio, then crop the overflow from the center. No letterboxing, no distortion; the edges of wider sources are cut off instead.
Also in notes/commands2.txt: the same cover-and-crop at 1280×720 (scale=1280:720:force_original_aspect_ratio=increase,crop=1280:720).
The command
ffmpeg -i input.mp4 \
-vf "scale=640:480:force_original_aspect_ratio=increase,crop=640:480,fps=30" \
-c:a aac -b:a 128k \
-c:v libx264 -crf 18 -preset veryfast -pix_fmt yuv420p \
output.mp4 What each part does
scale=640:480:force_original_aspect_ratio=increase
scale up just enough to cover 640×480
crop=640:480 cut the centered 640×480 region
fps=30 conform to 30 fps (drops or repeats frames)
-c:a aac -b:a 128k AAC audio, 128 kb/s
-c:v libx264 -crf 18 -preset veryfast -pix_fmt yuv420p
high-quality H.264 that plays everywhere When to use it
Use this when every clip has to land at exactly 640×480 with no black bars and no stretching: a 4:3 slot in a grid, a batch of mixed sources headed for one sequence, or footage for an older 4:3 target. It works like CSS object-fit: cover, and the header explains each flag.
Don't use it when the whole picture must stay visible. Wide sources lose their left and right edges, and portrait phone footage loses much of its top and bottom.
For widescreen output, change both the scale and the crop sizes to 1280:720, the variant noted in the header. You can also change fps=30 to match your project rate. For a 720×480 frame, see fill-crop-720x480.sh.
If the output looks wrong:
- The subject is cut off: the crop is always centered, so off-center action is lost.
- Motion stutters: the source rate didn't divide evenly into 30 fps, so frames were dropped or repeated.
- You get a filter error: check the commas between the filters. The original batch loop broke because of a missing comma.
Notes
- Source
- ffmpeg-utilities/batch 2.sh (also the batch loop in videogrep.sh, where a missing comma read "crop=640:480fps=fps=30")
- Changed
- fps=fps=30 → fps=30