FFmpeg Filters in Action: Scale, Crop, Rotate, Sharpen

Fri May 10 2024

Master filtergraphs for common visual transforms: scaling, cropping, rotation, denoise, sharpen, and overlays.

Filters let you transform video and audio streams. Use -vf for simple video chains or -filter_complex for multi‑input graphs.

When to Use -vf vs -filter_complex

  • -vf is perfect for a single video stream (e.g., scale, crop, rotate).
  • -filter_complex is required for multi‑input graphs (overlays, PiP, concat with filters).

Common Video Filters

# Scale to 1280 wide, preserve AR ffmpeg -i in.mp4 -vf "scale=1280:-2:flags=lanczos" -c:v libx264 -crf 22 -c:a copy out.mp4 # Center crop 200px off each side ffmpeg -i in.mp4 -vf "crop=in_w-400:in_h-400" -c:v libx264 -crf 22 -c:a copy out_crop.mp4 # 90° clockwise rotate (transpose=1) ffmpeg -i in.mp4 -vf "transpose=1" -c:v libx264 -crf 22 -c:a copy out_rot.mp4 # Denoise (hqdn3d) + mild sharpen (unsharp) ffmpeg -i in.mp4 -vf "hqdn3d=1.5:1.5:6:6,unsharp=5:5:1.0" -c:v libx264 -crf 23 -c:a copy out_clean.mp4 # Picture-in-Picture overlay (second input top-right) ffmpeg -i bg.mp4 -i pip.mp4 -filter_complex "[0:v]scale=1280:720[v0];[1:v]scale=320:180[v1];[v0][v1]overlay=main_w-340:20" -c:v libx264 -crf 22 -c:a aac -shortest out_pip.mp4

Tips and Pitfalls

  • Filter order matters. For example, scale before sharpen.
  • Some overlays require matching pixel formats; use -pix_fmt yuv420p when in doubt.

Once you get comfortable with filtergraphs, you can compose powerful pipelines without leaving the CLI.