Convert video to WebM with FFmpeg

Run ffmpeg -i in.mp4 -c:v libvpx-vp9 -crf 31 -b:v 0 -row-mt 1 -c:a libopus out.webm. CRF sets the quality (0 to 63, lower is better), -row-mt 1 lets libvpx use more threads, and Opus is the audio WebM expects. For a smaller file at the same quality, use AV1 with libaom-av1: on our clip it scored the same VMAF in 41% less video data.

VP9 Re-encode

The usual WebM. Smaller than H.264 at the same quality.

ffmpeg -i in.mp4 -c:v libvpx-vp9 -crf 31 -b:v 0 -row-mt 1 -c:a libopus out.webm

VMAF 97.8. 7.3 MB of video, 9% less than H.264 at CRF 23 (VMAF 97.6) on the same clip. libopus picked about 84 kb/s.

VMAF
97.8
Video data
7.3 MB
Run time
25.4 s
Output
7.7 MB
AV1 Re-encode

The smallest file for the same quality, for players that decode AV1.

ffmpeg -i in.mp4 -c:v libaom-av1 -crf 30 -cpu-used 6 -row-mt 1 -c:a libopus out.webm

VMAF 97.7, level with VP9, in 4.3 MB of video: 41% smaller than the VP9 file.

VMAF
97.7
Video data
4.3 MB, 41% under VP9
Run time
32.7 s
Output
4.6 MB

Proof

Three codecs on the same frame, and an alpha channel

The crops are 0:27 of each WebM, the baby dragon, enlarged 2x with no smoothing. The last two pictures are the transparent logo WebM laid over a Sintel frame, decoded two ways.
libvpx-vp9 -crf 31 -b:v 0 VMAF 97.8
Dragon close-up from the VP9 CRF 31 WebM, sharp scales and wall texture
7.7 MB Scales and stone grain hold, close to the H.264 CRF 23 encode of the same clip.
libaom-av1 -crf 30 -cpu-used 6 VMAF 97.7
Dragon close-up from the AV1 CRF 30 WebM, close to the VP9 frame
4.6 MB Hard to tell from VP9 in this crop, in 60% of the bytes.
libvpx -crf 10 -b:v 1M VMAF 90.2
Dragon close-up from the VP8 WebM with ringing around edges and a smeared wall
4.1 MB The old VP8 command from the most-voted answers. The 1 Mb/s cap holds the size down and the wall smears.
decoded with -c:v libvpx-vp9 Transparency kept
The white Rendobar mark laid over a Sintel frame with the background showing through
26 KB The 3 s logo WebM over a frame of the film. The scene shows through every transparent pixel.
decoded with FFmpeg's default VP9 decoder Alpha dropped
The same overlay where the transparent areas of the logo came out black
yuv420p Same file, same command, without -c:v libvpx-vp9 before the input. The built-in decoder ignores the alpha.

Footage: Sintel, © Blender Foundation, CC BY 3.0. Cut to 30 s and scaled to 1280x546 by us.

Run it

Run it on Rendobar

Send the same command from your code. The job fetches each input from its URL and returns the output file's URL when it finishes.

job.ts
import { createClient } from "@rendobar/sdk";
const rb = createClient({ apiKey: process.env.RENDOBAR_API_KEY });
const job = await rb.jobs.run({
type: "ffmpeg",
inputs: {
"in.mp4": "https://cdn.rendobar.com/examples/convert-to-webm/in.mp4",
},
params: {
command: "ffmpeg -i in.mp4 -c:v libvpx-vp9 -crf 31 -b:v 0 -row-mt 1 -c:a libopus out.webm",
},
});
console.log(job.output.file.url);

Install with npm i @rendobar/sdk. jobs.run() submits and waits, so it returns the finished job in one call.

terminal
curl https://api.rendobar.com/jobs \
-H "Authorization: Bearer $RENDOBAR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "ffmpeg",
"inputs": {
"in.mp4": "https://cdn.rendobar.com/examples/convert-to-webm/in.mp4"
},
"params": {
"command": "ffmpeg -i in.mp4 -c:v libvpx-vp9 -crf 31 -b:v 0 -row-mt 1 -c:a libopus out.webm"
}
}'

