This guide helps you encode your hero video for optimal web performance.
- ffmpeg installed on your system
- macOS:
brew install ffmpeg - Ubuntu/Debian:
sudo apt-get install ffmpeg - Windows: Download from ffmpeg.org
- macOS:
ffmpeg -i input.mp4 \
-c:v libvpx-vp9 \
-b:v 0 \
-crf 34 \
-an \
-vf "scale=1920:-2" \
public/video/hero.webmParameters:
-c:v libvpx-vp9: Use VP9 codec (better compression than VP8)-b:v 0: Variable bitrate mode-crf 34: Quality level (23-40, higher = smaller file but lower quality)-an: Remove audio track (not needed for background video)-vf "scale=1920:-2": Scale to 1920px width, maintain aspect ratio
ffmpeg -i input.mp4 \
-c:v libx264 \
-preset slow \
-crf 22 \
-pix_fmt yuv420p \
-profile:v high \
-level 4.1 \
-movflags +faststart \
-an \
-vf "scale=1920:-2" \
public/video/hero.mp4Parameters:
-c:v libx264: Use H.264 codec-preset slow: Better compression (slower encoding)-crf 22: Quality level (18-28 recommended)-pix_fmt yuv420p: Pixel format for broad compatibility-profile:v high -level 4.1: Modern device compatibility-movflags +faststart: Enable progressive streaming-an: Remove audio track
Extract a clean frame from your video to use as a poster:
ffmpeg -ss 00:00:01 \
-i input.mp4 \
-frames:v 1 \
public/img/hero-poster.pngParameters:
-ss 00:00:01: Seek to 1 second (adjust as needed)-frames:v 1: Extract only 1 frame
- WebM: Aim for < 5MB for a 10-20 second loop
- MP4: Aim for < 8MB for a 10-20 second loop
- Poster: Aim for < 200KB
If your output file is too large, increase the CRF value:
- WebM: Try CRF 36-40
- MP4: Try CRF 24-28
If quality is poor, decrease the CRF value:
- WebM: Try CRF 30-32
- MP4: Try CRF 18-20
For hero videos:
- Desktop: 1920x1080 (Full HD)
- Mobile: Consider creating a separate 1280x720 version
# WebM mobile
ffmpeg -i input.mp4 \
-c:v libvpx-vp9 \
-b:v 0 \
-crf 36 \
-an \
-vf "scale=1280:-2" \
public/video/hero-mobile.webm
# MP4 mobile
ffmpeg -i input.mp4 \
-c:v libx264 \
-preset slow \
-crf 24 \
-pix_fmt yuv420p \
-profile:v high \
-level 4.1 \
-movflags +faststart \
-an \
-vf "scale=1280:-2" \
public/video/hero-mobile.mp4Then use responsive video sources in your Hero component.
After encoding:
- Check file sizes:
ls -lh public/video/ - Test in browsers: Chrome, Firefox, Safari, Edge
- Test on mobile devices
- Verify autoplay works (muted videos only)
- Check loading performance in DevTools
Video won't play:
- Ensure video is muted (
mutedattribute required for autoplay) - Check browser console for errors
- Verify file paths are correct
File too large:
- Increase CRF value
- Reduce resolution
- Shorten video duration
- Reduce frame rate: add
-r 24to commands
Poor quality:
- Decrease CRF value
- Increase resolution (if source allows)
- Use higher quality source file
- Adjust
-presettoslowerorveryslow