## What Is WebM?
**WebM** is an open-source, royalty-free video container format developed by Google and launched in 2010. Designed specifically for web use, it combines Xiph.org audio technologies with Alliance for Open Media video codecs.
WebM can contain:
- **Video:** VP8, VP9, or AV1.
- **Audio:** Vorbis or Opus.
WebM's primary goal: provide a patent-free alternative to MP4/H.264, which requires licensing fees.
## WebM Video Codecs
| Codec | Year | Quality | Encoding speed | Use |
|-------|------|---------|--------------|-----|
| **VP8** | 2010 | Comparable to H.264 | Fast | Legacy |
| **VP9** | 2013 | Comparable to H.265 | Moderate | YouTube, streaming |
| **AV1** | 2018 | Superior to H.265 | Slow (CPU-intensive) | Future, 4K streaming |
## WebM vs MP4
| Feature | MP4 (H.264) | WebM (VP9) | WebM (AV1) |
|---------|-------------|-----------|-----------|
| Quality at equal bitrate | Baseline | Similar | Superior |
| File size | Baseline | Similar | 30-50% smaller |
| Patents/Royalties | Yes (MPEG-LA) | **No** | **No** |
| Browser compatibility | ✅ Universal | 90%+ | 75%+ (growing) |
| iOS Safari | ✅ | ✅ (iOS 14.5+) | Partial |
## Convert to WebM with FFmpeg
```bash
# MP4 to WebM with VP9
ffmpeg -i video.mp4 -c:v libvpx-vp9 -crf 33 -b:v 0 -c:a libopus video.webm
# MP4 to WebM with AV1 (best quality, slowest)
ffmpeg -i video.mp4 -c:v libaom-av1 -crf 30 -b:v 0 -c:a libopus video.webm
# WebM to MP4
ffmpeg -i video.webm -c:v libx264 -c:a aac video.mp4
# Constant quality VP9 (recommended)
ffmpeg -i video.mp4 -c:v libvpx-vp9 -crf 33 -b:v 0 \
-deadline good -cpu-used 2 \
-c:a libopus -b:a 128k video.webm
```
## Implement WebM in HTML with MP4 Fallback
```html
```
## WebM for Background / Loop Video
```html
```
**Essential autoplay attributes:**
- `muted`: required for autoplay in Chrome/Firefox.
- `playsinline`: required on iOS to prevent fullscreen.
- `loop`: continuous looping.
## WebM as GIF Replacement
```bash
ffmpeg -i clip.mp4 -t 5 -vf "fps=15,scale=480:-1" \
-c:v libvpx-vp9 -crf 35 -b:v 0 \
-an animation.webm
```
Result is typically 10-20x smaller than the equivalent GIF.
## Conclusion
**WebM with VP9** is the open-source web video standard, used by YouTube and Netflix. With 90%+ browser support, it's ideal for modern web video. For maximum compatibility include an MP4 fallback. For the future, **AV1 in WebM container** offers the best available efficiency.
Guide