Appearance
Video optimization
Videos used as web banners, hero backgrounds, and short video reviews should be compressed before storing on S3.
Installation
Install ffmpeg via Homebrew:
bash
brew install ffmpegUsage
The script at scripts/media/compress-videos.sh handles all video compression. It scans a directory for .mp4 files and compresses them with H.264/CRF-based encoding.
Silent videos (banners, backgrounds)
Strips the audio track by default — the single biggest win for reducing file size on decorative videos:
bash
./scripts/media/compress-videos.sh /path/to/videosVideos with audio (reviews, shorts)
Pass --keep-audio to encode audio as AAC at 96k:
bash
./scripts/media/compress-videos.sh --keep-audio /path/to/videosCapping resolution
Some source videos are recorded at 1440p or 4K but are only ever displayed at 1080p or smaller on the site. The extra pixels just waste bandwidth. Pass --cap-resolution to scale videos above 1080p down to 1080p while keeping lower resolutions native:
bash
./scripts/media/compress-videos.sh --cap-resolution /path/to/videosFlags can be combined in any order:
bash
./scripts/media/compress-videos.sh --keep-audio --cap-resolution /path/to/videosOutput files are saved alongside the originals with a -minified.mp4 suffix.
Flags explained
-c:v libx264— Sets the video codec to H.264 (AVC). Universal web standard that plays on everything from 2010-era phones to modern smart TVs.-crf 26— Constant Rate Factor. Instead of a fixed bitrate, CRF ensures consistent quality throughout the video.26is an efficient "web-light" setting — smaller than the default23, but still looks sharp.-preset slower— Tells the encoder to spend more time analyzing pixels to find better compression. Results in a smaller file size for the same quality level.-pix_fmt yuv420p(format=yuv420pin-vf) — Ensures the color space is compatible with all web browsers. Without this, some high-end camera footage (10-bit color) won't play in Chrome or Safari.scale=-2:'min(1080,ih)'— Caps the height at 1080 pixels. Videos at 1080p or below are untouched; anything above (1440p, 4K) is scaled down. The-2keeps the width proportional and divisible by 2 (required by H.264). Only applied when--cap-resolutionis passed.-an— Short for "Audio None." Removes the audio track completely (default behavior).-c:a aac -b:a 96k— AAC audio at 96 kbps, used when--keep-audiois passed.-movflags +faststart— Moves the file's metadata index to the beginning so the video starts playing instantly while the rest downloads. Essential for the web.