Optimizing the settings for WebM using FFMpeg

30/12/2025

To achieve the smallest possible file size for WebM video while maintaining compatibility with modern web browsers, your best strategy is to use the VP9 video codec combined with the Opus audio codec.

While the newer AV1 codec offers slightly better compression, VP9 is the current "sweet spot" for web compatibility (supported by Chrome, Firefox, Edge, and Android) and high efficiency. To get the absolute best file size, you must trade encoding time for compression efficiency.

The following guide details how to use FFmpeg to maximize compression.

The Codec Combination

  • Video: libvpx-vp9 (VP9) provides excellent compression, approximately 30–50% better than the older H.264 standard.

  • Audio: libopus (Opus) is widely considered the best audio codec for the web, delivering high fidelity at very low bitrates (e.g., 64k or 96k).

Method 1: Two-Pass Constrained Quality (Recommended)

The most efficient way to compress VP9 is using a 2-pass encoding process. This allows FFmpeg to analyze the video first and then distribute the data bits exactly where they are needed most in the second pass.

We will also use "Constrained Quality" mode. This sets a target quality level (CRF) but prevents the bitrate from spiking too high, keeping the file size predictable and small.

The Commands:

Run these two commands in your terminal one after the other.

Pass 1 (Analysis):

Pass 2 (Compression):

Breakdown of the Critical Flags:

  • -c:v libvpx-vp9: Selects the VP9 encoder.

  • -b:v 0: Strictly necessary for VP9 Constant Quality mode. It tells the encoder to ignore standard bitrate targets and rely on the CRF value.

  • -crf 30: The Constant Rate Factor controls quality. The range is 0–63.

    • Lower numbers (e.g., 15) = Higher quality, larger file.

    • Higher numbers (e.g., 45) = Lower quality, tiny file.

    • 30–35 is usually the best balance for the web. If the file is still too big, try increasing this to 40.

  • -pass 1 / -pass 2: Tells FFmpeg to analyze the video first, then encode it.

  • -an: Removes audio in the first pass (speeds up analysis).

  • -deadline best: This is crucial for file size. It forces the encoder to spend as much time as necessary to find the most efficient compression. It is slow but produces the smallest file.

  • -cpu-used 0: Sets the compression efficiency to the maximum. Value 0 is the slowest but most efficient. (Values range 0–5).

  • -c:a libopus -b:a 64k: Encodes audio to Opus at 64 kbps, which is generally transparent for speech and decent for background music on the web.

This method is also compatible with the online video encoding service https://webmconverter.app where method 2 is not.

Method 2: AV1 (The "Bleeding Edge" Option)

If your target audience uses only the absolute newest browsers (Chrome 70+, Firefox 67+, Edge 79+), you can use the AV1 codec. It can be 30% smaller than VP9, but encoding takes significantly longer.

The Command:

Key Differences:

  • -c:v libsvtav1: Uses the Scalable Video Technology AV1 encoder (faster than the reference libaom-av1 but still very efficient).

  • -preset 3: Controls the speed/compression tradeoff (0–13). Lower numbers provide better compression but are much slower. Preset 3 is a heavy, high-efficiency setting.

  • -crf 35: AV1 handles quality differently; a CRF of 35 in AV1 often looks better than CRF 35 in VP9. You can push this number higher (e.g., 40 or 45) for incredibly small files.

Optimizing Audio for Web

Audio often takes up a surprising amount of space in small web videos. Since you are using WebM, the Opus codec is your secret weapon.

  • Stereo Music: Use -b:a 96k.

  • General Web Video: Use -b:a 64k.

  • Speech Only: You can safely drop to -b:a 32k or even -b:a 24k.

  • Remove Audio: If the video is a silent background loop (like a hero banner), always strip the audio track completely using -an.

Summary Checklist for Smallest Files

  1. Strip Audio (-an) if it is not needed.

  2. Use VP9 for broad compatibility or AV1 for maximum compression.

  3. Use 2-Pass Encoding to ensure efficient bit distribution.

  4. Maximize Effort with -deadline best and -cpu-used 0.

  5. Raise CRF (try 35–45) until the quality becomes unacceptable; this is the single most effective lever for reducing file size.

Even though method 2 is superior in file size, it remains a premium due to the costs of encoding.


© 2025 to-webm.webnode.co.uk. All rights reserved.
Powered by Webnode Cookies
Create your website for free! This website was made with Webnode. Create your own for free today! Get started