Returns immediately with a job id. Poll GET /jobs/{id} or register a webhook rather than blocking on the request.

Every variant

Pick the command for your case

Each one ran on the same input. The line under it is what came out. Run times are the best of three runs with FFmpeg 8.0 on one desktop machine, so read them as relative.

  1. Encode VP9 in two passes

    Re-encode
    ffmpeg -i in.mp4 -c:v libvpx-vp9 -crf 31 -b:v 0 -row-mt 1 -pass 1 -an -f null - && ffmpeg -i in.mp4 -c:v libvpx-vp9 -crf 31 -b:v 0 -row-mt 1 -pass 2 -c:a libopus out.webm

    VMAF 98.2 in 6.5 MB of video: smaller and better than one pass at the same CRF. Pass 1 leaves ffmpeg2pass-0.log next to the input.

    1.8 s run 6.8 MB 30.02 s long

  2. Encode VP9 faster

    Re-encode
    ffmpeg -i in.mp4 -c:v libvpx-vp9 -crf 31 -b:v 0 -row-mt 1 -cpu-used 4 -c:a libopus out.webm

    VMAF 97.5 against 97.8, and 1% bigger. -cpu-used runs from -8 to 8 in libvpx-vp9, default 1, and higher is faster.

    10.5 s run 7.8 MB 30.02 s long

  3. Encode VP9 with -crf and no -b:v

    Re-encode
    ffmpeg -i in.mp4 -c:v libvpx-vp9 -crf 31 -row-mt 1 -c:a libopus out.webm

    The same video stream as with -b:v 0, MD5 for MD5, on FFmpeg 8.0.

    25.6 s run 7.7 MB 30.02 s long

  4. Make a WebM with a transparent background

    Re-encode
    ffmpeg -loop 1 -t 3 -i logo.png -vf fade=in:st=0:d=1:alpha=1 -c:v libvpx-vp9 -pix_fmt yuva420p out.webm

    3 s of the logo fading in over transparency, 512x512. The file is tagged alpha_mode=1 and decodes as yuva420p.

    936 ms run 26 KB 3.00 s long

  5. Make a VP8 WebM for old players

    Re-encode
    ffmpeg -i in.mp4 -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis out.webm

    VMAF 90.2. With VP8, -b:v is a ceiling and -crf the target inside it, so 1M decides the size here.

    10.0 s run 4.1 MB 30.02 s long

Gotchas

Where it goes wrong

Do I still need -b:v 0 with -crf?

Not on FFmpeg 8.0. The VP9 wiki and older answers say -b:v 0 is required for constant quality, and that -crf alone runs constrained quality under a default bitrate. On 8.0 the two commands wrote the same video stream, MD5 8d530f4e... both times.

Keep it in scripts anyway. It changes nothing on 8.0 and it pins the mode on builds you have not tested.

VP9 or AV1?

AV1 gives the smaller file. At the settings above both scored VMAF 97.7 to 97.8, with 7.3 MB of VP9 video against 4.3 MB of AV1. H.264 at CRF 23 needed 8.1 MB for VMAF 97.6.

Check which AV1 encoders your FFmpeg has before you copy a command:

ffmpeg -hide_banner -encoders | grep av1

This build lists libaom-av1 and hardware encoders such as av1_nvenc and av1_qsv, and no libsvtav1. A command that names libsvtav1 fails on it with "Unknown encoder 'libsvtav1'".

Why does my transparent WebM show a black background?

FFmpeg's built-in VP9 decoder ignores the alpha channel, so anything decoded with it loses the transparency. ffprobe reports the file as yuv420p for the same reason, which makes it look as if the alpha was never written.

Ask for the libvpx decoder before the input:

ffmpeg -c:v libvpx-vp9 -i out.webm -f null -

The stream decodes as yuva420p, 655,360 bytes a frame at 512x512: the alpha plane is there. The pictures above show the difference in an overlay.

Related: Encode H.264 and H.265, Convert to MP4, Compress a video, MP4 to GIF.

Your command. Our infrastructure.

Bring your own commands. Run them on scalable CPU and GPU infrastructure, and pay only for compute time.