Set WebP Quality in FFmpeg Video Extraction

Extracting video frames as WebP images allows you to balance image fidelity and file size effectively. This guide explains how to control the WebP quality factor using FFmpeg's command-line options, whether you need lossy compression, high-fidelity output, or completely lossless images.

The Quality Parameter (-q:v)

When encoding to WebP via FFmpeg's libwebp encoder, image quality is controlled using the -q:v (or -quality) flag.

  • The quality scale ranges from 0 to 100.
  • Lower values increase compression and decrease file size.
  • Higher values retain more detail at the expense of larger file sizes.
  • The default value is typically 75.

Basic Extraction Command

To extract every frame from a video with a specific quality factor (for example, quality 80):

ffmpeg -i input.mp4 -q:v 80 output_%04d.webp

In this command:

  • -i input.mp4: Specifies the input video file.
  • -q:v 80: Sets the WebP quality factor to 80.
  • output_%04d.webp: Generates sequentially numbered files (e.g., output_0001.webp, output_0002.webp).

Extracting Frames at Specific Intervals

Extracting every frame of a high-framerate video creates thousands of files. To extract frames at set intervals, such as one frame per second, combine -q:v with the fps video filter:

ffmpeg -i input.mp4 -vf fps=1 -q:v 85 output_%04d.webp

To extract a single frame at a specific timestamp (e.g., at 00:01:30):

ffmpeg -ss 00:01:30 -i input.mp4 -frames:v 1 -q:v 90 thumbnail.webp

Lossless WebP Extraction

If your project requires pixel-perfect accuracy without compression artifacts, enable lossless mode using -lossless 1:

ffmpeg -i input.mp4 -lossless 1 output_%04d.webp

When -lossless 1 is specified, the -q:v flag changes its behavior: instead of controlling visual quality, it controls the encoding effort (compression speed vs. file size) from 0 (fastest, largest files) to 100 (slowest, smallest files).