WaveSpeedAI

How to Convert Images to JPG, PNG, WebP, GIF with FFmpeg (2026 Guide)

Complete guide to converting images between JPG, PNG, WebP, and GIF formats using FFmpeg. Includes batch conversion, quality control, and a free one-click alternative.

By WaveSpeedAI7 min read
How to Convert Images to JPG, PNG, WebP, GIF with FFmpeg (2026 Guide)

FFmpeg isn’t just for video—it’s also a powerful tool for ​image format conversion​. Whether you need to convert PNG screenshots to JPG, optimize images as WebP for the web, or create GIFs from image sequences, FFmpeg handles it all from the command line. Use JPG when you don’t need transparency, PNG or WebP when you do, and GIF for short animations.

Of course, if typing commands isn’t your thing, we’ve got a free one-click solution at the end.

Prerequisites: Install FFmpeg

macOS:

brew install ffmpeg

​Ubuntu/Debian:

sudo apt update && sudo apt install ffmpeg

Windows: Download from ffmpeg.org, extract, and add bin to your PATH.

Check your version before starting. WebP commands also need a build with the libwebp encoder:

ffmpeg -version
ffmpeg -hide_banner -h encoder=libwebp

I checked the image and GIF conversion commands on November 4, 2026, with FFmpeg 9.0 on macOS, using a transparent 64×64 PNG and a two-second MP4. In the examples below, input.* is your source file and output.* is the new file.

Basic Image Conversions

PNG to JPG

For a PNG without transparency:

ffmpeg -i input.png -q:v 2 output.jpg
  • -q:v 2 — JPEG quality (lower values mean higher quality and usually larger files). 2–5 is a useful starting range.

JPG cannot store transparency. If your PNG has transparent areas, put it on a background first. This command uses white:

ffmpeg -i input.png -filter_complex "[0:v]split[fg][base];[base]format=rgb24,drawbox=c=white:t=fill[bg];[bg][fg]overlay=shortest=1:format=auto,format=yuv420p" -frames:v 1 -q:v 2 output.jpg

On the test PNG, transparent areas became white and semi-transparent blue became pale blue in the JPG output.

JPG to PNG

ffmpeg -i input.jpg output.png

PNG saves the new output losslessly, but converting a JPG to PNG won’t restore detail already lost in the JPG.

PNG/JPG to WebP

ffmpeg -i input.png -frames:v 1 -c:v libwebp -quality 80 output.webp
  • -quality 80 — lossy WebP quality (0–100). 75–85 is a reasonable range to try.

With a libwebp build, both lossy and lossless WebP can retain transparency from a transparent PNG. The test PNG kept its transparent, semi-transparent, and opaque areas in both modes. To check the output’s codec, dimensions, and pixel format, run:

ffprobe -v error -select_streams v:0 -show_entries stream=codec_name,pix_fmt,width,height -of default=noprint_wrappers=1 output.webp

Also open the WebP over a checkerboard background to confirm that transparency looks right.

WebP to PNG

ffmpeg -i input.webp output.png

WebP to JPG

ffmpeg -i input.webp -q:v 2 output.jpg

If the WebP has transparency, use the white-background command from “PNG to JPG” with input.webp as the input.

BMP to PNG

ffmpeg -i input.bmp output.png

TIFF to JPG

ffmpeg -i input.tiff -q:v 2 output.jpg

Working with GIFs

Image Sequence to GIF

Convert a series of images (frame001.png, frame002.png, …) into an animated GIF:

ffmpeg -framerate 10 -i frame%03d.png -vf "scale=480:-1:flags=lanczos" output.gif
  • -framerate 10 — 10 frames per second
  • frame%03d.png — pattern matching frame001.png, frame002.png, etc.
  • scale=480:-1 — scale width to 480px, auto height
  • flags=lanczos — scaling algorithm

Video to GIF

ffmpeg -i input.mp4 -vf "fps=10,scale=480:-1:flags=lanczos" -loop 0 output.gif

If the colors look rough, make a second version with the palette commands under “Common Errors and Fixes,” then compare output.gif with output_palette.gif.

GIF to Image Sequence

Extract every frame from a GIF:

ffmpeg -i input.gif frame%03d.png

GIF to MP4

MP4 can be much smaller than GIF, though the reduction depends on the clip. Padding makes odd-sized GIFs compatible with the yuv420p pixel format:

ffmpeg -i input.gif -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -movflags +faststart -pix_fmt yuv420p output.mp4

