Skip to content

How to Create WebM videos with FFmpeg

WebM is a media container format that is designed for video on the web. It's offered under a permissive licence which means that it has been integrated into many browsers making it a great choice for encoding video.

Because WebM is just a container format, the video itself is encoded using the VP8/VP9 or AV1 codecs. Vorbis or Opus codecs are used for the audio. AV1 and Opus are the most recent codecs to be released and so often perform the best when looking at compression and quality.

If opting to use the AV1 codec, make sure you check what devices you plan to support as only recent iPhones can play them back natively.

LinkWhy use WebM? Mux explains

There are many reasons you might choose to use WebM over other media formats:

  • Optimized for the Web - WebM was designed by Google for web use, making it compatible with modern web browsers.
  • High Compression Efficiency - WebM achieves high compression ratios which ultimately result in smaller file sizes. This means that videos with start playing faster and be quicker to download and stream.
  • Free and Open Source - WebM is an open-source format with no licensing fees, unlike formats like H.264, which may require licensing fees for commercial use.

LinkCreating a WebM file with VP9 and Opus

By default, FFmpeg will create a WebM using the VP9 and Opus codecs if you don't specify any encoder options:

bash
ffmpeg -i input.mp4 output.webm

To explicitly specify VP9 and Opus if needed, you can use the following options:

bash
ffmpeg -i input.mp4 -c:v libvpx-vp9 -c:a libopus output.webm

If you want to control the bitrate and adjust the quality of the output, it's recommended that you use "2-pass" mode which can achieve a higher quality result:

bash
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 3.5M -pass 1 -an -f null /dev/null && \ ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 3.5M -pass 2 -c:a libopus output.webm

We're calling `ffmpeg` twice to achieve this. 2-pass encoding can sometimes be very slow though. You may want to omit it when testing out options or when you don't require a very high quality encode.

LinkCreating a WebM file with AV1 and Opus

AV1 is the most recent and advanced video codec that WebM supports and is usually paired with Opus for audio.

To use AV1 you need to specify which codec to use for encoding, in this case `libaom-av1`. This example also sets the desired video bitrate to 3.5Mbps and chooses the Opus codec for audio (which should also just be the default if omitted):

bash
ffmpeg -i input.mp4 -c:v libaom-av1 -b:v 3.5M -c:a libopus output.webm

Similar to VP9, the highest quality output is usually done with 2 passes:

bash
ffmpeg -i input.mp4 -c:v libaom-av1 -b:v 3.5M -pass 1 -an -f null /dev/null && \ ffmpeg -i input.mp4 -c:v libaom-av1 -b:v 3.5M -pass 2 -c:a libopus output.mkv

LinkCreating a WebM file with VP8 for legacy support

If you need to support very old devices or browsers you may need to opt for VP8 instead of VP9 or AV1 for the codec. This will likely need to be paired with Vorbis instead of Opus for the audio codec to work correctly also. It would be best to use VP9 or AV1 where possible though.

You can create a WebM with VP8 and Vorbis like this:

bash
ffmpeg -i input.mp4 -c:v libvpx -c:a libvorbis output.webm

LinkAlternatives to using WebM

Containers like MP4 and the H.264 codec are extremely well supported across a range of devices where WebM is still catching up, so you might want to consider alternative formats if you need to support more than just the web.

Here are some guides we have that may be useful for you when choosing an alternative:

LinkWebM FAQs

Should I use VP9 or AV1 for WebM encoding?

AV1 offers roughly 30% better compression than VP9 at equivalent quality but encodes much slower (5-10x longer) and isn't supported on older devices—particularly pre-2020 iPhones. Use VP9 for broad compatibility and reasonable encoding times. Use AV1 when file size is critical, encoding time isn't constrained, and you know your audience has modern devices. For most web video, VP9 provides the best balance.

Why is WebM encoding so much slower than H.264?

VP9 and especially AV1 codecs use more sophisticated compression algorithms than H.264, requiring significantly more computational analysis per frame. AV1 encoding can be 50-100x slower than H.264. This is the tradeoff for better compression—smaller files at equivalent quality require more processing time. Use faster presets during testing, and slower presets for final production encodes when quality and file size matter most.

Is WebM supported on all browsers and devices?

WebM (VP9) works on Chrome, Firefox, Edge, and Android devices, but Safari/iOS only added VP9 support in macOS Big Sur and iOS 14 (2020). AV1 support is even more limited—Chrome, Firefox, and recent Safari versions support it, but many mobile devices don't. For maximum compatibility, use MP4 with H.264 as your primary format, with WebM as an alternative for browsers that support it.

How do I choose between WebM and MP4 for web video?

Use MP4 with H.264 for maximum compatibility—it plays everywhere. Use WebM with VP9 for smaller file sizes when you control the playback environment or can provide fallback MP4 versions. Many platforms serve both: WebM to compatible browsers for bandwidth savings, MP4 to others for compatibility. Video platforms typically handle this codec selection automatically based on viewer capabilities.

What bitrate should I use for WebM encoding?

VP9 achieves H.264 quality at roughly 50% of the bitrate. For 1080p VP9, use 2-3 Mbps (vs. 4-6 Mbps H.264). For 720p VP9, use 1-2 Mbps (vs. 2-4 Mbps H.264). AV1 is even more efficient—roughly 30% less than VP9. Start with these values and adjust based on content complexity. Two-pass encoding helps achieve target bitrates more accurately than single-pass.

Why should I use two-pass encoding for WebM?

Two-pass encoding analyzes the entire video in the first pass to understand complexity patterns, then uses that information in the second pass to allocate bitrate optimally. This produces significantly better quality at target bitrates compared to single-pass, especially important for VP9/AV1 since their encoding complexity benefits more from informed bit allocation. The tradeoff is roughly double the encoding time.

Can I use WebM for live streaming?

Technically yes, but it's uncommon. WebM encoding (especially VP9/AV1) is too slow for real-time encoding at scale. Most live streaming uses H.264 for encoding, then may transcode to other formats for on-demand playback afterward. If you need WebM for live, use VP8 with fast encoding presets, though even then H.264 is more practical for most live streaming applications.

What's the difference between Vorbis and Opus audio codecs?

Opus is newer and more efficient than Vorbis—it achieves better quality at lower bitrates, particularly for speech. Opus also handles both low-bitrate (voice) and high-bitrate (music) content well with a single codec. Use Opus with VP9 or AV1 for modern WebM. Only use Vorbis with VP8 when targeting very old browsers, as Opus is now widely supported and clearly superior.

Arrow RightBack to Articles

No credit card required to start using Mux.