---
title: "Compress Image with FFmpeg"
date: 2022-12-05T10:43:28.000Z
author: Z.SHINCHVEN
tags: [FFmpeg, JPEG]
canonical: https://atlassc.net/2022/12/05/compress-image-with-ffmpeg
---
[FFmpeg](https://ffmpeg.org/) 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. 

```bash
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](https://trac.ffmpeg.org/wiki/Scaling) is scaled to 320px width, and the height is automatically calculated.