Advanced Options

Control JPEG Quality

ffmpeg -i input.png -q:v 5 output.jpg
-q:vQualityFile Size
1HighestUsually largest
2–3Very goodLarge
5GoodMedium
10LowerSmaller
31LowestUsually smallest

These are rough guides; compare the actual output at the size people will view it.

Control WebP Quality

# Lossy WebP
ffmpeg -i input.png -frames:v 1 -c:v libwebp -quality 85 output.webp

# Lossless WebP
ffmpeg -i input.png -frames:v 1 -c:v libwebp -lossless 1 output.webp

Use lossless when exact pixels or clean graphics matter. Check file size and appearance before choosing between the two.

Resize Images

Scale to specific width (maintain aspect ratio):

ffmpeg -i input.png -vf "scale=800:-1" output.png

Scale to specific dimensions:

ffmpeg -i input.png -vf "scale=800:600" output.jpg

The second command can stretch the image if its original aspect ratio isn’t 4:3.

Change Color Space

Convert to grayscale:

ffmpeg -i input.png -vf "format=gray" output.png

Batch Conversion

Convert All PNG to JPG

Linux/macOS​​ (bash):

for f in *.png; do
  [ -e "$f" ] || continue
  ffmpeg -n -i "$f" -frames:v 1 -q:v 2 "${f%.png}.jpg" || { printf 'Failed: %s\n' "$f" >&2; break; }
done

-n prevents overwriting an existing output. This loop is for PNGs without transparency; for transparent PNGs, use the white-background conversion shown above.

Convert All JPG to WebP

for f in *.jpg; do
  [ -e "$f" ] || continue
  ffmpeg -n -i "$f" -frames:v 1 -c:v libwebp -quality 80 "${f%.jpg}.webp" || { printf 'Failed: %s\n' "$f" >&2; break; }
done

​Windows (PowerShell​**):**

Get-ChildItem *.png | ForEach-Object {
  ffmpeg -n -i $_.Name -frames:v 1 -q:v 2 ($_.BaseName + ".jpg")
}

Common Errors and Fixes

“Output​​ file is blank or all black”

If a transparent PNG turns black when converted to JPG, use the white-background command in “PNG to JPG.” If the output is genuinely blank, check whether FFmpeg can decode the input:

ffmpeg -v error -i input.png -f null -

An error printed here points to the input or decoder; forcing rgb24 on the JPG output does not fix either problem.

“GIF​​ output has terrible colors”

GIFs are limited to 256 colors. Make a palette version from the same input and settings as the direct GIF above:

ffmpeg -i input.mp4 -vf "fps=10,scale=480:-1:flags=lanczos,palettegen" palette.png
ffmpeg -i input.mp4 -i palette.png -lavfi "fps=10,scale=480:-1:flags=lanczos[x];[x][1:v]paletteuse" output_palette.gif

Compare output.gif and output_palette.gif visually and by file size. A palette can improve color handling, but it does not guarantee a smaller file.

“Cannot determine format”

Check the input file and give the output a recognizable extension, such as .png. FFmpeg normally selects the image output format from that extension; adding -f image2 to an invalid input won’t repair it.

Skip the Terminal: Use WaveSpeed Desktop Instead

Converting one image is manageable with FFmpeg. Converting a batch of images while controlling quality, format, and size? That’s where it gets tedious fast.

WaveSpeed Desktop includes a built-in ​Image Converter​:

  • Drag and drop one or multiple images
  • Pick the output format (JPG, PNG, WebP, GIF)
  • Click convert — all done

No FFmpeg setup. No terminal. No remembering quality flags.

Download WaveSpeed Desktop for free:https://github.com/WaveSpeedAI/wavespeed-desktop/releases

FAQ

What’s the best image format for the web?

WebP is a good starting point when your target supports it, including when you need transparency. JPEG works for photos; PNG works when you need lossless graphics or a PNG-specific workflow.

Does converting JPG to PNG improve quality?

No. Like audio, you can’t recover information lost during JPEG compression. The PNG file may just be larger.

How much smaller is WebP compared to JPEG?

It depends on the image and quality settings. Compare the two outputs at a visual quality you can accept rather than expecting a fixed percentage.

Can FFmpeg handle RAW camera files?

Support varies by RAW format and FFmpeg build. For camera-specific color and processing controls, use a dedicated RAW tool such as darktable.


Previous posts:

Share