This project demonstrates several key strategies for optimizing video delivery on websites and applications, focusing on better User Experience (UX), smoother streaming, and reduced data transfer costs.
It serves as a checklist and guide for approaching video optimization, particularly since dedicated video streaming performance audits are not covered in tools like Lighthouse.
The repository provides three components to play videos. HTML5Video
uses a simple HTML5 Video tag, ImageKitVideo
uses the ImageKit Video component for optimizations and transformations on videos, HLSVideoPlayer
uses hls.js with ImageKit's Video API's Adaptive Bitrate Streaming transformation for HLS streaming. Each component has different options such as autoplay, muted, transformations, play, pause etc. to optimize video streaming.
A CDN is the starting point for any optimized delivery strategy.
Use ImageKit Video API to automatically compress the video and transcode it to modern formats like WebM and codecs like VP9, AV1.
Don't load Full HD videos in smaller placeholders.
Employ an aggressive optimization strategy by removing the audio track if the video does not need any sound, such as a background video.
ABS dynamically changes the video quality based on the player size and network conditions, which is crucial for balancing UX and business costs.
- Provide different resolutions (e.g., 360p, 480p, 720p, 1080p, etc.) for different devices and network conditions.
- Ensure the adaptive streaming adapts to the player size as well. If the max resolution needed for visual clarity is 360p, there is no need to load a Full HD video, even if the network is great.
- Do you really need ABS? Only use it if your videos are long enough to benefit from the adaptation, typically more than three segments, or over 20s.
- Do you really need higher quality ever? For ex, background videos can often use lower resolution and bitrate without noticeable visual impact.
If business allows, using a thumbnail and waiting for user interaction consumes significantly lesser bandwidth.
- For autoplay videos, this defers loading until the user scrolls near it. An aggressive strategy can defer even the player script until user interaction.
- Limit how many seconds of video are buffered ahead to reduce unnecessary data download. This is controlled by HLS player settings or the HTML
preload
attribute.
- Ensure the video pauses when scrolled out of view. If a video continues playing off-screen, it continues downloading data unnecessarily.