Why Unoptimized Video Ruins Core Web Vitals
Motion designers and developers love embedding crisp showreel loops, UI animations, and product demos on portfolio sites. Unfortunately, dropping a raw 25 MB H.264 MP4—or worse, a 12 MB animated GIF—directly into an HTML <video> tag destroys Largest Contentful Paint (LCP) and drains mobile data plans.
By encoding a dual-format stack (AV1/VP9 + H.264 fallback) with stripped audio tracks and progressive faststart metadata, you can shrink a 20 MB hero video down to under 1.2 MB with virtually zero visible quality loss.
1. Codec Efficiency Comparison for Web Delivery
| Codec | File Size vs. H.264 | Browser Support (2026) | Hardware Decode Support |
|---|---|---|---|
| AV1 (`libsvtav1`) | 40% – 50% smaller | Chrome, Edge, Firefox, Safari 17+ | Apple M3/M4, RTX 30/40/50, Modern Android |
| VP9 (`libvpx-vp9`) | 25% – 35% smaller | Universal (Chrome, Firefox, Edge, Safari) | Widely supported across desktop & mobile |
| H.264 (`libx264`) | Baseline (100%) | 100% Universal (including legacy devices) | Universal on every GPU since 2012 |
2. Production FFmpeg Commands for Web Hero Loops
Step A: Encode Primary AV1 Stream (Smallest Payload)
ffmpeg -i hero_master.mov -an \
-vf "scale=1920:-2" \
-c:v libsvtav1 -crf 32 -preset 6 \
-pix_fmt yuv420p -movflags +faststart \
hero_av1.mp4Step B: Encode Universal H.264 Fallback
ffmpeg -i hero_master.mov -an \
-vf "scale=1920:-2" \
-c:v libx264 -preset slow -crf 24 \
-profile:v main -level:v 4.0 -pix_fmt yuv420p \
-movflags +faststart \
hero_h264.mp4Notice the -an flag: stripping silent audio tracks saves 100–300 KB and guarantees browsers allow instant muted autoplay without policy blocks.
3. Clean HTML5 Progressive <video> Markup
Always supply a lightweight WebP poster image so the browser paints frame 1 immediately for LCP before the video stream finishes buffering:
<video
autoplay
loop
muted
playsinline
preload="metadata"
poster="/media/hero-poster.webp"
width="1920"
height="1080"
>
<source src="/media/hero_av1.mp4" type="video/mp4; codecs=av01.0.08M.08" />
<source src="/media/hero_h264.mp4" type="video/mp4; codecs=avc1.4D4028" />
</video>4 Performance Rules for Web Video
1. Explicit `width` and `height`: Prevents Cumulative Layout Shift (CLS) while the poster loads.
2. Always include `playsinline`: Prevents iOS Safari from hijacking background loops into the fullscreen native player.
3. Cap Frame Rate to 30 FPS: Unless showcasing a 60 FPS gaming edit, 30 FPS cuts file size by ~35% while remaining fluid for UI motion.
4. Pause Off-Screen Videos: Use an IntersectionObserver to call video.pause() once the user scrolls past the hero section, freeing GPU decode cycles.