avatar

ShinChven's Blog

Compress Image with FFmpeg

Mon Dec 05 2022

FFmpeg is a powerful tool to process video and audio files.

It can also be used to compress images.

Compress JPEG

FFmpeg uses mjpeg as the default codec for JPEG.

ffmpeg -i input.jpg -q:v 1 -vf scale=320:-1 output.jpg
  • -q:v 1 also -qscale:v 1 means the quality of the output image is 1/31. The smaller the number, the better the quality. 1 is the best quality, 31 is the worst quality.
  • -vf scale=320:-1 means the output image is scaled to 320px width, and the height is automatically calculated.