Why Use FFmpeg for WebM Conversion?

FFmpeg is the gold standard for video conversion. It's free, open-source, runs on Windows, macOS, and Linux, and gives you precise control over codecs, bitrates, resolution, and quality settings. For anyone serious about WebM conversion, FFmpeg is the tool to know.

Installing FFmpeg

Before you begin, make sure FFmpeg is installed on your system:

  • Windows: Download from ffmpeg.org, extract the zip, and add the bin folder to your system PATH
  • macOS: Install via Homebrew with brew install ffmpeg
  • Linux (Ubuntu/Debian): Run sudo apt install ffmpeg

Verify the installation by running ffmpeg -version in your terminal.

Basic MP4 to WebM Conversion

The simplest conversion command looks like this:

ffmpeg -i input.mp4 output.webm

FFmpeg will automatically choose VP8 for video and Vorbis for audio. This works, but you can do much better with a few extra flags.

Recommended Command: VP9 + Opus

For the best quality-to-size ratio, use the VP9 video codec and the Opus audio codec:

ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 30 -b:v 0 -c:a libopus output.webm

Here's what each flag means:

  • -c:v libvpx-vp9 — Use the VP9 video codec
  • -crf 30 — Constant Rate Factor; lower = better quality (range: 0–63)
  • -b:v 0 — Variable bitrate mode (required for CRF to work correctly with VP9)
  • -c:a libopus — Use the Opus audio codec

Controlling Quality vs. File Size

The -crf value is your main quality dial:

CRF ValueQuality LevelTypical Use Case
15–20High qualityArchival, professional use
25–33Good qualityWeb video, streaming
35–45AcceptableSmall file sizes, previews

Two-Pass Encoding for Better Results

For consistent bitrate control — useful when you have a target file size — use two-pass encoding:

# Pass 1
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 1M -pass 1 -an -f null /dev/null

# Pass 2
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 1M -pass 2 -c:a libopus output.webm

Replace 1M with your desired target bitrate (e.g., 500K, 2M). On Windows, replace /dev/null with NUL.

Resizing and Trimming During Conversion

You can resize the video and trim it in the same command:

# Resize to 1280x720
ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 30 -b:v 0 -vf scale=1280:720 -c:a libopus output.webm

# Trim to first 30 seconds
ffmpeg -i input.mp4 -t 30 -c:v libvpx-vp9 -crf 30 -b:v 0 -c:a libopus output.webm

Batch Converting Multiple Files

On Linux/macOS, convert all MP4 files in a folder with a one-liner:

for f in *.mp4; do ffmpeg -i "$f" -c:v libvpx-vp9 -crf 30 -b:v 0 -c:a libopus "${f%.mp4}.webm"; done

Final Tips

  • VP9 encoding is slower than H.264 — be patient with large files
  • Use -speed 4 for faster encoding at a slight quality cost during testing
  • Always check your output with ffprobe output.webm to verify codec and bitrate