All posts

MP4 to WebM via CLI

Re-encode to VP9 + Opus with ffmpeg.

Open online converter

Packages to install

Install ffmpeg built with libvpx-vp9 and libopus — Ubuntu’s package includes both.

ffmpeg
apt install
sudo apt-get update
sudo apt-get install -y ffmpeg

How to run the command

ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 32 -b:v 0 -deadline good -cpu-used 4 -c:a libopus -b:a 96k output.webm. -b:v 0 enables constant-quality CRF mode.

ffmpeg
ffmpeg -y -i input.mp4 -c:v libvpx-vp9 -crf 32 -b:v 0 -deadline good -cpu-used 4 -c:a libopus -b:a 96k output.webm

Dockerfile example

Build a minimal Ubuntu image with the required packages and run the conversion inside the container.

Dockerfile
FROM ubuntu:24.04

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        ffmpeg && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /work
docker build && docker run
docker build -t mp4-to-webm .
docker run --rm -v "$PWD:/work" -w /work mp4-to-webm \
  ffmpeg -y -i input.mp4 -c:v libvpx-vp9 -crf 32 -b:v 0 -deadline good -cpu-used 4 -c:a libopus -b:a 96k output.webm

Example commands

Run these locally after installing the packages, or inside the container from the Dockerfile.

Example 1
ffmpeg -y -i input.mp4 -c:v libvpx-vp9 -crf 32 -b:v 0 -deadline good -cpu-used 4 -c:a libopus -b:a 96k output.webm
Example 2
ffmpeg -y -i input.mp4 -c:v libvpx-vp9 -crf 36 -b:v 0 -c:a libopus -b:a 64k output.webm